diff --git a/win32/_tfwopen.cpp b/win32/_tfwopen.cpp index ec6103aa..67f55923 100644 --- a/win32/_tfwopen.cpp +++ b/win32/_tfwopen.cpp @@ -48,12 +48,18 @@ extern "C" int _twopen(const char *filename, int oflag, int pmode) { return _wopen(Utf8ToWide(filename), oflag, pmode); } -extern "C" void _twfullpath(char* dst, const char* src, int len) { +extern "C" char *_twfullpath(char* dst, const char* src, int len) { wchar_t *resolved = _wfullpath(NULL, Utf8ToWide(src), MAX_PATH); - strncpy(dst, WideToUtf8(resolved), len); - free(resolved); + WideToUtf8 utf8resolved = WideToUtf8(resolved); + free(resolved); + if (dst == NULL) + { + len = strlen(utf8resolved) + 1; + dst = (char *)malloc(len); + } + strncpy(dst, utf8resolved, len); dst[len - 1] = '\0'; - return; + return dst; } #endif // UNICODE diff --git a/win32/_tfwopen.h b/win32/_tfwopen.h index 98d32cc9..3a519a20 100644 --- a/win32/_tfwopen.h +++ b/win32/_tfwopen.h @@ -18,7 +18,7 @@ extern "C" { FILE *_tfwopen(const char *filename, const char *mode ); int _twremove(const char *filename ); int _twopen(const char *filename, int oflag, int pmode); -void _twfullpath(char* dst, const char* src, int len); +char *_twfullpath(char* dst, const char* src, int len); #ifdef __cplusplus }