qemu/util
Eduardo Habkost e3f9fe2d40 cutils: unsigned int parsing functions
There are lots of duplicate parsing code using strto*() in QEMU, and
most of that code is broken in one way or another. Even the visitors
code have duplicate integer parsing code[1]. This introduces functions
to help parsing unsigned int values: parse_uint() and parse_uint_full().

Parsing functions for signed ints and floats will be submitted later.

parse_uint_full() has all the checks made by opts_type_uint64() at
opts-visitor.c:

 - Check for NULL (returns -EINVAL)
 - Check for negative numbers (returns -EINVAL)
 - Check for empty string (returns -EINVAL)
 - Check for overflow or other errno values set by strtoll() (returns
   -errno)
 - Check for end of string (reject invalid characters after number)
   (returns -EINVAL)

parse_uint() does everything above except checking for the end of the
string, so callers can continue parsing the remainder of string after
the number.

Unit tests included.

[1] string-input-visitor.c:parse_int() could use the same parsing code
    used by opts-visitor.c:opts_type_int(), instead of duplicating that
    logic.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-02-04 14:38:33 -06:00
..
acl.c acl: Free memory allocated with g_malloc() with g_free() 2013-01-15 18:25:41 -06:00
aes.c
bitmap.c
bitops.c bitops: unify bitops_ffsl with the one in host-utils.h, call it bitops_ctzl 2013-02-02 20:16:00 +00:00
cache-utils.c
compatfd.c
cutils.c cutils: unsigned int parsing functions 2013-02-04 14:38:33 -06:00
envlist.c util: Fix compilation of envlist.c for MinGW 2013-02-02 20:13:19 +00:00
error.c
event_notifier-posix.c
event_notifier-win32.c
hbitmap.c bitops: unify bitops_ffsl with the one in host-utils.h, call it bitops_ctzl 2013-02-02 20:16:00 +00:00
host-utils.c
iov.c
Makefile.objs add hierarchical bitmap data type and test cases 2013-01-25 18:18:32 +01:00
module.c
notify.c
osdep.c
oslib-posix.c bsd-user: avoid conflict with qemu_vmalloc 2013-01-26 13:18:27 +00:00
oslib-win32.c
path.c Replace non-portable asprintf by g_strdup_printf 2013-01-19 10:24:43 +00:00
qemu-config.c
qemu-error.c
qemu-option.c g_strdup(NULL) returns NULL; simplify 2013-01-30 11:14:46 +01:00
qemu-progress.c
qemu-sockets.c
qemu-thread-posix.c
qemu-thread-win32.c
qemu-timer-common.c
uri.c