shell32: Add helper functions for XDG directories lookup and resource deallocation.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=22974
Signed-off-by: Olivier F. R. Dierick <o.dierick@piezo-forte.be>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Olivier F. R. Dierick 2020-02-19 00:16:37 +01:00 committed by Alexandre Julliard
parent 81b4dba58a
commit 8c7c6e9b79
1 changed files with 39 additions and 9 deletions

View File

@ -3948,6 +3948,43 @@ end:
return hr;
}
/*************************************************************************
* _SHGetXDGUserDirs [Internal]
*
* Get XDG directories paths from XDG configuration.
*
* PARAMS
* xdg_dirs [I] Array of XDG directories to look for.
* num_dirs [I] Number of elements in xdg_dirs.
* xdg_results [O] An array of the XDG directories paths.
*/
static inline void _SHGetXDGUserDirs(const char * const *xdg_dirs, const unsigned int num_dirs, char *** xdg_results) {
HRESULT hr;
hr = XDG_UserDirLookup(xdg_dirs, num_dirs, xdg_results);
if (FAILED(hr)) *xdg_results = NULL;
}
/*************************************************************************
* _SHFreeXDGUserDirs [Internal]
*
* Free resources allocated by XDG_UserDirLookup().
*
* PARAMS
* num_dirs [I] Number of elements in xdg_results.
* xdg_results [I] An array of the XDG directories paths.
*/
static inline void _SHFreeXDGUserDirs(const unsigned int num_dirs, char ** xdg_results) {
UINT i;
if (xdg_results)
{
for (i = 0; i < num_dirs; i++)
heap_free(xdg_results[i]);
heap_free(xdg_results);
}
}
/*************************************************************************
* _SHAppendToUnixPath [Internal]
*
@ -4069,8 +4106,7 @@ static void _SHCreateSymbolicLinks(void)
pszPersonal = wine_get_unix_file_name(wszTempPath);
if (!pszPersonal) return;
hr = XDG_UserDirLookup(xdg_dirs, num, &xdg_results);
if (FAILED(hr)) xdg_results = NULL;
_SHGetXDGUserDirs(xdg_dirs, num, &xdg_results);
pszHome = getenv("HOME");
if (pszHome && !stat(pszHome, &statFolder) && S_ISDIR(statFolder.st_mode))
@ -4204,13 +4240,7 @@ static void _SHCreateSymbolicLinks(void)
}
}
/* Free resources allocated by XDG_UserDirLookup() */
if (xdg_results)
{
for (i = 0; i < num; i++)
heap_free(xdg_results[i]);
heap_free(xdg_results);
}
_SHFreeXDGUserDirs(num, xdg_results);
}
/******************************************************************************