Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: zstat - PATH_MAX



This also removes the duplication loop to its own function and generalizes
it for any character.

Index: Src/string.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/string.c,v
retrieving revision 1.1
diff -u -r1.1 string.c
--- Src/string.c	2000/09/19 15:54:31	1.1
+++ Src/string.c	2000/09/22 22:03:40
@@ -133,3 +133,23 @@
 {
     return strcat(realloc(base, strlen(base) + strlen(append) + 1), append);
 }
+
+/* Duplicate a string, stripping delimiters. */
+
+/**/
+mod_export char *
+ztrdupstrip(const char *nam, char delim)
+{
+    char *p, *buf;
+
+    buf = zalloc(strlen(nam));
+
+    for (p = buf; *nam; nam++)
+        if (*nam == delim && nam[1])
+            *p++ = *++nam;
+        else
+            *p++ = *nam;
+    *p = '\0';
+
+    return buf;
+}
Index: Src/Zle/compresult.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compresult.c,v
retrieving revision 1.21
diff -u -r1.21 compresult.c
--- Src/Zle/compresult.c	2000/06/28 07:29:59	1.21
+++ Src/Zle/compresult.c	2000/09/22 22:03:45
@@ -731,19 +731,17 @@
 mod_export int
 ztat(char *nam, struct stat *buf, int ls)
 {
-    char b[PATH_MAX], *p;
+    int e;
+    char *b;
 
     if (!(ls ? lstat(nam, buf) : stat(nam, buf)))
 	return 0;
 
-    for (p = b; p < b + sizeof(b) - 1 && *nam; nam++)
-	if (*nam == '\\' && nam[1])
-	    *p++ = *++nam;
-	else
-	    *p++ = *nam;
-    *p = '\0';
+    b = ztrdupstrip(nam, '\\');
 
-    return ls ? lstat(b, buf) : stat(b, buf);
+    e = ls ? lstat(b, buf) : stat(b, buf);
+    zsfree(b);
+    return e;
 }
 
 /* Insert a single match in the command line. */



Messages sorted by: Reverse Date, Date, Thread, Author