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!
This commit is contained in:
2013-08-20 08:33:04 +00:00
parent 347ba7f159
commit ba6b83d63d
4 changed files with 35 additions and 35 deletions

View File

@@ -42,7 +42,9 @@
#include <cstdlib> /* for exit */ #include <cstdlib> /* for exit */
#include <pwd.h> /* for get home without use getenv() */ #include <pwd.h> /* for get home without use getenv() */
#include <limits.h> /* for PATH_MAX */ #include <string>
using std::string;
#ifdef PREFIX #ifdef PREFIX
static const char *static_path = PREFIX "/share"; 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 */ /* no prefix assumes a portable build which only uses bundled scripts */
if (static_path) { if (static_path) {
static char system_path[PATH_MAX]; static string system_path = string(static_path) + "/blender/" + versionstr;
snprintf(system_path, sizeof(system_path), "%s/blender/%s", static_path, versionstr); return (GHOST_TUns8 *)system_path.c_str();
return (GHOST_TUns8 *)system_path;
} }
return NULL; 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 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 /* 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 */ * operator works we give a different path depending on the requested version */
if (version < 264) { if (version < 264) {
const char *home = getenv("HOME"); if (user_path.empty()) {
const char *home = getenv("HOME");
if (home) { if (home) {
snprintf(user_path, sizeof(user_path), "%s/.blender/%s", home, versionstr); user_path = string(home) + "/.blender/" + versionstr;
return (GHOST_TUns8 *)user_path; }
else {
return NULL;
}
} }
return (GHOST_TUns8 *)user_path.c_str();
return NULL;
} }
else { else {
const char *home = getenv("XDG_CONFIG_HOME"); if (user_path.empty()) {
const char *home = getenv("XDG_CONFIG_HOME");
if (home) { if (home) {
snprintf(user_path, sizeof(user_path), "%s/blender/%s", home, versionstr); user_path = string(home) + "/blender/" + versionstr;
} }
else { else {
home = getenv("HOME"); home = getenv("HOME");
if (home == NULL) if (home == NULL)
home = getpwuid(getuid())->pw_dir; 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();
} }
} }

View File

@@ -43,6 +43,12 @@ extern "C" {
/* for size_t (needed on windows) */ /* for size_t (needed on windows) */
#include <stddef.h> #include <stddef.h>
#include <limits.h> /* for PATH_MAX */
#ifndef PATH_MAX
# define PATH_MAX 4096
#endif
struct gzFile; struct gzFile;
/* Common */ /* Common */

View File

@@ -100,7 +100,6 @@ extern "C" {
// not accepted by access() on windows // not accepted by access() on windows
//# define X_OK 1 //# define X_OK 1
# define F_OK 0 # define F_OK 0
# define PATH_MAX 4096
#endif #endif
#ifndef FREE_WINDOWS #ifndef FREE_WINDOWS

View File

@@ -70,7 +70,6 @@
#ifdef WIN32 #ifdef WIN32
# include <io.h> # include <io.h>
# include <direct.h> # include <direct.h>
# include <limits.h> /* PATH_MAX */
# include "BLI_winstuff.h" # include "BLI_winstuff.h"
# include "utfconv.h" # include "utfconv.h"
#else #else
@@ -255,18 +254,11 @@ static void bli_builddir(struct BuildDirCtx *dir_ctx, const char *dirname)
struct dirlink * dlink = (struct dirlink *) dirbase.first; struct dirlink * dlink = (struct dirlink *) dirbase.first;
struct direntry *file = &dir_ctx->files[dir_ctx->nrfiles]; struct direntry *file = &dir_ctx->files[dir_ctx->nrfiles];
while (dlink) { while (dlink) {
#ifdef PATH_MAX char fullname[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
memset(file, 0, sizeof(struct direntry)); memset(file, 0, sizeof(struct direntry));
file->relname = dlink->name; file->relname = dlink->name;
file->path = BLI_strdupcat(dirname, 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. // use 64 bit file size, only needed for WIN32 and WIN64.
// Excluding other than current MSVC compiler until able to test // Excluding other than current MSVC compiler until able to test
#ifdef WIN32 #ifdef WIN32
@@ -288,9 +280,6 @@ static void bli_builddir(struct BuildDirCtx *dir_ctx, const char *dirname)
dir_ctx->nrfiles++; dir_ctx->nrfiles++;
file++; file++;
dlink = dlink->next; dlink = dlink->next;
#ifndef PATH_MAX
MEM_freeN(fullname);
#endif
} }
} }
else { else {