-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpictDBM_tools.c
34 lines (30 loc) · 882 Bytes
/
pictDBM_tools.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* @file pictDBM_tools.c
* @brief pictDB Manager : useful tool functions
*
* @author Jean-Cédric Chappelier
* @date 25 Nov 2015
*/
#include <stdint.h> // for uint16_t, uint32_t
#include <errno.h>
#include <inttypes.h> // strtoumax()
#include "pictDBM_tools.h"
/********************************************************************//**
* Tool functions for string to uint<N>_t conversion.
********************************************************************** */
#define define_atouintN(N) \
uint ## N ## _t \
atouint ## N(const char* str) \
{ \
char* endptr; \
errno = 0; \
uintmax_t val = strtoumax(str, &endptr, 10); \
if (errno == ERANGE || val > UINT ## N ## _MAX \
|| endptr == str || *endptr != '\0') { \
errno = ERANGE; \
return 0; \
} \
return (uint ## N ## _t) val; \
}
define_atouintN(16)
define_atouintN(32)