Log errors of GetShortPathNameW/GetLongPathNameW

This commit is contained in:
Thomas Bernard 2020-12-05 15:09:38 +01:00
parent 100776eca7
commit 0915f86aa3
No known key found for this signature in database
GPG Key ID: DB511043A31ACAAF
3 changed files with 27 additions and 2 deletions

View File

@ -809,15 +809,23 @@ word * Get_Unicode_Filename(word * filename_unicode, const char * filename, cons
len = GetLongPathNameW(shortPath, NULL, 0); len = GetLongPathNameW(shortPath, NULL, 0);
if (len == 0) if (len == 0)
{ {
GFX2_Log(GFX2_ERROR, "GetLongPathNameW(%s\\%s, NULL, 0) returned 0\n", directory, filename);
free(shortPath); free(shortPath);
return NULL; return NULL;
} }
longPath = (WCHAR *)GFX2_malloc(len * sizeof(WCHAR)); longPath = (WCHAR *)GFX2_malloc(len * sizeof(WCHAR));
if (longPath == NULL || GetLongPathNameW(shortPath, longPath, len) == 0) if (longPath == NULL)
{ {
free(shortPath); free(shortPath);
return NULL; return NULL;
} }
if (GetLongPathNameW(shortPath, longPath, len) == 0)
{
GFX2_Log(GFX2_ERROR, "GetLongPathNameW(%s\\%s, %p, %u) returned 0\n", directory, filename, longPath, len);
free(longPath);
free(shortPath);
return NULL;
}
free(shortPath); free(shortPath);
sep = wcsrchr(longPath, '\\'); sep = wcsrchr(longPath, '\\');
if (sep == NULL) if (sep == NULL)

View File

@ -93,8 +93,16 @@ FILE * Open_file_write(T_IO_Context *context)
context->File_name[index] = '\0'; context->File_name[index] = '\0';
} }
} }
else
{
GFX2_Log(GFX2_ERROR, "GetShortPathNameW(%p, %p, %u) failed !\n", filename_unicode, shortpath, len);
}
} }
} }
else
{
GFX2_Log(GFX2_ERROR, "GetShortPathNameW(%p, NULL, 0) failed !\n", filename_unicode);
}
} }
free(filename_unicode); free(filename_unicode);
return f; return f;

View File

@ -599,7 +599,11 @@ bye:
void GFX2_GetShortPathName(char * shortname, size_t shortname_len, const word * longname) void GFX2_GetShortPathName(char * shortname, size_t shortname_len, const word * longname)
{ {
DWORD short_len = GetShortPathNameW((WCHAR *)longname, NULL, 0); DWORD short_len = GetShortPathNameW((WCHAR *)longname, NULL, 0);
if (short_len > 0) if (short_len == 0)
{
GFX2_Log(GFX2_ERROR, "GetShortPathNameW(%p, NULL, 0) failed !\n", longname);
}
else
{ {
WCHAR * temp_str = (WCHAR *)GFX2_malloc(short_len * sizeof(WCHAR)); WCHAR * temp_str = (WCHAR *)GFX2_malloc(short_len * sizeof(WCHAR));
short_len = GetShortPathNameW((WCHAR *)longname, temp_str, short_len); short_len = GetShortPathNameW((WCHAR *)longname, temp_str, short_len);
@ -610,6 +614,10 @@ void GFX2_GetShortPathName(char * shortname, size_t shortname_len, const word *
shortname[i] = temp_str[i]; shortname[i] = temp_str[i];
shortname[i] = '\0'; shortname[i] = '\0';
} }
else
{
GFX2_Log(GFX2_ERROR, "GetShortPathNameW(%p, %p, %u) failed !\n", longname, temp_str, short_len);
}
free(temp_str); free(temp_str);
} }
if (short_len == 0) if (short_len == 0)
@ -621,6 +629,7 @@ void GFX2_GetShortPathName(char * shortname, size_t shortname_len, const word *
shortname[i] = (longname[i] < 256) ? (byte)longname[i] : '_'; shortname[i] = (longname[i] < 256) ? (byte)longname[i] : '_';
} }
shortname[i] = '\0'; shortname[i] = '\0';
GFX2_Log(GFX2_WARNING, "Generated a temporary ansi name : %s\n", shortname);
} }
} }
#endif #endif