parent
11472e8be9
commit
c8d45854ba
|
@ -289,7 +289,7 @@ bool configRead(Config* config, const char* filePath, bool isDb)
|
|||
} else {
|
||||
FILE* stream = compat_fopen(filePath, "rt");
|
||||
if (stream != NULL) {
|
||||
while (fgets(string, sizeof(string), stream) != NULL) {
|
||||
while (compat_fgets(string, sizeof(string), stream) != NULL) {
|
||||
configParseLine(config, string);
|
||||
}
|
||||
|
||||
|
|
|
@ -447,7 +447,7 @@ int dictionaryLoad(FILE* stream, Dictionary* dictionary, int a3)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (fgets(entry->key, keyLength + 1, stream) == NULL) {
|
||||
if (compat_fgets(entry->key, keyLength + 1, stream) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -239,6 +239,36 @@ gzFile compat_gzopen(const char* path, const char* mode)
|
|||
return gzopen(nativePath, mode);
|
||||
}
|
||||
|
||||
char* compat_fgets(char* buffer, int maxCount, FILE* stream)
|
||||
{
|
||||
buffer = fgets(buffer, maxCount, stream);
|
||||
|
||||
if (buffer != NULL) {
|
||||
size_t len = strlen(buffer);
|
||||
if (len >= 2 && buffer[len - 1] == '\n' && buffer[len - 2] == '\r') {
|
||||
buffer[len - 2] = '\n';
|
||||
buffer[len - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
char* compat_gzgets(gzFile stream, char* buffer, int maxCount)
|
||||
{
|
||||
buffer = gzgets(stream, buffer, maxCount);
|
||||
|
||||
if (buffer != NULL) {
|
||||
size_t len = strlen(buffer);
|
||||
if (len >= 2 && buffer[len - 1] == '\n' && buffer[len - 2] == '\r') {
|
||||
buffer[len - 2] = '\n';
|
||||
buffer[len - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
int compat_remove(const char* path)
|
||||
{
|
||||
char nativePath[COMPAT_MAX_PATH];
|
||||
|
|
|
@ -35,6 +35,8 @@ int compat_mkdir(const char* path);
|
|||
unsigned int compat_timeGetTime();
|
||||
FILE* compat_fopen(const char* path, const char* mode);
|
||||
gzFile compat_gzopen(const char* path, const char* mode);
|
||||
char* compat_fgets(char* buffer, int maxCount, FILE* stream);
|
||||
char* compat_gzgets(gzFile stream, char* buffer, int maxCount);
|
||||
int compat_remove(const char* path);
|
||||
int compat_rename(const char* oldFileName, const char* newFileName);
|
||||
void compat_windows_path_to_native(char* path);
|
||||
|
|
|
@ -234,10 +234,10 @@ char* xfileReadString(char* string, int size, XFile* stream)
|
|||
result = dfileReadString(string, size, stream->dfile);
|
||||
break;
|
||||
case XFILE_TYPE_GZFILE:
|
||||
result = gzgets(stream->gzfile, string, size);
|
||||
result = compat_gzgets(stream->gzfile, string, size);
|
||||
break;
|
||||
default:
|
||||
result = fgets(string, size, stream->file);
|
||||
result = compat_fgets(string, size, stream->file);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue