Misc: Drop stat compatibility calls

This commit is contained in:
Stenzek 2023-09-04 22:31:52 +10:00 committed by Connor McLaughlin
parent 1f88072eae
commit c16836e7c0
3 changed files with 9 additions and 51 deletions

View File

@ -726,13 +726,6 @@ int FileSystem::FSeek64(std::FILE* fp, s64 offset, int whence)
#ifdef _WIN32
return _fseeki64(fp, offset, whence);
#else
// Prevent truncation on platforms which don't have a 64-bit off_t.
if constexpr (sizeof(off_t) != sizeof(s64))
{
if (offset < std::numeric_limits<off_t>::min() || offset > std::numeric_limits<off_t>::max())
return -1;
}
return fseeko(fp, static_cast<off_t>(offset), whence);
#endif
}
@ -1474,6 +1467,9 @@ bool FileSystem::SetPathCompression(const char* path, bool enable)
#else
// No 32-bit file offsets breaking stuff please.
static_assert(sizeof(off_t) == sizeof(s64));
static u32 RecursiveFindFiles(const char* OriginPath, const char* ParentPath, const char* Path, const char* Pattern,
u32 Flags, FileSystem::FindResultsArray* pResults)
{
@ -1528,17 +1524,10 @@ static u32 RecursiveFindFiles(const char* OriginPath, const char* ParentPath, co
FILESYSTEM_FIND_DATA outData;
outData.Attributes = 0;
#if defined(__HAIKU__) || defined(__APPLE__) || defined(__FreeBSD__)
struct stat sDir;
if (stat(full_path.c_str(), &sDir) < 0)
continue;
#else
struct stat64 sDir;
if (stat64(full_path.c_str(), &sDir) < 0)
continue;
#endif
if (S_ISDIR(sDir.st_mode))
{
if (Flags & FILESYSTEM_FIND_RECURSIVE)
@ -1641,13 +1630,8 @@ bool FileSystem::StatFile(const char* path, FILESYSTEM_STAT_DATA* sd)
return false;
// stat file
#if defined(__HAIKU__) || defined(__APPLE__) || defined(__FreeBSD__)
struct stat sysStatData;
if (stat(path, &sysStatData) < 0)
#else
struct stat64 sysStatData;
if (stat64(path, &sysStatData) < 0)
#endif
return false;
// parse attributes
@ -1674,13 +1658,8 @@ bool FileSystem::StatFile(std::FILE* fp, FILESYSTEM_STAT_DATA* sd)
return false;
// stat file
#if defined(__HAIKU__) || defined(__APPLE__) || defined(__FreeBSD__)
struct stat sysStatData;
if (fstat(fd, &sysStatData) < 0)
#else
struct stat64 sysStatData;
if (fstat64(fd, &sysStatData) < 0)
#endif
return false;
// parse attributes
@ -1707,13 +1686,8 @@ bool FileSystem::FileExists(const char* path)
return false;
// stat file
#if defined(__HAIKU__) || defined(__APPLE__) || defined(__FreeBSD__)
struct stat sysStatData;
if (stat(path, &sysStatData) < 0)
#else
struct stat64 sysStatData;
if (stat64(path, &sysStatData) < 0)
#endif
return false;
if (S_ISDIR(sysStatData.st_mode))
@ -1729,13 +1703,8 @@ bool FileSystem::DirectoryExists(const char* path)
return false;
// stat file
#if defined(__HAIKU__) || defined(__APPLE__) || defined(__FreeBSD__)
struct stat sysStatData;
if (stat(path, &sysStatData) < 0)
#else
struct stat64 sysStatData;
if (stat64(path, &sysStatData) < 0)
#endif
return false;
if (S_ISDIR(sysStatData.st_mode))

View File

@ -250,13 +250,9 @@ void* HostSys::CreateSharedMemory(const char* name, size_t size)
shm_unlink(name);
// ensure it's the correct size
#if !defined(__APPLE__) && !defined(__FreeBSD__)
if (ftruncate64(fd, static_cast<off64_t>(size)) < 0)
#else
if (ftruncate(fd, static_cast<off_t>(size)) < 0)
#endif
{
std::fprintf(stderr, "ftruncate64(%zu) failed: %d\n", size, errno);
std::fprintf(stderr, "ftruncate(%zu) failed: %d\n", size, errno);
return nullptr;
}

View File

@ -88,7 +88,6 @@ void FlatFileReader::CancelRead(void)
void FlatFileReader::Close(void)
{
if (m_fd != -1)
close(m_fd);
@ -100,15 +99,9 @@ void FlatFileReader::Close(void)
uint FlatFileReader::GetBlockCount(void) const
{
#if defined(__HAIKU__) || defined(__APPLE__) || defined(__FreeBSD__)
struct stat sysStatData;
if (fstat(m_fd, &sysStatData) < 0)
return 0;
#else
struct stat64 sysStatData;
if (fstat64(m_fd, &sysStatData) < 0)
return 0;
#endif
return (int)(sysStatData.st_size / m_blocksize);
return static_cast<uint>(sysStatData.st_size / m_blocksize);
}