diff options
-rw-r--r-- | intern/ghost/intern/GHOST_SystemPathsX11.cpp | 50 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_fileops.h | 6 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_winstuff.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/storage.c | 15 |
4 files changed, 36 insertions, 36 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(); } } diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h index 0a6d95df40a..ca82086b529 100644 --- a/source/blender/blenlib/BLI_fileops.h +++ b/source/blender/blenlib/BLI_fileops.h @@ -43,6 +43,12 @@ extern "C" { /* for size_t (needed on windows) */ #include <stddef.h> +#include <limits.h> /* for PATH_MAX */ + +#ifndef PATH_MAX +# define PATH_MAX 4096 +#endif + struct gzFile; /* Common */ diff --git a/source/blender/blenlib/BLI_winstuff.h b/source/blender/blenlib/BLI_winstuff.h index 20a4c3c274e..e75ec7eef2c 100644 --- a/source/blender/blenlib/BLI_winstuff.h +++ b/source/blender/blenlib/BLI_winstuff.h @@ -100,7 +100,6 @@ extern "C" { // not accepted by access() on windows //# define X_OK 1 # define F_OK 0 -# define PATH_MAX 4096 #endif #ifndef FREE_WINDOWS diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index c1645c05359..e40527b1bb6 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -70,7 +70,6 @@ #ifdef WIN32 # include <io.h> # include <direct.h> -# include <limits.h> /* PATH_MAX */ # include "BLI_winstuff.h" # include "utfconv.h" #else @@ -255,18 +254,11 @@ static void bli_builddir(struct BuildDirCtx *dir_ctx, const char *dirname) struct dirlink * dlink = (struct dirlink *) dirbase.first; struct direntry *file = &dir_ctx->files[dir_ctx->nrfiles]; while (dlink) { -#ifdef PATH_MAX - char static_fullname[PATH_MAX]; - char *fullname = static_fullname; - size_t fullname_size = PATH_MAX; -#else - size_t fullname_size = strlen(dirname) + strlen(dlink->name) + 2; - char *fullname = MEM_mallocN(fullname_size, "bli_builddir fullname"); -#endif + char fullname[PATH_MAX]; memset(file, 0, sizeof(struct direntry)); file->relname = dlink->name; file->path = BLI_strdupcat(dirname, dlink->name); - BLI_join_dirfile(fullname, fullname_size, dirname, dlink->name); + BLI_join_dirfile(fullname, sizeof(fullname), dirname, dlink->name); // use 64 bit file size, only needed for WIN32 and WIN64. // Excluding other than current MSVC compiler until able to test #ifdef WIN32 @@ -288,9 +280,6 @@ static void bli_builddir(struct BuildDirCtx *dir_ctx, const char *dirname) dir_ctx->nrfiles++; file++; dlink = dlink->next; -#ifndef PATH_MAX - MEM_freeN(fullname); -#endif } } else { |