X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=quote.c;h=e3a4d4aef3478148ff89aebeba23e1cbf4202ba1;hb=4b4a5dbb17e1136275665024689625ed5cc5a03d;hp=a38786c177d090b36bcd13a13b08dbe42a2c2340;hpb=7cf67205ca68a157c6ffdb4e5a4ff231217c0871;p=git.git diff --git a/quote.c b/quote.c index a38786c17..e3a4d4aef 100644 --- a/quote.c +++ b/quote.c @@ -106,6 +106,35 @@ char *sq_quote_argv(const char** argv, int count) return buf; } +/* + * Append a string to a string buffer, with or without shell quoting. + * Return true if the buffer overflowed. + */ +int add_to_string(char **ptrp, int *sizep, const char *str, int quote) +{ + char *p = *ptrp; + int size = *sizep; + int oc; + int err = 0; + + if (quote) + oc = sq_quote_buf(p, size, str); + else { + oc = strlen(str); + memcpy(p, str, (size <= oc) ? size - 1 : oc); + } + + if (size <= oc) { + err = 1; + oc = size - 1; + } + + *ptrp += oc; + **ptrp = '\0'; + *sizep -= oc; + return err; +} + char *sq_dequote(char *arg) { char *dst = arg;