const char *f;
char *r, *t;
+ /* Does C style string escaping. May be reversed with cunescape(). */
+
assert(s || n == 0);
- /* Does C style string escaping. May be reversed with
- * cunescape(). */
+ if (n == SIZE_MAX)
+ n = strlen(s);
+
+ if (n > (SIZE_MAX - 1) / 4)
+ return NULL;
r = new(char, n*4 + 1);
if (!r)
return r;
}
-char* cescape(const char *s) {
- assert(s);
-
- return cescape_length(s, strlen(s));
-}
-
int cunescape_one(const char *p, size_t length, char32_t *ret, bool *eight_bit, bool accept_nul) {
int r = 1;
assert(s || len == 0);
+ if (len == SIZE_MAX)
+ len = strlen(s);
+
+ if (len > (SIZE_MAX - 1) / 4)
+ return NULL;
+
t = buf = new(char, len * 4 + 1);
if (!buf)
return NULL;
SHELL_ESCAPE_EMPTY = 1 << 2, /* Format empty arguments as "". */
} ShellEscapeFlags;
-char* cescape(const char *s);
-char* cescape_length(const char *s, size_t n);
int cescape_char(char c, char *buf);
+char* cescape_length(const char *s, size_t n);
+static inline char* cescape(const char *s) {
+ return cescape_length(s, SIZE_MAX);
+}
int cunescape_one(const char *p, size_t length, char32_t *ret, bool *eight_bit, bool accept_nul);