diff options
author | René Scharfe <l.s.r@web.de> | 2017-10-31 14:46:49 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-11-01 10:35:35 +0900 |
commit | 0ec218656a02ea48e173262f7b80513feeb7f263 (patch) | |
tree | 7cd0bbbbd2a1bccd5873c0c962d40040c2a7e504 /hex.c | |
parent | cb5918aa0d50f50e83787f65c2ddc3dcb10159fe (diff) | |
download | git-0ec218656a02ea48e173262f7b80513feeb7f263.tar.gz |
notes: move hex_to_bytes() to hex.c and export it
Make the function for converting pairs of hexadecimal digits to binary
available to other call sites.
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'hex.c')
-rw-r--r-- | hex.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -35,6 +35,18 @@ const signed char hexval_table[256] = { -1, -1, -1, -1, -1, -1, -1, -1, /* f8-ff */ }; +int hex_to_bytes(unsigned char *binary, const char *hex, size_t len) +{ + for (; len; len--, hex += 2) { + unsigned int val = (hexval(hex[0]) << 4) | hexval(hex[1]); + + if (val & ~0xff) + return -1; + *binary++ = val; + } + return 0; +} + int get_sha1_hex(const char *hex, unsigned char *sha1) { int i; |