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

PATCH: bin_ln - PATH_MAX



> After 12828, utils.c doesn't compile when MAILDIR_SUPPORT is defined.
> It must have been issuing warnings about prototypes even before that, so
> I can't believe it's a very widely-used [*] feature, but as commited it
> has a structure-access error (->d.name should be ->d_name).

That was my typo in 12827.  Thanks for the cleanup.

> * Move dyncat() and tricat() from glob.c to utils.c; they've not been
>   specific to the glob code for some years now.  (Though it may be time
>   to break utils.c up into a couple of files, or move some of the string
>   allocation functions to mem.c where ztrdup() lives.)

Why not a string.c for all of those?

> I'm certain we can replace all uses of PATH_MAX with one of VARARR(),
> tricat(), zhtricat(), or ztrdup()+appstr().  The point is to analyze the
> way the buffer is used and pick the best of those alternatives, not just
> to pick one and use it everywhere.

PATH_MAX removed from bin_ln

Index: Src/Modules/files.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/files.c,v
retrieving revision 1.7
diff -u -r1.7 files.c
--- Src/Modules/files.c	2000/08/14 07:30:29	1.7
+++ Src/Modules/files.c	2000/09/18 17:10:23
@@ -186,10 +186,10 @@
 bin_ln(char *nam, char **args, char *ops, int func)
 {
     MoveFunc move;
-    int flags, space, err = 0;
-    char **a, *ptr, *rp;
+    int flags, err = 0;
+    char **a, *ptr, *rp, *buf;
     struct stat st;
-    char buf[PATH_MAX * 2 + 1];
+    size_t blen;
 
 
     if(func == BIN_MV) {
@@ -203,7 +203,7 @@
 	    move = (MoveFunc) symlink;
 	else
 #endif
-	     {
+	{
 	    move = (MoveFunc) link;
 	    if(!ops['d'])
 		flags |= MV_NODIRS;
@@ -229,31 +229,24 @@
 	    args[1] = args[0];
     }
     return domove(nam, move, args[0], args[1], flags);
-    havedir:
-    strcpy(buf, *a);
+ havedir:
+    buf = ztrdup(*a);
     *a = NULL;
-    space = PATH_MAX - 1 - ztrlen(buf);
-    rp = strchr(buf, 0);
-    *rp++ = '/';
+    buf = appstr(buf, "/");
+    blen = strlen(buf);
     for(; *args; args++) {
-	if(ztrlen(*args) > PATH_MAX) {
-	    zwarnnam(nam, "%s: %e", *args, ENAMETOOLONG);
-	    err = 1;
-	    continue;
-	}
+
 	ptr = strrchr(*args, '/');
 	if(ptr)
 	    ptr++;
 	else
 	    ptr = *args;
-	if(ztrlen(ptr) > space) {
-	    zwarnnam(nam, "%s: %e", ptr, ENAMETOOLONG);
-	    err = 1;
-	    continue;
-	}
-	strcpy(rp, ptr);
+
+	buf[blen] = 0;
+	buf = appstr(buf, ptr);
 	err |= domove(nam, move, *args, buf, flags);
     }
+    zsfree(buf);
     return err;
 }
 



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