diff options
author | Adam Chlipala <adam@chlipala.net> | 2014-02-25 16:34:04 -0500 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2014-02-25 16:34:04 -0500 |
commit | dbd82b58311150797d5f8a43fa412c5135e9fd27 (patch) | |
tree | 2ef3745f6c69baf9965649bd3e881a75d54e2460 | |
parent | cc4f8ee471c8a613f6c748c89808c52e3f64c936 (diff) |
Parse new bytea output format from Postgres 9.x
-rw-r--r-- | src/c/urweb.c | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c index 7ff8a262..9bf72ce1 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -3049,27 +3049,39 @@ uw_Basis_blob uw_Basis_stringToBlob_error(uw_context ctx, uw_Basis_string s, siz uw_check_heap(ctx, len); - while (*s) { - if (s[0] == '\\') { - if (s[1] == '\\') { - *r++ = '\\'; - s += 2; - } else if (isdigit((int)s[1]) && isdigit((int)s[2]) && isdigit((int)s[3])) { - *r++ = (s[1] - '0') * 8 * 8 + ((s[2] - '0') * 8) + (s[3] - '0'); - s += 4; - } - else { - *r++ = '\\'; + if (s[0] == '\\' && s[1] == 'x') { + s += 2; + + while (*s) { + int n; + sscanf(s, "%02x", &n); + *r++ = n; + s += 2; + } + } else { + while (*s) { + if (s[0] == '\\') { + if (s[1] == '\\') { + *r++ = '\\'; + s += 2; + } else if (isdigit((int)s[1]) && isdigit((int)s[2]) && isdigit((int)s[3])) { + *r++ = (s[1] - '0') * 8 * 8 + ((s[2] - '0') * 8) + (s[3] - '0'); + s += 4; + } + else { + *r++ = '\\'; + ++s; + } + } else { + *r++ = s[0]; ++s; } - } else { - *r++ = s[0]; - ++s; } } b.size = r - ctx->heap.front; ctx->heap.front = r; + return b; } |