26#if !defined WIN32_LEAN_AND_MEAN
27# define WIN32_LEAN_AND_MEAN
32#include <osl/thread.h>
36#include <osl/file.hxx>
41 static struct { DWORD wnt;
ErrCode sv; } errArr[] =
85 if( errArr[
i].wnt == nWntError )
87 nRetVal = errArr[
i].sv;
91 }
while( errArr[
i].wnt != DWORD(0xFFFFFFFF) );
105 if ( FileBase::getSystemPathFromFileURL( rFileName, aFileName ) != FileBase::E_None )
106 aFileName = rFileName;
107 Open( aFileName, nMode );
130 bool bResult = ReadFile(
mxFileHandle,pData,nSize,&nCount,
nullptr);
133 std::size_t nTestError = GetLastError();
145 if(!WriteFile(
mxFileHandle,pData,nSize,&nCount,
nullptr))
154 assert(nPos != SAL_MAX_UINT32);
155 LARGE_INTEGER nNewPos, nActPos;
156 nNewPos.QuadPart = 0;
157 nActPos.QuadPart =
nPos;
177 return static_cast<sal_uInt64
>(nNewPos.QuadPart);
191 bool bRetVal =
false;
215 if( nLockCounter > 0)
217 if( nLockCounter == 1)
246 OUString aParsedFilename(rFilename);
248 SetLastError( ERROR_SUCCESS );
256 SetLastError( ERROR_SUCCESS );
259 DWORD nShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
260 DWORD nAccessMode = 0;
261 UINT nOldErrorMode = SetErrorMode( SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX );
264 nShareMode &= ~FILE_SHARE_READ;
267 nShareMode &= ~FILE_SHARE_WRITE;
273 nAccessMode |= GENERIC_READ;
275 nAccessMode |= GENERIC_WRITE;
277 if( nAccessMode == GENERIC_READ )
284 nOpenAction = CREATE_ALWAYS;
286 nOpenAction = OPEN_ALWAYS;
291 nOpenAction = TRUNCATE_EXISTING;
293 nOpenAction = OPEN_EXISTING;
296 DWORD
nAttributes = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS;
315 GetLastError() == ERROR_ALREADY_EXISTS ||
317 GetLastError() == ERROR_FILE_NOT_FOUND ))
320 if( nOpenAction == OPEN_ALWAYS || nOpenAction == CREATE_ALWAYS )
321 SetLastError( ERROR_SUCCESS );
326 (nAccessMode & GENERIC_WRITE))
329 if(nErr==SVSTREAM_ACCESS_DENIED || nErr==SVSTREAM_SHARING_VIOLATION)
332 nAccessMode = GENERIC_READ;
335 nOpenAction = OPEN_EXISTING;
336 SetLastError( ERROR_SUCCESS );
343 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
346 if( GetLastError() == ERROR_ALREADY_EXISTS )
347 SetLastError( ERROR_SUCCESS );
351 if( GetLastError() != ERROR_SUCCESS )
360 if( nAccessMode & GENERIC_WRITE )
363 SetErrorMode( nOldErrorMode );
398 DWORD
const nOld = SetFilePointer( hFile, 0L,
nullptr, FILE_CURRENT );
399 if( nOld != 0xffffffff )
401 if( SetFilePointer(hFile,nSize,
nullptr,FILE_BEGIN ) != 0xffffffff)
403 bool bSucc = SetEndOfFile( hFile );
407 if( SetFilePointer( hFile,nOld,
nullptr,FILE_BEGIN ) == 0xffffffff)
virtual std::size_t GetData(void *pData, std::size_t nSize) override
Does not check for EOF, makes isEof callable.
virtual void ResetError() override
set filepointer to beginning of file
virtual void FlushData() override
void Open(const OUString &rFileName, StreamMode eOpenMode)
virtual ~SvFileStream() override
virtual void SetSize(sal_uInt64 nSize) override
virtual sal_uInt64 SeekPos(sal_uInt64 nPos) override
virtual std::size_t PutData(const void *pData, std::size_t nSize) override
SAL_DLLPRIVATE void ClearBuffer()
void SetBufferSize(sal_uInt16 m_nBufSize)
SAL_DLLPRIVATE void ClearError()
void SetError(ErrCode nErrorCode)
void FlushBuffer()
If we have data in our internal buffers, write them out.
#define SVSTREAM_WRITE_ERROR
#define SVSTREAM_SHARING_VIOLATION
#define SVSTREAM_TOO_MANY_OPEN_FILES
#define SVSTREAM_ACCESS_DENIED
#define SVSTREAM_INVALID_PARAMETER
#define SVSTREAM_PATH_NOT_FOUND
#define SVSTREAM_LOCKING_VIOLATION
#define SVSTREAM_SEEK_ERROR
#define SVSTREAM_INVALID_ACCESS
#define SVSTREAM_SHARE_BUFF_EXCEEDED
#define SVSTREAM_DISK_FULL
#define SVSTREAM_INVALID_HANDLE
#define SVSTREAM_GENERALERROR
#define SVSTREAM_FILE_NOT_FOUND
#define SVSTREAM_READ_ERROR
#define STREAM_SEEK_TO_END
@ READ
allow read accesses
@ TEMPORARY
temporary file attribute (Windows-only)
@ TRUNC
Truncate existing file to zero length.
@ NOCREATE
1 == Don't create file
@ WRITE
allow write accesses
@ DELETE_ON_CLOSE
only for temporary files (Windows-only)
static ErrCode GetSvError(DWORD nWntError)