Provide filepath compatibility layer (#22)

Co-authored-by: Alexander Batalov <alex.batalov@gmail.com>
This commit is contained in:
Jan Šimek 2022-05-28 23:22:40 +02:00 committed by GitHub
parent 442e0a17ab
commit 86c0585efc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 28 additions and 6 deletions

View File

@ -6,7 +6,6 @@
#include "sound.h"
#include <assert.h>
#include <io.h>
#include <stdio.h>
#include <string.h>
@ -100,7 +99,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 = filelength(fileno(stream));
audioFile->fileSize = compat_filelength(fileno(stream));
}
audioFile->position = 0;

View File

@ -5,6 +5,7 @@
#include "sound.h"
#include <limits.h>
#include <stdlib.h> // qsort
#include <stdio.h>
#include <string.h>

View File

@ -5,7 +5,6 @@
#include <fpattern.h>
#include <assert.h>
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -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 = filelength(fileno(stream));
int fileSize = compat_filelength(fileno(stream));
if (fseek(stream, fileSize - sizeof(int) * 2, SEEK_SET) != 0) {
goto err;
}

View File

@ -56,7 +56,12 @@
#include "window_manager.h"
#include "world_map.h"
#ifdef _WIN32
#include <io.h>
#else
#include <unistd.h> // access
#endif
#include <stdio.h>
#define HELP_SCREEN_WIDTH (640)

View File

@ -5,6 +5,13 @@
#include <filesystem>
#ifdef _WIN32
#include <io.h>
#include <stdio.h>
#else
#include <unistd.h>
#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;
}

View File

@ -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 */

View File

@ -2,6 +2,7 @@
#include "debug.h"
#include "memory.h"
#include "platform_compat.h"
#include <io.h>
#include <limits.h>
@ -37,7 +38,7 @@ SoundFileIO gSoundDefaultFileIO = {
write,
lseek,
tell,
filelength,
compat_filelength,
-1,
};

View File

@ -418,7 +418,7 @@ long xfileGetSize(XFile* stream)
fileSize = 0;
break;
default:
fileSize = filelength(fileno(stream->file));
fileSize = compat_filelength(fileno(stream->file));
break;
}