Make g_get_current_dir work on systems with unlimited pathname length like
authorSebastian Wilhelmi <wilhelmi@ira.uka.de>
Mon, 20 Mar 2000 16:01:41 +0000 (16:01 +0000)
committerSebastian Wilhelmi <wilhelmi@src.gnome.org>
Mon, 20 Mar 2000 16:01:41 +0000 (16:01 +0000)
2000-03-20  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>

* gutils.c (g_get_current_dir): Make g_get_current_dir work on
systems with unlimited pathname length like the HURD (It worked
there before, but only for pathes shorter than 2048). Closes
Bug#4525 as reported by Marcus Brinkmann
<Marcus.Brinkmann@ruhr-uni-bochum.de>.

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
glib/gutils.c
gutils.c

index 8d8c41e..b15f5ba 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2000-03-20  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * gutils.c (g_get_current_dir): Make g_get_current_dir work on
+       systems with unlimited pathname length like the HURD (It worked
+       there before, but only for pathes shorter than 2048). Closes
+       Bug#4525 as reported by Marcus Brinkmann
+       <Marcus.Brinkmann@ruhr-uni-bochum.de>.
+
 2000-03-17  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * giounix.c (g_io_unix_write, g_io_unix_read): Interpret EINTR as
index 8d8c41e..b15f5ba 100644 (file)
@@ -1,3 +1,11 @@
+2000-03-20  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * gutils.c (g_get_current_dir): Make g_get_current_dir work on
+       systems with unlimited pathname length like the HURD (It worked
+       there before, but only for pathes shorter than 2048). Closes
+       Bug#4525 as reported by Marcus Brinkmann
+       <Marcus.Brinkmann@ruhr-uni-bochum.de>.
+
 2000-03-17  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * giounix.c (g_io_unix_write, g_io_unix_read): Interpret EINTR as
index 8d8c41e..b15f5ba 100644 (file)
@@ -1,3 +1,11 @@
+2000-03-20  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * gutils.c (g_get_current_dir): Make g_get_current_dir work on
+       systems with unlimited pathname length like the HURD (It worked
+       there before, but only for pathes shorter than 2048). Closes
+       Bug#4525 as reported by Marcus Brinkmann
+       <Marcus.Brinkmann@ruhr-uni-bochum.de>.
+
 2000-03-17  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * giounix.c (g_io_unix_write, g_io_unix_read): Interpret EINTR as
index 8d8c41e..b15f5ba 100644 (file)
@@ -1,3 +1,11 @@
+2000-03-20  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * gutils.c (g_get_current_dir): Make g_get_current_dir work on
+       systems with unlimited pathname length like the HURD (It worked
+       there before, but only for pathes shorter than 2048). Closes
+       Bug#4525 as reported by Marcus Brinkmann
+       <Marcus.Brinkmann@ruhr-uni-bochum.de>.
+
 2000-03-17  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * giounix.c (g_io_unix_write, g_io_unix_read): Interpret EINTR as
index 8d8c41e..b15f5ba 100644 (file)
@@ -1,3 +1,11 @@
+2000-03-20  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * gutils.c (g_get_current_dir): Make g_get_current_dir work on
+       systems with unlimited pathname length like the HURD (It worked
+       there before, but only for pathes shorter than 2048). Closes
+       Bug#4525 as reported by Marcus Brinkmann
+       <Marcus.Brinkmann@ruhr-uni-bochum.de>.
+
 2000-03-17  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * giounix.c (g_io_unix_write, g_io_unix_read): Interpret EINTR as
index 8d8c41e..b15f5ba 100644 (file)
@@ -1,3 +1,11 @@
+2000-03-20  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * gutils.c (g_get_current_dir): Make g_get_current_dir work on
+       systems with unlimited pathname length like the HURD (It worked
+       there before, but only for pathes shorter than 2048). Closes
+       Bug#4525 as reported by Marcus Brinkmann
+       <Marcus.Brinkmann@ruhr-uni-bochum.de>.
+
 2000-03-17  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * giounix.c (g_io_unix_write, g_io_unix_read): Interpret EINTR as
index 8d8c41e..b15f5ba 100644 (file)
@@ -1,3 +1,11 @@
+2000-03-20  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * gutils.c (g_get_current_dir): Make g_get_current_dir work on
+       systems with unlimited pathname length like the HURD (It worked
+       there before, but only for pathes shorter than 2048). Closes
+       Bug#4525 as reported by Marcus Brinkmann
+       <Marcus.Brinkmann@ruhr-uni-bochum.de>.
+
 2000-03-17  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * giounix.c (g_io_unix_write, g_io_unix_read): Interpret EINTR as
