From: Sebastian Wilhelmi Date: Mon, 20 Mar 2000 16:01:41 +0000 (+0000) Subject: Make g_get_current_dir work on systems with unlimited pathname length like X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=2c4b4788fd8662cc26b248859c156c20fe9e7e3a;p=dana%2Fcg-glib.git Make g_get_current_dir work on systems with unlimited pathname length like 2000-03-20 Sebastian Wilhelmi * 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 . --- diff --git a/ChangeLog b/ChangeLog index 8d8c41e3..b15f5ba3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2000-03-20 Sebastian Wilhelmi + + * 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 + . + 2000-03-17 Sebastian Wilhelmi * giounix.c (g_io_unix_write, g_io_unix_read): Interpret EINTR as diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 8d8c41e3..b15f5ba3 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,11 @@ +2000-03-20 Sebastian Wilhelmi + + * 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 + . + 2000-03-17 Sebastian Wilhelmi * giounix.c (g_io_unix_write, g_io_unix_read): Interpret EINTR as diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 8d8c41e3..b15f5ba3 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,11 @@ +2000-03-20 Sebastian Wilhelmi + + * 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 + . + 2000-03-17 Sebastian Wilhelmi * giounix.c (g_io_unix_write, g_io_unix_read): Interpret EINTR as diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 8d8c41e3..b15f5ba3 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,11 @@ +2000-03-20 Sebastian Wilhelmi + + * 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 + . + 2000-03-17 Sebastian Wilhelmi * giounix.c (g_io_unix_write, g_io_unix_read): Interpret EINTR as diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 8d8c41e3..b15f5ba3 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,11 @@ +2000-03-20 Sebastian Wilhelmi + + * 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 + . + 2000-03-17 Sebastian Wilhelmi * giounix.c (g_io_unix_write, g_io_unix_read): Interpret EINTR as diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 8d8c41e3..b15f5ba3 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,11 @@ +2000-03-20 Sebastian Wilhelmi + + * 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 + . + 2000-03-17 Sebastian Wilhelmi * giounix.c (g_io_unix_write, g_io_unix_read): Interpret EINTR as diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 8d8c41e3..b15f5ba3 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,11 @@ +2000-03-20 Sebastian Wilhelmi + + * 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 + . + 2000-03-17 Sebastian Wilhelmi * giounix.c (g_io_unix_write, g_io_unix_read): Interpret EINTR as diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 8d8c41e3..b15f5ba3 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,11 @@ +2000-03-20 Sebastian Wilhelmi + + * 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 + . + 2000-03-17 Sebastian Wilhelmi * giounix.c (g_io_unix_write, g_io_unix_read): Interpret EINTR as diff --git a/glib/gutils.c b/glib/gutils.c index 62b4e54e..b858a7db 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -67,12 +67,14 @@ #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) diff --git a/gutils.c b/gutils.c index 62b4e54e..b858a7db 100644 --- a/gutils.c +++ b/gutils.c @@ -67,12 +67,14 @@ #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)