1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-11-19 13:33:52 +01:00

12859: dynamically-allocate buffer in ztat(), ztrdupstring()

This commit is contained in:
Clint Adams 2000-09-22 22:16:15 +00:00
parent 430e294795
commit 2a625db39d
3 changed files with 32 additions and 8 deletions

@ -1,3 +1,9 @@
2000-09-22 Clint Adams <schizo@debian.org>
* 12859: Src/string.c, Src/Zle/compresult.c:
dynamically allocate buffer in ztat, remove
duplication loop to ztrdupstrip().
2000-09-20 Bart Schaefer <schaefer@zsh.org>
* 12851, 12852: Completion/Commands/_expand_word,

@ -731,19 +731,17 @@ do_ambiguous(void)
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. */

@ -133,3 +133,23 @@ appstr(char *base, char const *append)
{
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;
}