filesel.c: fewer dependencies to <windows.h>

This commit is contained in:
Thomas Bernard
2020-04-13 00:15:52 +02:00
parent 8b2e925c00
commit 7f08ad5bb9
3 changed files with 34 additions and 24 deletions

View File

@@ -574,3 +574,33 @@ bye:
return NULL;
#endif
}
#if defined(WIN32)
void GFX2_GetShortPathName(char * shortname, size_t shortname_len, const word * longname)
{
DWORD short_len = GetShortPathNameW((WCHAR *)longname, NULL, 0);
if (short_len > 0)
{
WCHAR * temp_str = (WCHAR *)GFX2_malloc(short_len * sizeof(WCHAR));
short_len = GetShortPathNameW((WCHAR *)longname, temp_str, short_len);
if (short_len > 0)
{
DWORD i;
for (i = 0; i < short_len && temp_str[i] != 0; i++)
shortname[i] = temp_str[i];
shortname[i] = '\0';
}
free(temp_str);
}
if (short_len == 0)
{
// generate a temporary ansi name
int i;
for (i = 0; (i < (int)shortname_len - 1) && (longname[i] != 0); i++)
{
shortname[i] = (longname[i] < 256) ? (byte)longname[i] : '_';
}
shortname[i] = '\0';
}
}
#endif