win32: make _twfullpath work with NULL destination

This commit is contained in:
OV2 2019-01-15 23:23:39 +01:00
parent 4ede9b18cc
commit 5b01fa2dc1
2 changed files with 11 additions and 5 deletions

View File

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

View File

@ -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
}