X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=quote.c;h=e220dcc280d9ed6be2e2357e2660c7e828f3631b;hb=5f468c4805c785115cd9c5f6a8f299f23a9034f5;hp=dcc23266109ce30e3fd098f3c76799b67b75a332;hpb=5ab2c0a47574c92f92ea3709b23ca35d96319edd;p=git.git diff --git a/quote.c b/quote.c index dcc232661..e220dcc28 100644 --- a/quote.c +++ b/quote.c @@ -13,7 +13,7 @@ * a!b ==> a'\!'b ==> 'a'\!'b' */ #undef EMIT -#define EMIT(x) ( (++len < n) && (*bp++ = (x)) ) +#define EMIT(x) do { if (++len < n) *bp++ = (x); } while(0) static inline int need_bs_quote(char c) { @@ -45,6 +45,23 @@ size_t sq_quote_buf(char *dst, size_t n, const char *src) return len; } +void sq_quote_print(FILE *stream, const char *src) +{ + char c; + + fputc('\'', stream); + while ((c = *src++)) { + if (need_bs_quote(c)) { + fputs("'\\", stream); + fputc(c, stream); + fputc('\'', stream); + } else { + fputc(c, stream); + } + } + fputc('\'', stream); +} + char *sq_quote(const char *src) { char *buf;