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

PATCH: ztat revisited



This folds back the guts of ztrdupstrip into ztat, and changes
the memory allocation to VARARR.

Index: Src/string.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/string.c,v
retrieving revision 1.2
diff -u -r1.2 string.c
--- Src/string.c	2000/09/22 22:16:16	1.2
+++ Src/string.c	2000/09/27 19:19:32
@@ -133,23 +133,3 @@
 {
     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.22
diff -u -r1.22 compresult.c
--- Src/Zle/compresult.c	2000/09/22 22:16:16	1.22
+++ Src/Zle/compresult.c	2000/09/27 19:19:42
@@ -732,16 +732,22 @@
 ztat(char *nam, struct stat *buf, int ls)
 {
     int e;
-    char *b;
 
     if (!(ls ? lstat(nam, buf) : stat(nam, buf)))
 	return 0;
+    else {
+	char *p;
+	VARARR(char, b, strlen(nam) + 1);
 
-    b = ztrdupstrip(nam, '\\');
-
-    e = ls ? lstat(b, buf) : stat(b, buf);
-    zsfree(b);
-    return e;
+	for (p = b; *nam; nam++)
+	    if (*nam == '\\' && nam[1])
+		*p++ = *++nam;
+	    else
+		*p++ = *nam;
+	*p = '\0';
+	
+	return ls ? lstat(b, buf) : stat(b, buf);
+    }
 }
 
 /* Insert a single match in the command line. */



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