Fix errors in BKE_appdir_font_folder_default
- Missing NULL check for the HOME environment variable. - The user preference path was written to even when the path didn't exist.
This commit is contained in:
parent
e2937ff24f
commit
b99d6e1bed
|
@ -281,22 +281,29 @@ bool BKE_appdir_folder_caches(char *r_path, const size_t path_len)
|
|||
*/
|
||||
bool BKE_appdir_font_folder_default(char *dir)
|
||||
{
|
||||
char test_dir[FILE_MAXDIR];
|
||||
test_dir[0] = '\0';
|
||||
|
||||
#ifdef WIN32
|
||||
wchar_t wpath[FILE_MAXDIR];
|
||||
if (SHGetSpecialFolderPathW(0, wpath, CSIDL_FONTS, 0)) {
|
||||
wcscat(wpath, L"\\");
|
||||
BLI_strncpy_wchar_as_utf8(dir, wpath, FILE_MAXDIR);
|
||||
return (BLI_exists(dir));
|
||||
BLI_strncpy_wchar_as_utf8(test_dir, wpath, sizeof(test_dir));
|
||||
}
|
||||
return false;
|
||||
#elif defined(__APPLE__)
|
||||
const char *home = BLI_getenv("HOME");
|
||||
BLI_snprintf(dir, FILE_MAXDIR, "%s/Library/Fonts/", home);
|
||||
return (BLI_exists(dir));
|
||||
if (home) {
|
||||
BLI_path_join(test_dir, sizeof(test_dir), home, "Library", "Fonts", NULL);
|
||||
}
|
||||
#else
|
||||
BLI_strncpy(dir, "/usr/share/fonts/", FILE_MAXDIR);
|
||||
return (BLI_exists(dir));
|
||||
STRNCPY(test_dir, "/usr/share/fonts");
|
||||
#endif
|
||||
|
||||
if (test_dir[0] && BLI_exists(test_dir)) {
|
||||
BLI_strncpy(dir, test_dir, FILE_MAXDIR);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
|
Loading…
Reference in New Issue