diff options
author | Lennart Poettering <lennart@poettering.net> | 2016-02-13 11:15:41 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2016-02-13 11:15:41 +0100 |
commit | 91ba5ac7d0196074863ff08f5251689d324a6550 (patch) | |
tree | c12c05be46f21a42d30f2bf1b46d1207db49db89 /src/basic/escape.c | |
parent | 6c3bedd5cfef5c70185fbbac33829c5c11686669 (diff) | |
parent | 718af59e9ac1a525b0a73b99a74bc376f1b4d49d (diff) |
Merge pull request #2589 from keszybz/resolve-tool-2
Better support of OPENPGPKEY, CAA, TLSA packets and tests
Diffstat (limited to 'src/basic/escape.c')
-rw-r--r-- | src/basic/escape.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/basic/escape.c b/src/basic/escape.c index 2e483880c8..01daf11ce7 100644 --- a/src/basic/escape.c +++ b/src/basic/escape.c @@ -413,6 +413,34 @@ char *xescape(const char *s, const char *bad) { return r; } +char *octescape(const char *s, size_t len) { + char *r, *t; + const char *f; + + /* Escapes all chars in bad, in addition to \ and " chars, + * in \nnn style escaping. */ + + r = new(char, len * 4 + 1); + if (!r) + return NULL; + + for (f = s, t = r; f < s + len; f++) { + + if (*f < ' ' || *f >= 127 || *f == '\\' || *f == '"') { + *(t++) = '\\'; + *(t++) = '0' + (*f >> 6); + *(t++) = '0' + ((*f >> 3) & 8); + *(t++) = '0' + (*f & 8); + } else + *(t++) = *f; + } + + *t = 0; + + return r; + +} + static char *strcpy_backslash_escaped(char *t, const char *s, const char *bad) { assert(bad); |