[Libvir] PATCH: Add xstrtol variants for long long

Jim's xstrtol convenience function simplified the use of strtol, but only support the 'int' variant. For the storage drivers I need a similar function that will always be at minimum 64-bit since we may have files > 2 GB even on 32-bit. So this adds a variant of the xstrtol functions which use a long long / unsigned long long type Regards, Dan. diff -r 83e80c558f4d src/internal.h --- a/src/internal.h Wed Jan 16 09:28:01 2008 -0500 +++ b/src/internal.h Wed Jan 16 09:28:05 2008 -0500 @@ -304,6 +304,42 @@ xstrtol_ui(char const *s, char **end_ptr 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 } #endif /* __cplusplus */ Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|

"Daniel P. Berrange" <berrange@redhat.com> wrote:
Jim's xstrtol convenience function simplified the use of strtol, but only support the 'int' variant. For the storage drivers I need a similar function that will always be at minimum 64-bit since we may have files > 2 GB even on 32-bit. So this adds a variant of the xstrtol functions which use a long long / unsigned long long type
Regards, Dan.
diff -r 83e80c558f4d src/internal.h --- a/src/internal.h Wed Jan 16 09:28:01 2008 -0500 +++ b/src/internal.h Wed Jan 16 09:28:05 2008 -0500 @@ -304,6 +304,42 @@ xstrtol_ui(char const *s, char **end_ptr return 0; }
+static inline int +xstrtol_ll(char const *s, char **end_ptr, int base, long long *result)
ACK. FYI, no harm of course, but I don't see a use of xstrtol_ll (yet?) in the queue.

On Sat, Jan 19, 2008 at 08:28:38PM +0100, Jim Meyering wrote:
"Daniel P. Berrange" <berrange@redhat.com> wrote:
Jim's xstrtol convenience function simplified the use of strtol, but only support the 'int' variant. For the storage drivers I need a similar function that will always be at minimum 64-bit since we may have files > 2 GB even on 32-bit. So this adds a variant of the xstrtol functions which use a long long / unsigned long long type
Regards, Dan.
diff -r 83e80c558f4d src/internal.h --- a/src/internal.h Wed Jan 16 09:28:01 2008 -0500 +++ b/src/internal.h Wed Jan 16 09:28:05 2008 -0500 @@ -304,6 +304,42 @@ xstrtol_ui(char const *s, char **end_ptr return 0; }
+static inline int +xstrtol_ll(char const *s, char **end_ptr, int base, long long *result)
ACK.
FYI, no harm of course, but I don't see a use of xstrtol_ll (yet?) in the queue.
Yes, I only use the xstrtol_ull variant in the drivers, but figured we might as well define the whole set for completeness. Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|

Daniel P. Berrange wrote:
Jim's xstrtol convenience function simplified the use of strtol, but only support the 'int' variant. For the storage drivers I need a similar function that will always be at minimum 64-bit since we may have files > 2 GB even on 32-bit. So this adds a variant of the xstrtol functions which use a long long / unsigned long long type
+1, although I might have called it xstroll / xstroull, but it's not important. Rich. -- Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/ Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 03798903

On Sun, Jan 20, 2008 at 12:24:51PM +0000, Richard W.M. Jones wrote:
Daniel P. Berrange wrote:
Jim's xstrtol convenience function simplified the use of strtol, but only support the 'int' variant. For the storage drivers I need a similar function that will always be at minimum 64-bit since we may have files > 2 GB even on 32-bit. So this adds a variant of the xstrtol functions which use a long long / unsigned long long type
+1, although I might have called it xstroll / xstroull, but it's not important.
Ok, have comitted this patch. Regards, Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
participants (3)
-
Daniel P. Berrange
-
Jim Meyering
-
Richard W.M. Jones