about summary refs log tree commit diff
path: root/Src/hist.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2009-03-19 15:00:18 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2009-03-19 15:00:18 +0000
commitcb6856d115b26fbe6d78e3e730a57e9c0e05e8b9 (patch)
treea42e224d0ccbeda8af4b9220501fe42839b27b55 /Src/hist.c
parent9e1a3e6d062522c77f17d8be947850ee824cee8e (diff)
downloadzsh-cb6856d115b26fbe6d78e3e730a57e9c0e05e8b9.tar.gz
zsh-cb6856d115b26fbe6d78e3e730a57e9c0e05e8b9.tar.xz
zsh-cb6856d115b26fbe6d78e3e730a57e9c0e05e8b9.zip
26754: tweak zgetdir() and test for realpath()
Diffstat (limited to 'Src/hist.c')
-rw-r--r--Src/hist.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/Src/hist.c b/Src/hist.c
index 4a2c12530..b843a2399 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -1522,7 +1522,7 @@ chabspath(char **junkptr)
 	current += 3;
     }
 #endif
-	
+
     for (;;) {
 	if (*current == '/') {
 #ifdef __CYGWIN__
@@ -1579,7 +1579,14 @@ chabspath(char **junkptr)
 int
 chrealpath(char **junkptr)
 {
+    char *str;
+#ifdef HAVE_CANONICALIZE_FILE_NAME
+    char *lastpos, *nonreal, *real;
+#else
+# ifdef HAVE_REAL_PATH
     char *lastpos, *nonreal, real[PATH_MAX];
+# endif
+#endif
 
     if (!**junkptr)
 	return 1;
@@ -1588,6 +1595,9 @@ chrealpath(char **junkptr)
     if (!chabspath(junkptr))
 	return 0;
 
+#if !defined(HAVE_REALPATH) && !defined(HAVE_CANONICALIZE_FILE_NAME)
+    return 1;
+#else
     /*
      * Notice that this means you cannot pass relative paths into this
      * function!
@@ -1600,7 +1610,19 @@ chrealpath(char **junkptr)
     lastpos = strend(*junkptr);
     nonreal = lastpos + 1;
 
-    while (!realpath(*junkptr, real)) {
+    while (!
+#ifdef HAVE_CANONICALIZE_FILE_NAME
+	   /*
+	    * This is a GNU extension to realpath(); it's the
+	    * same as calling realpath() with a NULL second argument
+	    * which uses malloc() to get memory.  The alternative
+	    * interface is easier to test for, however.
+	    */
+	   (real = canonicalize_file_name(*junkptr))
+#else
+	   realpath(*junkptr, real)
+#endif
+	) {
 	if (errno == EINVAL || errno == ELOOP ||
 	    errno == ENAMETOOLONG || errno == ENOMEM)
 	    return 0;
@@ -1615,7 +1637,7 @@ chrealpath(char **junkptr)
 	*nonreal = '\0';
     }
 
-    char *str = nonreal;
+    str = nonreal;
     while (str <= lastpos) {
 	if (*str == '\0')
 	    *str = '/';
@@ -1623,6 +1645,10 @@ chrealpath(char **junkptr)
     }
 
     *junkptr = metafy(bicat(real, nonreal), -1, META_HEAPDUP);
+#ifdef HAVE_CANONICALIZE_FILE_NAME
+    free(real);
+#endif
+#endif
 
     return 1;
 }