[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59316] trunk/blender: Get rid of PATH_MAX in Ghost System X11

Sergey Sharybin sergey.vfx at gmail.com
Tue Aug 20 10:33:04 CEST 2013


Revision: 59316
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59316
Author:   nazgul
Date:     2013-08-20 08:33:04 +0000 (Tue, 20 Aug 2013)
Log Message:
-----------
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!

Modified Paths:
--------------
    trunk/blender/intern/ghost/intern/GHOST_SystemPathsX11.cpp
    trunk/blender/source/blender/blenlib/BLI_fileops.h
    trunk/blender/source/blender/blenlib/BLI_winstuff.h
    trunk/blender/source/blender/blenlib/intern/storage.c

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemPathsX11.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemPathsX11.cpp	2013-08-20 07:59:50 UTC (rev 59315)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemPathsX11.cpp	2013-08-20 08:33:04 UTC (rev 59316)
@@ -42,8 +42,10 @@
 #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";
 #else
@@ -62,9 +64,8 @@
 {
 	/* 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::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 (user_path.empty()) {
+			const char *home = getenv("HOME");
 
-		if (home) {
-			snprintf(user_path, sizeof(user_path), "%s/.blender/%s", home, versionstr);
-			return (GHOST_TUns8 *)user_path;
+			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();
 	}
 }
 

Modified: trunk/blender/source/blender/blenlib/BLI_fileops.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_fileops.h	2013-08-20 07:59:50 UTC (rev 59315)
+++ trunk/blender/source/blender/blenlib/BLI_fileops.h	2013-08-20 08:33:04 UTC (rev 59316)
@@ -43,6 +43,12 @@
 /* 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 */

Modified: trunk/blender/source/blender/blenlib/BLI_winstuff.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_winstuff.h	2013-08-20 07:59:50 UTC (rev 59315)
+++ trunk/blender/source/blender/blenlib/BLI_winstuff.h	2013-08-20 08:33:04 UTC (rev 59316)
@@ -100,7 +100,6 @@
 // not accepted by access() on windows
 //#  define	X_OK	1
 #  define	F_OK	0
-#  define	PATH_MAX 4096
 #endif
 
 #ifndef FREE_WINDOWS

Modified: trunk/blender/source/blender/blenlib/intern/storage.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/storage.c	2013-08-20 07:59:50 UTC (rev 59315)
+++ trunk/blender/source/blender/blenlib/intern/storage.c	2013-08-20 08:33:04 UTC (rev 59316)
@@ -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 @@
 				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 @@
 					dir_ctx->nrfiles++;
 					file++;
 					dlink = dlink->next;
-#ifndef PATH_MAX
-					MEM_freeN(fullname);
-#endif
 				}
 			}
 			else {




More information about the Bf-blender-cvs mailing list