Just code motion, but this function seems to make more sense in version.c since that is the main (but not only) user. --- lib/guestfs-internal.h | 2 +- lib/inspect.c | 14 -------------- lib/version.c | 24 ++++++++++++++++++++++++ 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lib/guestfs-internal.h b/lib/guestfs-internal.h index a694be8f5..d24435011 100644 --- a/lib/guestfs-internal.h +++ b/lib/guestfs-internal.h @@ -714,7 +714,6 @@ extern int guestfs_int_set_backend (guestfs_h *g, const char *method); /* inspect.c */ extern char *guestfs_int_download_to_tmp (guestfs_h *g, const char *filename, const char *basename, uint64_t max_size); -extern int guestfs_int_parse_unsigned_int (guestfs_h *g, const char *str); /* dbdump.c */ typedef int (*guestfs_int_db_dump_callback) (guestfs_h *g, const unsigned char *key, size_t keylen, const unsigned char *value, size_t valuelen, void *opaque); @@ -805,6 +804,7 @@ extern int guestfs_int_version_from_x_y_re (guestfs_h *g, struct version *v, con extern int guestfs_int_version_from_x_y_or_x (guestfs_h *g, struct version *v, const char *str); extern bool guestfs_int_version_ge (const struct version *v, int maj, int min, int mic); extern bool guestfs_int_version_cmp_ge (const struct version *a, const struct version *b); +extern int guestfs_int_parse_unsigned_int (guestfs_h *g, const char *str); #define version_init_null(v) guestfs_int_version_from_values (v, 0, 0, 0) #define version_is_null(v) ((v)->v_major == 0 && (v)->v_minor == 0 && (v)->v_micro == 0) diff --git a/lib/inspect.c b/lib/inspect.c index b7c5b6cc7..eb53edf32 100644 --- a/lib/inspect.c +++ b/lib/inspect.c @@ -33,7 +33,6 @@ #endif #include "ignore-value.h" -#include "xstrtol.h" #include "guestfs.h" #include "guestfs-internal.h" @@ -105,16 +104,3 @@ guestfs_int_download_to_tmp (guestfs_h *g, free (r); return NULL; } - -/* Parse small, unsigned ints, as used in version numbers. */ -int -guestfs_int_parse_unsigned_int (guestfs_h *g, const char *str) -{ - long ret; - const int r = xstrtol (str, NULL, 10, &ret, ""); - if (r != LONGINT_OK) { - error (g, _("could not parse integer in version number: %s"), str); - return -1; - } - return ret; -} diff --git a/lib/version.c b/lib/version.c index 60ffe1e89..cf601ef91 100644 --- a/lib/version.c +++ b/lib/version.c @@ -22,10 +22,14 @@ #include <config.h> +#include <stdio.h> +#include <stdlib.h> #include <string.h> #include <unistd.h> +#include <libintl.h> #include "ignore-value.h" +#include "xstrtol.h" #include "guestfs.h" #include "guestfs-internal.h" @@ -144,3 +148,23 @@ version_from_x_y_or_x (guestfs_h *g, struct version *v, const char *str, } return 0; } + +/** + * Parse small, unsigned ints, as used in version numbers. + * + * This will fail with an error if trailing characters are found after + * the integer. + * + * Returns E<ge> C<0> on success, or C<-1> on failure. + */ +int +guestfs_int_parse_unsigned_int (guestfs_h *g, const char *str) +{ + long ret; + const int r = xstrtol (str, NULL, 10, &ret, ""); + if (r != LONGINT_OK) { + error (g, _("could not parse integer in version number: %s"), str); + return -1; + } + return ret; +} -- 2.13.2