diff options
| author | Amitay Isaacs <amitay@gmail.com> | 2013-03-13 22:57:44 +1100 |
|---|---|---|
| committer | Amitay Isaacs <amitay@gmail.com> | 2013-03-25 17:45:23 +1100 |
| commit | dd050cd4ba6bb22efb43da80518a96ec0c858833 (patch) | |
| tree | f11afeaf0076d55994a2a65223f060e60794c24a /ctdb | |
| parent | 7f88fe3d054817598fa0426b6d5b76cc260f8688 (diff) | |
| download | samba-dd050cd4ba6bb22efb43da80518a96ec0c858833.tar.gz samba-dd050cd4ba6bb22efb43da80518a96ec0c858833.tar.xz samba-dd050cd4ba6bb22efb43da80518a96ec0c858833.zip | |
util: Add hex_decode_talloc() to decode hex string into a binary blob
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
(This used to be ctdb commit 307416afda707b687f5e89e8438e45c154a4c806)
Diffstat (limited to 'ctdb')
| -rw-r--r-- | ctdb/include/includes.h | 1 | ||||
| -rw-r--r-- | ctdb/lib/util/util_file.c | 16 |
2 files changed, 17 insertions, 0 deletions
diff --git a/ctdb/include/includes.h b/ctdb/include/includes.h index e0ce06b82a..37471982de 100644 --- a/ctdb/include/includes.h +++ b/ctdb/include/includes.h @@ -58,6 +58,7 @@ double timeval_elapsed(struct timeval *tv); double timeval_delta(struct timeval *tv2, struct timeval *tv); char **file_lines_load(const char *fname, int *numlines, TALLOC_CTX *mem_ctx); char *hex_encode_talloc(TALLOC_CTX *mem_ctx, const unsigned char *buff_in, size_t len); +uint8_t *hex_decode_talloc(TALLOC_CTX *mem_ctx, const char *hex_in, size_t *len); _PUBLIC_ const char **str_list_add(const char **list, const char *s); _PUBLIC_ int set_blocking(int fd, bool set); diff --git a/ctdb/lib/util/util_file.c b/ctdb/lib/util/util_file.c index 21d64b20e3..3a90201cce 100644 --- a/ctdb/lib/util/util_file.c +++ b/ctdb/lib/util/util_file.c @@ -114,3 +114,19 @@ char *hex_encode_talloc(TALLOC_CTX *mem_ctx, const unsigned char *buff_in, size_ return hex_buffer; } + +uint8_t *hex_decode_talloc(TALLOC_CTX *mem_ctx, const char *hex_in, size_t *len) +{ + int i, num; + uint8_t *buffer; + + *len = strlen(hex_in) / 2; + buffer = talloc_array(mem_ctx, unsigned char, *len); + + for (i=0; i<*len; i++) { + sscanf(&hex_in[i*2], "%02X", &num); + buffer[i] = (uint8_t)num; + } + + return buffer; +} |
