20 #define CHECK_STRTOX_RESULT() \
23 if (errno == ERANGE) \
29 if (!next && *endptr) \
35 if (r < min || r > max) \
38 if (next) *next = endptr; \
42 if (next) *next = endptr; \
72 r = strtol(s, &endptr, base);
73 CHECK_STRTOX_RESULT();
79 unsigned long max,
int *ok,
char **next)
91 r = strtoul(s, &endptr, base);
92 CHECK_STRTOX_RESULT();
103 r = strtod(s, &endptr);
104 CHECK_STRTOX_RESULT();
111 uint64_t max,
int *ok,
char **next)
124 r = (uint64_t)strtoull(s, &endptr, base);
125 #elif defined(_WIN32)
126 r = (uint64_t)_strtoui64(s, &endptr, base);
127 #elif SIZEOF_LONG == 8
128 r = (uint64_t)strtoul(s, &endptr, base);
130 #error "I don't know how to parse 64-bit numbers."
133 CHECK_STRTOX_RESULT();
Utility macros to handle different features and behavior in different compilers.
uint64_t tor_parse_uint64(const char *s, int base, uint64_t min, uint64_t max, int *ok, char **next)
long tor_parse_long(const char *s, int base, long min, long max, int *ok, char **next)
unsigned long tor_parse_ulong(const char *s, int base, unsigned long min, unsigned long max, int *ok, char **next)
double tor_parse_double(const char *s, double min, double max, int *ok, char **next)