index 8d8c41e..b15f5ba 100644 (file)
@@ -1,3 +1,11 @@
+2000-03-20  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * gutils.c (g_get_current_dir): Make g_get_current_dir work on
+       systems with unlimited pathname length like the HURD (It worked
+       there before, but only for pathes shorter than 2048). Closes
+       Bug#4525 as reported by Marcus Brinkmann
+       <Marcus.Brinkmann@ruhr-uni-bochum.de>.
+
 2000-03-17  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * giounix.c (g_io_unix_write, g_io_unix_read): Interpret EINTR as
index 62b4e54..b858a7d 100644 (file)
 #include "glib.h"
 
 #ifdef MAXPATHLEN
-#define        G_PATH_LENGTH   (MAXPATHLEN + 1)
+#define        G_PATH_LENGTH   MAXPATHLEN
 #elif  defined (PATH_MAX)
-#define        G_PATH_LENGTH   (PATH_MAX + 1)
-#else  /* !MAXPATHLEN */
-#define G_PATH_LENGTH   (2048 + 1)
-#endif /* !MAXPATHLEN && !PATH_MAX */
+#define        G_PATH_LENGTH   PATH_MAX
+#elif   defined (_PC_PATH_MAX)
+#define        G_PATH_LENGTH   sysconf(_PC_PATH_MAX)
+#else  
+#define G_PATH_LENGTH   2048
+#endif
 
 const guint glib_major_version = GLIB_MAJOR_VERSION;
 const guint glib_minor_version = GLIB_MINOR_VERSION;
@@ -334,17 +336,28 @@ g_get_current_dir (void)
 {
   gchar *buffer;
   gchar *dir;
-
-  buffer = g_new (gchar, G_PATH_LENGTH);
-  *buffer = 0;
+  static gulong max_len = (G_PATH_LENGTH == -1) ? 2048 : G_PATH_LENGTH;
   
   /* We don't use getcwd(3) on SUNOS, because, it does a popen("pwd")
    * and, if that wasn't bad enough, hangs in doing so.
    */
 #if    defined (sun) && !defined (__SVR4)
+  buffer = g_new (gchar, max_len + 1);
+  *buffer = 0;
   dir = getwd (buffer);
 #else  /* !sun */
-  dir = getcwd (buffer, G_PATH_LENGTH - 1);
+  while (1)
+    {
+      buffer = g_new (gchar, max_len + 1);
+      *buffer = 0;
+      dir = getcwd (buffer, max_len);
+
+      if (dir || errno != ERANGE)
+       break;
+
+      g_free (buffer);
+      max_len *= 2;
+    }
 #endif /* !sun */
   
   if (!dir || !*buffer)
index 62b4e54..b858a7d 100644 (file)
--- a/gutils.c
+++ b/gutils.c
 #include "glib.h"
 
 #ifdef MAXPATHLEN
-#define        G_PATH_LENGTH   (MAXPATHLEN + 1)
+#define        G_PATH_LENGTH   MAXPATHLEN
 #elif  defined (PATH_MAX)
-#define        G_PATH_LENGTH   (PATH_MAX + 1)
-#else  /* !MAXPATHLEN */
-#define G_PATH_LENGTH   (2048 + 1)
-#endif /* !MAXPATHLEN && !PATH_MAX */
+#define        G_PATH_LENGTH   PATH_MAX
+#elif   defined (_PC_PATH_MAX)
+#define        G_PATH_LENGTH   sysconf(_PC_PATH_MAX)
+#else  
+#define G_PATH_LENGTH   2048
+#endif
 
 const guint glib_major_version = GLIB_MAJOR_VERSION;
 const guint glib_minor_version = GLIB_MINOR_VERSION;
@@ -334,17 +336,28 @@ g_get_current_dir (void)
 {
   gchar *buffer;
   gchar *dir;
-
-  buffer = g_new (gchar, G_PATH_LENGTH);
-  *buffer = 0;
+  static gulong max_len = (G_PATH_LENGTH == -1) ? 2048 : G_PATH_LENGTH;
   
   /* We don't use getcwd(3) on SUNOS, because, it does a popen("pwd")
    * and, if that wasn't bad enough, hangs in doing so.
    */
 #if    defined (sun) && !defined (__SVR4)
+  buffer = g_new (gchar, max_len + 1);
+  *buffer = 0;
   dir = getwd (buffer);
 #else  /* !sun */
-  dir = getcwd (buffer, G_PATH_LENGTH - 1);
+  while (1)
+    {
+      buffer = g_new (gchar, max_len + 1);
+      *buffer = 0;
+      dir = getcwd (buffer, max_len);
+
+      if (dir || errno != ERANGE)
+       break;
+
+      g_free (buffer);
+      max_len *= 2;
+    }
 #endif /* !sun */
   
   if (!dir || !*buffer)