diff options
author | Michael Cahill <michael.cahill@mongodb.com> | 2016-01-28 09:25:16 +1100 |
---|---|---|
committer | Michael Cahill <michael.cahill@mongodb.com> | 2016-01-28 09:30:32 +1100 |
commit | 67e412d4c578e203505446496c67fc1517931cad (patch) | |
tree | 5d1e780ea1e14b1d32ef34aa33716be9bc284f8c /src/support/hex.c | |
parent | 3c2ad56b507d82d8d5599dc1ebb50d3ccc087bfb (diff) | |
parent | 7fea169e425b2a56d88351f362d746d5b5dd77f5 (diff) | |
download | mongo-67e412d4c578e203505446496c67fc1517931cad.tar.gz |
Merge branch 'develop' into mongodb-3.2
Diffstat (limited to 'src/support/hex.c')
-rw-r--r-- | src/support/hex.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/support/hex.c b/src/support/hex.c index eb9f420911a..d42a84154ca 100644 --- a/src/support/hex.c +++ b/src/support/hex.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2014-2015 MongoDB, Inc. + * Copyright (c) 2014-2016 MongoDB, Inc. * Copyright (c) 2008-2014 WiredTiger, Inc. * All rights reserved. * @@ -8,7 +8,7 @@ #include "wt_internal.h" -static const u_char hex[] = "0123456789abcdef"; +const u_char __wt_hex[] = "0123456789abcdef"; /* * __fill_hex -- @@ -25,8 +25,8 @@ __fill_hex(const uint8_t *src, size_t src_max, --dest_max; for (; src_max > 0 && dest_max > 1; src_max -= 1, dest_max -= 2, ++src) { - *dest++ = hex[(*src & 0xf0) >> 4]; - *dest++ = hex[*src & 0x0f]; + *dest++ = __wt_hex[(*src & 0xf0) >> 4]; + *dest++ = __wt_hex[*src & 0x0f]; } *dest++ = '\0'; if (lenp != NULL) @@ -34,6 +34,17 @@ __fill_hex(const uint8_t *src, size_t src_max, } /* + * __wt_fill_hex -- + * In-memory conversion of raw bytes to a hexadecimal representation. + */ +void +__wt_fill_hex(const uint8_t *src, size_t src_max, + uint8_t *dest, size_t dest_max, size_t *lenp) +{ + __fill_hex(src, src_max, dest, dest_max, lenp); +} + +/* * __wt_raw_to_hex -- * Convert a chunk of data to a nul-terminated printable hex string. */ @@ -72,10 +83,6 @@ __wt_raw_to_esc_hex( */ WT_RET(__wt_buf_init(session, to, size * 3 + 1)); - /* - * In the worst case, every character takes up 3 spaces, plus a - * trailing nul byte. - */ for (p = from, t = to->mem, i = size; i > 0; --i, ++p) if (isprint((int)*p)) { if (*p == '\\') @@ -83,8 +90,8 @@ __wt_raw_to_esc_hex( *t++ = *p; } else { *t++ = '\\'; - *t++ = hex[(*p & 0xf0) >> 4]; - *t++ = hex[*p & 0x0f]; + *t++ = __wt_hex[(*p & 0xf0) >> 4]; + *t++ = __wt_hex[*p & 0x0f]; } *t++ = '\0'; to->size = WT_PTRDIFF(t, to->mem); |