zsh-workers
 help / color / mirror / code / Atom feed
From: Clint Adams <schizo@debian.org>
To: Bart Schaefer <schaefer@candle.brasslantern.com>
Cc: zsh-workers@sunsite.auc.dk
Subject: Re: PATCH: zasprintf
Date: Sun, 17 Sep 2000 11:04:03 -0400	[thread overview]
Message-ID: <20000917110403.A4270@dman.com> (raw)
In-Reply-To: <1000917053751.ZM18817@candle.brasslantern.com>; from schaefer@candle.brasslantern.com on Sun, Sep 17, 2000 at 05:37:50AM +0000

> I don't think it's impossible either, but the only way to "provide a
> compatibility function for vsnprintf()" is to implement a parser for
> printf format-strings.  There simply is no way to fake it if you don't

Which is not unheard of.  sendmail, for example, has compatibility
snprintf/vsnprintf functions.

> have it.  I don't believe there's any use zsh could make of asprintf()
> that isn't better solved another way.  In particular:

If by "better" you mean "avoiding asprintf and dealing with a specialized
case."

> I don't have any such confidence that asprintf() would be cleaner or more
> efficient than, say, a realloc'ing version of tricat() that takes a char**
> to an allocated string as its first parameter.

Why, other than portability?  The difference in speed between asprintf()
and the real tricat() is negligible.

Speaking of the real tricat, this eliminates bin_dot's dependence on PATH_MAX:

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.32
diff -u -r1.32 builtin.c
--- Src/builtin.c	2000/09/14 15:55:00	1.32
+++ Src/builtin.c	2000/09/17 14:27:56
@@ -3250,11 +3250,10 @@
 {
     char **old, *old0 = NULL;
     int ret, diddot = 0, dotdot = 0;
-    char buf[PATH_MAX];
-    char *s, **t, *enam, *arg0;
+    char *s, **t, *enam, *arg0, *buf;
     struct stat st;
 
-    if (!*argv || strlen(*argv) >= PATH_MAX)
+    if (!*argv)
 	return 0;
     old = pparams;
     /* get arguments for the script */
@@ -3295,18 +3294,18 @@
 		    if (diddot)
 			continue;
 		    diddot = 1;
-		    strcpy(buf, arg0);
-		} else {
-		    if (strlen(*t) + strlen(arg0) + 1 >= PATH_MAX)
-			continue;
-		    sprintf(buf, "%s/%s", *t, arg0);
-		}
+		    buf = ztrdup(arg0);
+		} else
+		    buf = tricat(*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);
 	    }
 	}
     }


  reply	other threads:[~2000-09-17 15:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-09-16 18:53 Clint Adams
2000-09-17  0:47 ` Bart Schaefer
2000-09-17  1:10   ` PATH_MAX again Bart Schaefer
2000-09-17  4:25   ` PATCH: zasprintf Clint Adams
2000-09-17  5:37     ` Bart Schaefer
2000-09-17 15:04       ` Clint Adams [this message]
2000-09-17 16:13         ` Bart Schaefer
2000-09-17 16:43           ` Clint Adams
2000-09-17 12:21   ` Zefram
2000-09-18 13:28 ` Andrej Borsenkow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20000917110403.A4270@dman.com \
    --to=schizo@debian.org \
    --cc=schaefer@candle.brasslantern.com \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).