diff options
author | Tim Mayberry <mojofunk@gmail.com> | 2015-08-18 14:44:53 +1000 |
---|---|---|
committer | Tim Mayberry <mojofunk@gmail.com> | 2015-08-18 15:33:03 +1000 |
commit | a2fbce0e7f31bdebf59bcea5282b4909c9e19837 (patch) | |
tree | 2b48333a8a7ce5f46c66b17a93c636900da1216d /libs/pbd | |
parent | 36e4c11a2ac8e1a2310d948b6f039d28be4cf521 (diff) |
Change return type and name of get_win_special_folder
Rename it get_win_special_folder_path to indicate what it is returning
Move documentation for the function into the header and use doxygen style
comments.
Fixes a couple of memory leaks in ArdourVideoToolPaths class although it looks
as if there are more.
Diffstat (limited to 'libs/pbd')
-rw-r--r-- | libs/pbd/pbd/windows_special_dirs.h | 14 | ||||
-rw-r--r-- | libs/pbd/windows_special_dirs.cc | 31 |
2 files changed, 23 insertions, 22 deletions
diff --git a/libs/pbd/pbd/windows_special_dirs.h b/libs/pbd/pbd/windows_special_dirs.h index c557ef4c16..0bc5accc96 100644 --- a/libs/pbd/pbd/windows_special_dirs.h +++ b/libs/pbd/pbd/windows_special_dirs.h @@ -20,10 +20,22 @@ #ifndef __libpbd_windows_special_dirs_h__ #define __libpbd_windows_special_dirs_h__ +#include <string> + #include "pbd/libpbd_visibility.h" namespace PBD { - LIBPBD_API char * get_win_special_folder (int csidl); + +/** +* Gets the full path that corresponds of one of the Windows special folders, +* such as "My Documents" and the like. +* +* @param csidl corresponds to CSIDL values, such as CSIDL_SYSTEM etc. +* @return A string containing the name of the special folder or an empty +* string on failure. +*/ +LIBPBD_API std::string get_win_special_folder_path (int csidl); + } #endif /* __libpbd_windows_special_dirs_h__ */ diff --git a/libs/pbd/windows_special_dirs.cc b/libs/pbd/windows_special_dirs.cc index 5e924f57e1..d5138050df 100644 --- a/libs/pbd/windows_special_dirs.cc +++ b/libs/pbd/windows_special_dirs.cc @@ -23,38 +23,27 @@ #include "pbd/windows_special_dirs.h" -//*************************************************************** -// -// get_win_special_folder() -// -// Gets the full path name that corresponds of one of the Windows -// special folders, such as "My Documents" and the like. The input -// parameter must be one of the corresponding CSIDL values, such -// as CSIDL_SYSTEM etc. -// -// Returns: -// -// On Success: A pointer to a newly allocated string containing -// the name of the special folder (must later be freed). -// On Failure: NULL -// - -char * -PBD::get_win_special_folder (int csidl) +std::string +PBD::get_win_special_folder_path (int csidl) { wchar_t path[PATH_MAX+1]; HRESULT hr; LPITEMIDLIST pidl = 0; - char *retval = 0; + char *utf8_folder_path = 0; if (S_OK == (hr = SHGetSpecialFolderLocation (0, csidl, &pidl))) { if (SHGetPathFromIDListW (pidl, path)) { - retval = g_utf16_to_utf8 ((const gunichar2*)path, -1, 0, 0, 0); + utf8_folder_path = g_utf16_to_utf8 ((const gunichar2*)path, -1, 0, 0, 0); } CoTaskMemFree (pidl); } - return retval; + if (utf8_folder_path != NULL) { + std::string folder_path(utf8_folder_path); + g_free (utf8_folder_path); + return folder_path; + } + return std::string(); } |