Merge branch 'master' into 12.0-development

This commit is contained in:
Alex Szpakowski
2021-01-06 21:49:34 -04:00
5 changed files with 81 additions and 9 deletions
+37 -9
View File
@@ -106,14 +106,25 @@ bool NativeFile::isOpen() const
int64 NativeFile::getSize()
{
int fd = file ? fileno(file) : -1;
#ifdef LOVE_WINDOWS
struct _stat64 buf;
// make sure non-ASCII filenames work.
std::wstring wfilename = to_widestr(filename);
if (fd != -1)
{
if (_fstat64(fd, &buf) != 0)
return -1;
}
else
{
// make sure non-ASCII filenames work.
std::wstring wfilename = to_widestr(filename);
struct _stat buf;
if (_wstat(wfilename.c_str(), &buf) != 0)
return -1;
if (_wstat64(wfilename.c_str(), &buf) != 0)
return -1;
}
return (int64) buf.st_size;
@@ -121,7 +132,13 @@ int64 NativeFile::getSize()
// Assume POSIX support...
struct stat buf;
if (stat(filename.c_str(), &buf) != 0)
if (fd != -1)
{
if (fstat(fd, &buf) != 0)
return -1;
}
else if (stat(filename.c_str(), &buf) != 0)
return -1;
return (int64) buf.st_size;
@@ -165,7 +182,7 @@ bool NativeFile::flush()
bool NativeFile::isEOF()
{
return file == nullptr || feof(file) != 0;
return file == nullptr || tell() >= getSize();
}
int64 NativeFile::tell()
@@ -173,12 +190,23 @@ int64 NativeFile::tell()
if (file == nullptr)
return -1;
return (int64) ftell(file);
#ifdef LOVE_WINDOWS
return (int64) _ftelli64(file);
#else
return (int64) ftello(file);
#endif
}
bool NativeFile::seek(uint64 pos)
{
return file != nullptr && fseek(file, (long) pos, SEEK_SET) == 0;
if (file == nullptr)
return false;
#ifdef LOVE_WINDOWS
return _fseeki64(file, (int64) pos, SEEK_SET) == 0;
#else
return fseeko(file, (off_t) pos, SEEK_SET) == 0;
#endif
}
bool NativeFile::setBuffer(BufferMode bufmode, int64 size)