On Thu, May 26, 2016 at 05:40:10PM +0200, Pino Toscano wrote:
Make use of the common version code, and avoid a separate regexp. --- src/osinfo.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/src/osinfo.c b/src/osinfo.c index 4a4cbfc..f4e2c71 100644 --- a/src/osinfo.c +++ b/src/osinfo.c @@ -65,8 +65,6 @@ #include "guestfs.h" #include "guestfs-internal.h"
-COMPILE_REGEXP (re_major_minor, "(\\d+)\\.(\\d+)", 0) - gl_lock_define_initialized (static, osinfo_db_lock); static ssize_t osinfo_db_size = 0; /* 0 = unread, -1 = error, >= 1 = #records */ static struct osinfo *osinfo_db = NULL; @@ -436,17 +434,16 @@ static int parse_version (guestfs_h *g, xmlNodePtr node, struct osinfo *osinfo) { CLEANUP_FREE char *content = NULL; - CLEANUP_FREE char *major = NULL, *minor = NULL;
content = (char *) xmlNodeGetContent (node); if (content) { - if (match2 (g, content, re_major_minor, &major, &minor)) { - osinfo->major_version = guestfs_int_parse_unsigned_int (g, major); - if (osinfo->major_version == -1) - return -1; - osinfo->minor_version = guestfs_int_parse_unsigned_int (g, minor); - if (osinfo->minor_version == -1) - return -1; + struct version version; + int res = guestfs_int_version_from_x_y (g, &version, content); + if (res < 0) + return -1; + else if (res > 0) { + osinfo->major_version = version.v_major; + osinfo->minor_version = version.v_minor; } }
ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org