mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
lib: Move guestfs_int_parse_unsigned_int to version.c
Just code motion, but this function seems to make more sense in version.c since that is the main (but not only) user.
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user