diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-08-20 12:33:04 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-08-20 12:33:04 +0400 |
commit | ba6b83d63dbd0c22b2a1a46d273d5bd51d039997 (patch) | |
tree | 0ff594608a26bf35a4ca6052fa172d0535680104 /intern | |
parent | 347ba7f159b4c01c3c7ecaeb2005b411d348eb47 (diff) |
Get rid of PATH_MAX in Ghost System X11
The reason of this is because PATH_MAX is not guaranteed
to be defined on all platforms and Hurd doesn't define it.
So either we need to support arbitrary long file path or
we need to define own maximum path length.
The rule here would be:
- If it's not big trouble to support arbitrary long paths
(i.e. in ghost by using std::string instead of char*)
then arbitrary long path shall be implemented.
- For other cases to use PATH_MAX please include BLI_fileops.h
which takes care of making sure PATH_MAX is defined.
Additional change: get rid of own changes made yesterday
which were supposed to make storage.c work fine in cases
PATH_MAX is not define, but on the second though it lead
to unneeded complication of the code.
Thanks Campbell for review!
Diffstat (limited to 'intern')
-rw-r--r-- | intern/ghost/intern/GHOST_SystemPathsX11.cpp | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/intern/ghost/intern/GHOST_SystemPathsX11.cpp b/intern/ghost/intern/GHOST_SystemPathsX11.cpp index 35bebd588c3..50eb68d9264 100644 --- a/intern/ghost/intern/GHOST_SystemPathsX11.cpp +++ b/intern/ghost/intern/GHOST_SystemPathsX11.cpp @@ -42,7 +42,9 @@ #include <cstdlib> /* for exit */ #include <pwd.h> /* for get home without use getenv() */ -#include <limits.h> /* for PATH_MAX */ +#include <string> + +using std::string; #ifdef PREFIX static const char *static_path = PREFIX "/share"; @@ -62,9 +64,8 @@ const GHOST_TUns8 *GHOST_SystemPathsX11::getSystemDir(int, const char *versionst { /* no prefix assumes a portable build which only uses bundled scripts */ if (static_path) { - static char system_path[PATH_MAX]; - snprintf(system_path, sizeof(system_path), "%s/blender/%s", static_path, versionstr); - return (GHOST_TUns8 *)system_path; + static string system_path = string(static_path) + "/blender/" + versionstr; + return (GHOST_TUns8 *)system_path.c_str(); } return NULL; @@ -72,36 +73,41 @@ const GHOST_TUns8 *GHOST_SystemPathsX11::getSystemDir(int, const char *versionst const GHOST_TUns8 *GHOST_SystemPathsX11::getUserDir(int version, const char *versionstr) const { - static char user_path[PATH_MAX]; + static string user_path = ""; /* in blender 2.64, we migrate to XDG. to ensure the copy previous settings * operator works we give a different path depending on the requested version */ if (version < 264) { - const char *home = getenv("HOME"); - - if (home) { - snprintf(user_path, sizeof(user_path), "%s/.blender/%s", home, versionstr); - return (GHOST_TUns8 *)user_path; + if (user_path.empty()) { + const char *home = getenv("HOME"); + + if (home) { + user_path = string(home) + "/.blender/" + versionstr; + } + else { + return NULL; + } } - - return NULL; + return (GHOST_TUns8 *)user_path.c_str(); } else { - const char *home = getenv("XDG_CONFIG_HOME"); + if (user_path.empty()) { + const char *home = getenv("XDG_CONFIG_HOME"); - if (home) { - snprintf(user_path, sizeof(user_path), "%s/blender/%s", home, versionstr); - } - else { - home = getenv("HOME"); + if (home) { + user_path = string(home) + "/blender/" + versionstr; + } + else { + home = getenv("HOME"); - if (home == NULL) - home = getpwuid(getuid())->pw_dir; + if (home == NULL) + home = getpwuid(getuid())->pw_dir; - snprintf(user_path, sizeof(user_path), "%s/.config/blender/%s", home, versionstr); + user_path = string(home) + "/.config/blender/" + versionstr; + } } - return (const GHOST_TUns8 *)user_path; + return (const GHOST_TUns8 *)user_path.c_str(); } } |