diff --git a/src/audio_file.cc b/src/audio_file.cc index 89805e9..86fbfd6 100644 --- a/src/audio_file.cc +++ b/src/audio_file.cc @@ -100,7 +100,7 @@ int audioFileOpen(const char* fname, int flags, ...) audioFile->soundDecoder = soundDecoderInit(audioFileSoundDecoderReadHandler, audioFile->fileHandle, &(audioFile->field_14), &(audioFile->field_10), &(audioFile->fileSize)); audioFile->fileSize *= 2; } else { - audioFile->fileSize = std::filesystem::file_size(path); + audioFile->fileSize = compat_filelength(fileno(stream)); } audioFile->position = 0; diff --git a/src/dfile.cc b/src/dfile.cc index f83f77c..9d71446 100644 --- a/src/dfile.cc +++ b/src/dfile.cc @@ -8,7 +8,6 @@ #include #include #include -#include // Reads .DAT file contents. // @@ -32,7 +31,7 @@ DBase* dbaseOpen(const char* filePath) // Get file size, and reposition stream to read footer, which contains two // 32-bits ints. - int fileSize = std::filesystem::file_size(filePath); + int fileSize = compat_filelength(fileno(stream)); if (fseek(stream, fileSize - sizeof(int) * 2, SEEK_SET) != 0) { goto err; } diff --git a/src/platform_compat.cc b/src/platform_compat.cc index 7429292..2b9623f 100644 --- a/src/platform_compat.cc +++ b/src/platform_compat.cc @@ -5,6 +5,13 @@ #include +#ifdef _WIN32 +#include +#include +#else +#include +#endif + int compat_stricmp(const char* string1, const char* string2) { return SDL_strcasecmp(string1, string2); @@ -81,3 +88,12 @@ void compat_makepath(char* path, const char* drive, const char* dir, const char* strcpy(path, p.string().substr(0, COMPAT_MAX_PATH - 1).c_str()); #endif } + +long compat_filelength(int fd) +{ + long originalOffset = lseek(fd, 0, SEEK_CUR); + lseek(fd, 0, SEEK_SET); + long filesize = lseek(fd, 0, SEEK_END); + lseek(fd, originalOffset, SEEK_SET); + return filesize; +} diff --git a/src/platform_compat.h b/src/platform_compat.h index a46bfd7..1b63744 100644 --- a/src/platform_compat.h +++ b/src/platform_compat.h @@ -24,5 +24,6 @@ char* compat_strlwr(char* string); char* compat_itoa(int value, char* buffer, int radix); void compat_splitpath(const char* path, char* drive, char* dir, char* fname, char* ext); void compat_makepath(char* path, const char* drive, const char* dir, const char* fname, const char* ext); +long compat_filelength(int fd); #endif /* PLATFORM_COMPAT_H */ diff --git a/src/xfile.cc b/src/xfile.cc index 22ad2c9..3a2f6e3 100644 --- a/src/xfile.cc +++ b/src/xfile.cc @@ -418,9 +418,7 @@ long xfileGetSize(XFile* stream) fileSize = 0; break; default: - fseek(stream->file, 0L, SEEK_END); - fileSize = ftell(stream->file); - rewind(stream->file); + fileSize = compat_filelength(fileno(stream->file)); break; }