interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / hex-ll.h

27 lines · 708 bytes Raw Blame History
1#ifndef HEX_LL_H
2#define HEX_LL_H
3
4extern const signed char hexval_table[256];
5static inline unsigned int hexval(unsigned char c)
6{
7 return hexval_table[c];
8}
9
10/*
11 * Convert two consecutive hexadecimal digits into a char. Return a
12 * negative value on error. Don't run over the end of short strings.
13 */
14static inline int hex2chr(const char *s)
15{
16 unsigned int val = hexval(s[0]);
17 return (val & ~0xf) ? val : (val << 4) | hexval(s[1]);
18}
19
20/*
21 * Read `len` pairs of hexadecimal digits from `hex` and write the
22 * values to `binary` as `len` bytes. Return 0 on success, or -1 if
23 * the input does not consist of hex digits).
24 */
25int hex_to_bytes(unsigned char *binary, const char *hex, size_t len);
26
27#endif