55 else if (errno == EACCES || errno ==
EPERM)
57 else if (errno == ENOSPC)
67 class SysErrorModeDisabler
74 if (pfileName && (pfileName[0]!=0) && pfileName[1]==
':')
77 OldMode = ::SetErrorMode(SEM_FAILCRITICALERRORS);
85 if (Disabled) ::SetErrorMode(OldMode);
94 #endif // OVR_OS_WIN32
123 #ifdef OVR_FILE_VERIFY_SEEK_ERRORS
124 UByte* pFileTestBuffer;
125 unsigned FileTestLength;
135 #ifdef OVR_FILE_VERIFY_SEEK_ERRORS
144 FILEFile(
const char* pfileName,
int flags,
int Mode);
168 virtual int Write(
const UByte *pbuffer,
int numBytes);
169 virtual int Read(
UByte *pbuffer,
int numBytes);
172 virtual bool Flush();
173 virtual int Seek(
int offset,
int origin);
177 virtual bool Close();
202 const char *omode =
"rb";
225 #if defined(OVR_CC_MSVC) && (OVR_CC_MSVC >= 1400)
231 _wfopen_s(&
fs, pwFileName, womode);
246 #ifdef OVR_FILE_VERIFY_SEEK_ERRORS
248 fseek(
fs, 0, SEEK_END);
249 FileTestLength = ftell(
fs);
250 fseek(
fs, 0, SEEK_SET);
254 OVR_ASSERT(FileTestLength == (
unsigned)
Read(pFileTestBuffer, FileTestLength));
290 int pos = (int)ftell (
fs);
340 int written = (int) fwrite(pbuffer, 1, numBytes,
fs);
341 if (written < numBytes)
344 #ifdef OVR_FILE_VERIFY_SEEK_ERRORS
357 int read = (int) fread(pbuffer, 1, numBytes,
fs);
361 #ifdef OVR_FILE_VERIFY_SEEK_ERRORS
365 UByte* pcompareBuffer = pFileTestBuffer + TestPos;
366 for (
int i=0; i< read; i++)
387 if ((pos==-1) || (newPos==-1))
393 return int (newPos-(
int)pos);
403 if ((pos==-1) || (endPos==-1))
411 return int (endPos-(
int)pos);
425 case Seek_Set: newOrigin = SEEK_SET;
break;
426 case Seek_Cur: newOrigin = SEEK_CUR;
break;
427 case Seek_End: newOrigin = SEEK_END;
break;
430 if (newOrigin == SEEK_SET && offset ==
Tell())
433 if (fseek (
fs, offset, newOrigin))
435 #ifdef OVR_FILE_VERIFY_SEEK_ERRORS
441 #ifdef OVR_FILE_VERIFY_SEEK_ERRORS
445 case Seek_Set: TestPos = offset;
break;
446 case Seek_Cur: TestPos += offset;
break;
447 case Seek_End: TestPos = FileTestLength + offset;
break;
457 return Seek((
int)offset,origin);
464 int szRequest, szRead, szWritten;
468 szRequest = (byteSize > int(
sizeof(buff))) ?
int(
sizeof(buff)) : byteSize;
470 szRead = pstream->
Read(buff, szRequest);
473 szWritten =
Write(buff, szRead);
476 byteSize -= szWritten;
477 if (szWritten < szRequest)
486 #ifdef OVR_FILE_VERIFY_SEEK_ERRORS
495 bool closeRet = !fclose(
fs);
573 #if defined(OVR_OS_WIN32)
575 struct __stat64 fileStat;
580 int ret = _wstat64(pwpath, &fileStat);
582 if (ret)
return false;
584 struct stat fileStat;
586 if (stat(path, &fileStat) != 0)
591 pfileStat->
FileSize = fileStat.st_size;
static bool OVR_CDECL GetFileStat(FileStat *pfileStats, const String &path)
virtual bool IsWritable()
Ptr< File > FileFILEOpen(const String &path, int flags, int mode)
virtual const char * GetFilePath()
SPInt OVR_STDCALL GetLength(const char *buf, SPInt buflen)
virtual int GetErrorCode()
UPInt OVR_STDCALL DecodeString(wchar_t *pbuff, const char *putf8str, SPInt bytesLen)
__END_NAMESPACE_STD char char __BEGIN_NAMESPACE_STD size_t strlen(const char *__s) __THROW __attribute_pure__ __nonnull((1))
virtual int Read(UByte *pbuffer, int numBytes)
virtual SInt64 LGetLength()
SysErrorModeDisabler(const char *pfileName)
virtual int Write(const UByte *pbuffer, int numBytes)
const char * ToCStr() const
virtual int BytesAvailable()
virtual SInt64 LSeek(SInt64 offset, int origin)
virtual int SkipBytes(int numBytes)
virtual int CopyFromStream(File *pStream, int byteSize)
virtual int Seek(int offset, int origin)
virtual int Read(UByte *pbufer, int numBytes)=0