Fix splitpath/makepath issues

See #68
This commit is contained in:
Alexander Batalov 2022-07-25 20:48:35 +03:00
parent 8ef9b66950
commit 8bd75e9737
1 changed files with 4 additions and 4 deletions

View File

@ -13,6 +13,7 @@
#include <direct.h> #include <direct.h>
#include <io.h> #include <io.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#else #else
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
@ -51,7 +52,7 @@ 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)
{ {
#if defined(_WIN32) #ifdef _WIN32
_splitpath(path, drive, dir, fname, ext); _splitpath(path, drive, dir, fname, ext);
#else #else
const char *driveStart = path; const char *driveStart = path;
@ -106,7 +107,7 @@ void compat_splitpath(const char* path, char* drive, char* dir, char* fname, cha
strncpy(fname, fnameStart, fileNameSize); strncpy(fname, fnameStart, fileNameSize);
fname[fileNameSize] = '\0'; fname[fileNameSize] = '\0';
} }
if (ext != NULL) { if (ext != NULL) {
size_t extSize = end - extStart; size_t extSize = end - extStart;
if (extSize > COMPAT_MAX_EXT - 1) { if (extSize > COMPAT_MAX_EXT - 1) {
@ -120,7 +121,7 @@ void compat_splitpath(const char* path, char* drive, char* dir, char* fname, cha
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)
{ {
#if defined(_WIN32) #ifdef _WIN32
_makepath(path, drive, dir, fname, ext); _makepath(path, drive, dir, fname, ext);
#else #else
path[0] = '\0'; path[0] = '\0';
@ -177,7 +178,6 @@ void compat_makepath(char* path, const char* drive, const char* dir, const char*
strcpy(path, ext); strcpy(path, ext);
path = strchr(path, '\0'); path = strchr(path, '\0');
} }
strcat(path, ext);
} }
*path = '\0'; *path = '\0';