xref: /memcached-1.4.29/util.h (revision 9791b779)
1 /*
2  * Wrappers around strtoull/strtoll that are safer and easier to
3  * use.  For tests and assumptions, see internal_tests.c.
4  *
5  * str   a NULL-terminated base decimal 10 unsigned integer
6  * out   out parameter, if conversion succeeded
7  *
8  * returns true if conversion succeeded.
9  */
10 bool safe_strtoull(const char *str, uint64_t *out);
11 bool safe_strtoll(const char *str, int64_t *out);
12 bool safe_strtoul(const char *str, uint32_t *out);
13 bool safe_strtol(const char *str, int32_t *out);
14 
15 #ifndef HAVE_HTONLL
16 extern uint64_t htonll(uint64_t);
17 extern uint64_t ntohll(uint64_t);
18 #endif
19 
20 #ifdef __GCC
21 # define __gcc_attribute__ __attribute__
22 #else
23 # define __gcc_attribute__(x)
24 #endif
25 
26 /**
27  * Vararg variant of perror that makes for more useful error messages
28  * when reporting with parameters.
29  *
30  * @param fmt a printf format
31  */
32 void vperror(const char *fmt, ...)
33     __gcc_attribute__ ((format (printf, 1, 2)));
34