10 #include <memcached/util.h>
13 #define xisspace(c) isspace((unsigned char)c)
15 bool safe_strtoull(
const char *str, uint64_t *out) {
20 unsigned long long ull = strtoull(str, &endptr, 10);
23 if (xisspace(*endptr) || (*endptr ==
'\0' && endptr != str)) {
24 if ((
long long) ull < 0) {
28 if (strchr(str,
'-') != NULL) {
38 bool safe_strtoll(
const char *str, int64_t *out) {
43 long long ll = strtoll(str, &endptr, 10);
46 if (xisspace(*endptr) || (*endptr ==
'\0' && endptr != str)) {
53 bool safe_strtoul(
const char *str, uint32_t *out) {
61 l = strtoul(str, &endptr, 10);
62 if (errno == ERANGE) {
66 if (xisspace(*endptr) || (*endptr ==
'\0' && endptr != str)) {
71 if (strchr(str,
'-') != NULL) {
82 bool safe_strtol(
const char *str, int32_t *out) {
87 long l = strtol(str, &endptr, 10);
90 if (xisspace(*endptr) || (*endptr ==
'\0' && endptr != str)) {
97 bool safe_strtof(
const char *str,
float *out) {
102 float l = strtof(str, &endptr);
105 if (isspace(*endptr) || (*endptr ==
'\0' && endptr != str)) {
112 void vperror(
const char *
fmt, ...) {
113 int old_errno = errno;
118 if (vsnprintf(buf,
sizeof(buf), fmt, ap) == -1) {
119 buf[
sizeof(
buf) - 1] =
'\0';
129 static uint64_t mc_swap64(uint64_t in) {
130 #ifndef WORDS_BIGENDIAN
135 for(i = 0; i<8; i++) {
136 rv = (rv << 8) | (in & 0xff);
146 uint64_t ntohll(uint64_t val) {
147 return mc_swap64(val);
150 uint64_t htonll(uint64_t val) {
151 return mc_swap64(val);