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

Re: PATCH: zasprintf



> This is a case where a zsh-heap-allocating version of tricat() would be
> slightly preferable to a permanent-heap-allocating version.

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.34
diff -u -r1.34 builtin.c
--- Src/builtin.c	2000/09/17 16:24:06	1.34
+++ Src/builtin.c	2000/09/17 16:38:39
@@ -3297,25 +3297,25 @@
 		break;
 	    }
 	if (!*s || (ret && isset(PATHDIRS) && diddot < 2 && dotdot == 0)) {
+	    pushheap();
 	    /* search path for script */
 	    for (t = path; *t; t++) {
 		if (!(*t)[0] || ((*t)[0] == '.' && !(*t)[1])) {
 		    if (diddot)
 			continue;
 		    diddot = 1;
-		    buf = ztrdup(arg0);
+		    buf = dupstring(arg0);
 		} else
-		    buf = tricat(*t, "/", arg0);
+		    buf = zhtricat(*t, "/", arg0);
 
 		s = unmeta(buf);
 		if (access(s, F_OK) == 0 && stat(s, &st) >= 0
 		    && !S_ISDIR(st.st_mode)) {
 		    ret = source(enam = buf);
-		    zsfree(buf);
 		    break;
 		}
-		zsfree(buf);
 	    }
+	    popheap();
 	}
     }
     /* clean up and return */
Index: Src/utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
retrieving revision 1.14
diff -u -r1.14 utils.c
--- Src/utils.c	2000/08/29 20:27:48	1.14
+++ Src/utils.c	2000/09/17 16:38:46
@@ -3473,6 +3473,20 @@
 }
 
 /**/
+mod_export char *
+zhtricat(char const *s1, char const *s2, char const *s3)
+{
+    char *ptr;
+    
+    ptr = (char *)zhalloc(strlen(s1) + strlen(s2) + strlen(s3) + 1);
+    strcpy(ptr, s1);
+    strcat(ptr, s2);
+    strcat(ptr, s3);
+    return ptr;
+}
+
+
+/**/
 static int
 upchdir(int n)
 {



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