libbtc
bitcoinclibrary
utils.h
Go to the documentation of this file.
1 /*
2 
3  The MIT License (MIT)
4 
5  Copyright (c) 2015 Douglas J. Bakkum
6  Copyright (c) 2015 Jonas Schnelli
7 
8  Permission is hereby granted, free of charge, to any person obtaining
9  a copy of this software and associated documentation files (the "Software"),
10  to deal in the Software without restriction, including without limitation
11  the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  and/or sell copies of the Software, and to permit persons to whom the
13  Software is furnished to do so, subject to the following conditions:
14 
15  The above copyright notice and this permission notice shall be included
16  in all copies or substantial portions of the Software.
17 
18  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
22  OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24  OTHER DEALINGS IN THE SOFTWARE.
25 
26 */
27 
28 
29 #ifndef _UTILS_H_
30 #define _UTILS_H_
31 
32 
33 #include <stdint.h>
34 #include <stddef.h>
35 
36 
37 #define TO_UINT8_HEX_BUF_LEN 2048
38 #define VARINT_LEN 20
39 
40 #define strlens(s) (s == NULL ? 0 : strlen(s))
41 
42 
43 void utils_clear_buffers(void);
44 void utils_hex_to_bin(const char* str, unsigned char* out, int inLen, int* outLen);
45 void utils_bin_to_hex(unsigned char* bin_in, size_t inlen, char* hex_out);
46 uint8_t* utils_hex_to_uint8(const char* str);
47 char* utils_uint8_to_hex(const uint8_t* bin, size_t l);
48 void utils_reverse_hex(char* h, int len);
49 void utils_uint64_to_varint(char* vi, int* l, uint64_t i);
50 int utils_varint_to_uint64(const char* vi, uint64_t* i);
51 
52 #endif
size_t len
Definition: buffer.h:22
void utils_reverse_hex(char *h, int len)
Definition: utils.c:140
int utils_varint_to_uint64(const char *vi, uint64_t *i)
Definition: utils.c:186
void utils_bin_to_hex(unsigned char *bin_in, size_t inlen, char *hex_out)
Definition: utils.c:111
void utils_uint64_to_varint(char *vi, int *l, uint64_t i)
Definition: utils.c:152
char * utils_uint8_to_hex(const uint8_t *bin, size_t l)
Definition: utils.c:123
uint8_t * utils_hex_to_uint8(const char *str)
Definition: utils.c:77
void utils_hex_to_bin(const char *str, unsigned char *out, int inLen, int *outLen)
Definition: utils.c:46
void utils_clear_buffers(void)
Definition: utils.c:40