diff options
author | Tom Gundersen <teg@jklm.no> | 2015-11-23 22:53:30 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2015-11-23 22:53:30 +0100 |
commit | 1f233d4c24a6c95d34cf0fe5d9c31b5440102479 (patch) | |
tree | 06a8eb4a76bc956f2b210f5c208ae51c7a9efa59 /src/basic | |
parent | e429762faaac0c49353d35144a9d45d283e91213 (diff) | |
parent | 45ec7efb6c2560c80dfa752bc9d3733749dc52cb (diff) |
Merge pull request #2007 from poettering/resolve-srv
resolved: add support for resolving plain SRV and DNS-SD services
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/escape.c | 16 | ||||
-rw-r--r-- | src/basic/escape.h | 1 |
2 files changed, 12 insertions, 5 deletions
diff --git a/src/basic/escape.c b/src/basic/escape.c index 4815161b09..42a84c9317 100644 --- a/src/basic/escape.c +++ b/src/basic/escape.c @@ -89,20 +89,20 @@ size_t cescape_char(char c, char *buf) { return buf - buf_old; } -char *cescape(const char *s) { - char *r, *t; +char *cescape_length(const char *s, size_t n) { const char *f; + char *r, *t; - assert(s); + assert(s || n == 0); /* Does C style string escaping. May be reversed with * cunescape(). */ - r = new(char, strlen(s)*4 + 1); + r = new(char, n*4 + 1); if (!r) return NULL; - for (f = s, t = r; *f; f++) + for (f = s, t = r; f < s + n; f++) t += cescape_char(*f, t); *t = 0; @@ -110,6 +110,12 @@ char *cescape(const char *s) { return r; } +char *cescape(const char *s) { + assert(s); + + return cescape_length(s, strlen(s)); +} + int cunescape_one(const char *p, size_t length, char *ret, uint32_t *ret_unicode) { int r = 1; diff --git a/src/basic/escape.h b/src/basic/escape.h index 30604c58f9..52ebf11c4a 100644 --- a/src/basic/escape.h +++ b/src/basic/escape.h @@ -35,6 +35,7 @@ typedef enum UnescapeFlags { } UnescapeFlags; char *cescape(const char *s); +char *cescape_length(const char *s, size_t n); size_t cescape_char(char c, char *buf); int cunescape(const char *s, UnescapeFlags flags, char **ret); |