From 8c7c6e9b79c0818a5c0da0a3af812d28053bbf40 Mon Sep 17 00:00:00 2001 From: "Olivier F. R. Dierick" Date: Wed, 19 Feb 2020 00:16:37 +0100 Subject: [PATCH] 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 Signed-off-by: Alexandre Julliard --- dlls/shell32/shellpath.c | 48 ++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/dlls/shell32/shellpath.c b/dlls/shell32/shellpath.c index 9bec7091aea..8caf68dc551 100644 --- a/dlls/shell32/shellpath.c +++ b/dlls/shell32/shellpath.c @@ -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); } /******************************************************************************