[gegl] Don't use PATH_MAX for portability reasons



commit 7d12e628b7fc112ee7a7b6ac7bcf79cd529d00e4
Author: Emilio Pozuelo Monfort <pochu27 gmail com>
Date:   Sat Feb 19 17:20:26 2011 +0000

    Don't use PATH_MAX for portability reasons
    
    Use dynamic allocation instead. Fixes FTBFS on GNU/Hurd.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=617416
    
    Jon Nordby: Also remove last PATH_MAX usage, and _XOPEN_SOURCE define

 bin/gegl.c      |   16 +++++-----------
 gegl/gegl-xml.c |   20 ++++++++------------
 2 files changed, 13 insertions(+), 23 deletions(-)
---
diff --git a/bin/gegl.c b/bin/gegl.c
index 157f68f..661377d 100644
--- a/bin/gegl.c
+++ b/bin/gegl.c
@@ -38,9 +38,6 @@
 #ifdef G_OS_WIN32
 #include <direct.h>
 #define getcwd(b,n) _getcwd(b,n)
-#ifndef PATH_MAX
-#define PATH_MAX _MAX_PATH
-#endif
 #define realpath(a,b) _fullpath(b,a,_MAX_PATH)
 #endif
 
@@ -104,24 +101,21 @@ main (gint    argc,
 
   if (o->xml)
     {
-      gchar *tmp = g_malloc(PATH_MAX);
-      tmp = getcwd (tmp, PATH_MAX);
-      path_root = tmp;
+      path_root = g_get_current_dir ();
     }
   else if (o->file)
     {
       if (!strcmp (o->file, "-"))  /* read XML from stdin */
         {
-          gchar *tmp = g_malloc(PATH_MAX);
-          tmp = getcwd (tmp, PATH_MAX);
-          path_root = tmp;
+          path_root = g_get_current_dir ();
         }
       else
         {
-          gchar real_path[PATH_MAX];
+          gchar *tmp;
           gchar *temp1 = g_strdup (o->file);
           gchar *temp2 = g_path_get_dirname (temp1);
-          path_root = g_strdup (realpath (temp2, real_path));
+          path_root = g_strdup (tmp = realpath (temp2, NULL));
+          g_free (tmp);
           g_free (temp1);
           g_free (temp2);
         }
diff --git a/gegl/gegl-xml.c b/gegl/gegl-xml.c
index cbb67ae..973afc3 100644
--- a/gegl/gegl-xml.c
+++ b/gegl/gegl-xml.c
@@ -17,9 +17,6 @@
  */
 #include "config.h"
 
-/* For clang, remove when getting rid of using PATH_MAX */
-#define _XOPEN_SOURCE 500
-
 #include <glib.h>
 #include <glib-object.h>
 #include <stdlib.h>
@@ -40,9 +37,6 @@
 #include "gegl-xml.h"
 
 #ifdef G_OS_WIN32
-#ifndef PATH_MAX
-#define PATH_MAX _MAX_PATH
-#endif
 #define realpath(a, b)    _fullpath (b, a, _MAX_PATH)
 #endif
 
@@ -129,7 +123,7 @@ set_clone_prop_as_well:
       else if (g_type_is_a (G_PARAM_SPEC_TYPE (paramspec),
                             GEGL_TYPE_PARAM_FILE_PATH))
         {
-          gchar buf[PATH_MAX];
+          gchar *buf;
 
           if (g_path_is_absolute (param_value))
             {
@@ -140,15 +134,15 @@ set_clone_prop_as_well:
               gchar * absolute_path;
               if (pd->path_root)
                 {
-                  g_snprintf (buf, sizeof (buf),
-                              "%s/%s", pd->path_root, param_value);
+                  buf = g_strdup_printf ("%s/%s", pd->path_root, param_value);
                 }
               else
                 {
-                  g_snprintf (buf, sizeof (buf), "./%s", param_value);
+                  buf = g_strdup_printf ("./%s", param_value);
                 }
 
               absolute_path = realpath (buf, NULL);
+              g_free (buf);
               if (absolute_path)
                 {
                   gegl_node_set (new, param_name, absolute_path, NULL);
@@ -571,13 +565,14 @@ gegl_node_new_from_file (const gchar   *path)
   GeglNode *node = NULL;
   GError   *err  = NULL;
   gchar    *script;
-  gchar     path_root[PATH_MAX];
+  gchar    *path_root;
   gchar    *dirname;
 
   g_assert (path);
 
   dirname = g_path_get_dirname (path);
-  if (!realpath (dirname, path_root))
+  path_root = realpath (dirname, NULL);
+  if (!path_root)
     {
       goto cleanup;
     }
@@ -593,6 +588,7 @@ gegl_node_new_from_file (const gchar   *path)
   node = gegl_node_new_from_xml (script, path_root);
 
 cleanup:
+  g_free (path_root);
   g_free (dirname);
   return node;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]