* PATCH: zstat - PATH_MAX
@ 2000-09-22 22:12 Clint Adams
0 siblings, 0 replies; only message in thread
From: Clint Adams @ 2000-09-22 22:12 UTC (permalink / raw)
To: zsh-workers
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. */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2000-09-22 22:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-09-22 22:12 PATCH: zstat - PATH_MAX Clint Adams
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).