From 90d9d12ba9d3818a0074f33c5153b577d07aa8fd Mon Sep 17 00:00:00 2001 From: Mark Nudelman Date: Tue, 16 Jan 2024 18:14:33 -0800 Subject: [PATCH] Implement osc8_open(). --- filename.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/filename.c b/filename.c index 482d264..64d9ded 100644 --- a/filename.c +++ b/filename.c @@ -139,8 +139,9 @@ metachar(c) * Insert a backslash before each metacharacter in a string. */ public char * -shell_quote(s) +shell_quoten(s, slen) char *s; + size_t slen; { constant char *p; char *np; @@ -155,7 +156,7 @@ shell_quote(s) * Determine how big a string we need to allocate. */ len = 1; /* Trailing null byte */ - for (p = s; *p != '\0'; p++) + for (p = s; p < s + slen; p++) { len++; if (*p == openquote || *p == closequote) @@ -185,7 +186,7 @@ shell_quote(s) * We can't quote a string that contains quotes. */ return (NULL); - len = (int) strlen(s) + 3; + len = slen + 3; } /* * Allocate and construct the new string. @@ -193,10 +194,11 @@ shell_quote(s) newstr = np = (char *) ecalloc(len, sizeof(char)); if (use_quotes) { - SNPRINTF3(newstr, len, "%c%s%c", openquote, s, closequote); + SNPRINTF4(newstr, len, "%c%.*s%c", openquote, (int) slen, s, closequote); } else { - while (*s != '\0') + constant char *es = s + slen; + while (s < es) { if (metachar(*s)) { @@ -213,6 +215,11 @@ shell_quote(s) return (newstr); } +public char * shell_quote(char *s) +{ + return shell_quoten(s, strlen(s)); +} + /* * Return a pathname that points to a specified file in a specified directory. * Return NULL if the file does not exist in the directory. -- 2.43.0