Added xstrtol_ll and xstrtol_ull convenience functions

This commit is contained in:
Daniel P. Berrange 2008-01-20 16:11:25 +00:00
parent e05a879022
commit d56aff5255
2 changed files with 41 additions and 0 deletions

View File

@ -1,3 +1,8 @@
Sun Jan 20 11:01:22 EST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/internal.h: Add xstrtol_ull, xstrtol_ll convenience
functions
Sun Jan 20 10:54:22 EST 2008 Daniel P. Berrange <berrange@redhat.com> Sun Jan 20 10:54:22 EST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/xend_internal.c: Fix nodeinfo compat with Xen 3.2.0 and * src/xend_internal.c: Fix nodeinfo compat with Xen 3.2.0 and

View File

@ -308,6 +308,42 @@ xstrtol_ui(char const *s, char **end_ptr, int base, unsigned int *result)
return 0; return 0;
} }
static inline int
xstrtol_ll(char const *s, char **end_ptr, int base, long long *result)
{
long long val;
char *p;
int err;
errno = 0;
val = strtoll(s, &p, base);
err = (errno || (!end_ptr && *p) || p == s || (long long) val != val);
if (end_ptr)
*end_ptr = p;
if (err)
return -1;
*result = val;
return 0;
}
/* Just like xstrtol_i, above, but produce an "unsigned long long" value. */
static inline int
xstrtol_ull(char const *s, char **end_ptr, int base, unsigned long long *result)
{
unsigned long long val;
char *p;
int err;
errno = 0;
val = strtoull(s, &p, base);
err = (errno || (!end_ptr && *p) || p == s || (unsigned long long) val != val);
if (end_ptr)
*end_ptr = p;
if (err)
return -1;
*result = val;
return 0;
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */