From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23997 invoked from network); 22 Sep 2000 22:13:19 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 22 Sep 2000 22:13:19 -0000 Received: (qmail 18688 invoked by alias); 22 Sep 2000 22:12:47 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 12859 Received: (qmail 18681 invoked from network); 22 Sep 2000 22:12:45 -0000 Date: Fri, 22 Sep 2000 18:12:43 -0400 From: Clint Adams To: zsh-workers@sunsite.auc.dk Subject: PATCH: zstat - PATH_MAX Message-ID: <20000922181243.A21141@dman.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii User-Agent: Mutt/1.1.2i 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. */