X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fwin32.c;h=c36b13ae8593d106080d34915ed8b712c4b9764a;hp=1b2aeffe597189f77396dd2a864a5ec54262c943;hb=0fff6faf47040a8b02eac070b6c5f2477d319fbb;hpb=16aab5992bfe8c33e2815b4ce5c9ebd7ec130c21 diff --git a/src/win32.c b/src/win32.c index 1b2aeffe..c36b13ae 100644 --- a/src/win32.c +++ b/src/win32.c @@ -394,22 +394,31 @@ static int win32_get_short_name(struct wim_dentry *dentry, const wchar_t *path) { WIN32_FIND_DATAW dat; - if (FindFirstFileW(path, &dat) && dat.cAlternateFileName[0] != L'\0') { - DEBUG("\"%ls\": short name \"%ls\"", path, dat.cAlternateFileName); - size_t short_name_nbytes = wcslen(dat.cAlternateFileName) * - sizeof(wchar_t); - size_t n = short_name_nbytes + sizeof(wchar_t); - dentry->short_name = MALLOC(n); - if (!dentry->short_name) - return WIMLIB_ERR_NOMEM; - memcpy(dentry->short_name, dat.cAlternateFileName, n); - dentry->short_name_nbytes = short_name_nbytes; - } + HANDLE hFind; + int ret = 0; + /* If we can't read the short filename for some reason, we just ignore * the error and assume the file has no short name. I don't think this * should be an issue, since the short names are essentially obsolete * anyway. */ - return 0; + hFind = FindFirstFileW(path, &dat); + if (hFind != INVALID_HANDLE_VALUE) { + if (dat.cAlternateFileName[0] != L'\0') { + DEBUG("\"%ls\": short name \"%ls\"", path, dat.cAlternateFileName); + size_t short_name_nbytes = wcslen(dat.cAlternateFileName) * + sizeof(wchar_t); + size_t n = short_name_nbytes + sizeof(wchar_t); + dentry->short_name = MALLOC(n); + if (dentry->short_name) { + memcpy(dentry->short_name, dat.cAlternateFileName, n); + dentry->short_name_nbytes = short_name_nbytes; + } else { + ret = WIMLIB_ERR_NOMEM; + } + } + FindClose(hFind); + } + return ret; } static int