Provide filepath compatibility layer (#22)
Co-authored-by: Alexander Batalov <alex.batalov@gmail.com>
This commit is contained in:
parent
442e0a17ab
commit
86c0585efc
|
@ -6,7 +6,6 @@
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <io.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.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->soundDecoder = soundDecoderInit(audioFileSoundDecoderReadHandler, audioFile->fileHandle, &(audioFile->field_14), &(audioFile->field_10), &(audioFile->fileSize));
|
||||||
audioFile->fileSize *= 2;
|
audioFile->fileSize *= 2;
|
||||||
} else {
|
} else {
|
||||||
audioFile->fileSize = filelength(fileno(stream));
|
audioFile->fileSize = compat_filelength(fileno(stream));
|
||||||
}
|
}
|
||||||
|
|
||||||
audioFile->position = 0;
|
audioFile->position = 0;
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <stdlib.h> // qsort
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include <fpattern.h>
|
#include <fpattern.h>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <io.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.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
|
// Get file size, and reposition stream to read footer, which contains two
|
||||||
// 32-bits ints.
|
// 32-bits ints.
|
||||||
int fileSize = filelength(fileno(stream));
|
int fileSize = compat_filelength(fileno(stream));
|
||||||
if (fseek(stream, fileSize - sizeof(int) * 2, SEEK_SET) != 0) {
|
if (fseek(stream, fileSize - sizeof(int) * 2, SEEK_SET) != 0) {
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,12 @@
|
||||||
#include "window_manager.h"
|
#include "window_manager.h"
|
||||||
#include "world_map.h"
|
#include "world_map.h"
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h> // access
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define HELP_SCREEN_WIDTH (640)
|
#define HELP_SCREEN_WIDTH (640)
|
||||||
|
|
|
@ -5,6 +5,13 @@
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <io.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
int compat_stricmp(const char* string1, const char* string2)
|
int compat_stricmp(const char* string1, const char* string2)
|
||||||
{
|
{
|
||||||
return SDL_strcasecmp(string1, 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());
|
strcpy(path, p.string().substr(0, COMPAT_MAX_PATH - 1).c_str());
|
||||||
#endif
|
#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;
|
||||||
|
}
|
||||||
|
|
|
@ -24,5 +24,6 @@ char* compat_strlwr(char* string);
|
||||||
char* compat_itoa(int value, char* buffer, int radix);
|
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_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);
|
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 */
|
#endif /* PLATFORM_COMPAT_H */
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
#include "platform_compat.h"
|
||||||
|
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
@ -37,7 +38,7 @@ SoundFileIO gSoundDefaultFileIO = {
|
||||||
write,
|
write,
|
||||||
lseek,
|
lseek,
|
||||||
tell,
|
tell,
|
||||||
filelength,
|
compat_filelength,
|
||||||
-1,
|
-1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -418,7 +418,7 @@ long xfileGetSize(XFile* stream)
|
||||||
fileSize = 0;
|
fileSize = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fileSize = filelength(fileno(stream->file));
|
fileSize = compat_filelength(fileno(stream->file));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue