Rework string_quote API
string_quote() has proven to be too hard to use, replace it with
print_quoted_string() that does memory allocation and prints the result.
* defs.h (string_quote): Remove.
(QUOTE_0_TERMINATED, QUOTE_OMIT_LEADING_TRAILING_QUOTES): New macros.
(print_quoted_string): New prototype.
* util.c (string_quote): Make static; take "style" flags instead
of "len", treat QUOTE_0_TERMINATED style flag as former (len == -1);
add QUOTE_OMIT_LEADING_TRAILING_QUOTES style flag support.
(ALLOCA_CUTOFF, use_alloca): New macros.
(print_quoted_string): New function.
(printpathn, printstr): Update to new API.
* loop.c (loop_ioctl): Likewise.
* mtd.c (ubi_ioctl): Likewise.
* net.c (print_scm_security): Likewise.
* socketutils.c (unix_parse_response): Likewise.
diff --git a/socketutils.c b/socketutils.c
index 93bb0c3..2de59cd 100644
--- a/socketutils.c
+++ b/socketutils.c
@@ -252,13 +252,13 @@
tprintf("->%u", peer);
if (path_len) {
if (path[0] == '\0') {
- char *outstr = alloca(4 * path_len - 1);
- string_quote(path + 1, outstr, -1, path_len);
- tprintf(",@%s", outstr);
+ tprints(",@");
+ print_quoted_string(path + 1, path_len,
+ QUOTE_0_TERMINATED);
} else {
- char *outstr = alloca(4 * path_len + 3);
- string_quote(path, outstr, -1, path_len + 1);
- tprintf(",%s", outstr);
+ tprints(",");
+ print_quoted_string(path, path_len + 1,
+ QUOTE_0_TERMINATED);
}
}
tprints("]");