]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libuuid: add uuid_parse_range()
authorZane van Iperen <z.vaniperen@uq.edu.au>
Tue, 5 Nov 2019 07:21:17 +0000 (17:21 +1000)
committerZane van Iperen <z.vaniperen@uq.edu.au>
Tue, 25 Feb 2020 05:22:49 +0000 (15:22 +1000)
For compatibility with C++'s std::string_view, et al.

Signed-off-by: Zane van Iperen <z.vaniperen@uq.edu.au>
libuuid/src/parse.c
libuuid/src/uuid.h

index 074383efae7c8cc6eb893a645a05bacc0b567511..e4ec44ab3c1d25d02607a6171f68e1f7a9f46f7e 100644 (file)
 #include "uuidP.h"
 
 int uuid_parse(const char *in, uuid_t uu)
+{
+       size_t len = strlen(in);
+       if (len != 36)
+               return -1;
+
+       return uuid_parse_range(in, in + len, uu);
+}
+
+int uuid_parse_range(const char *in_start, const char *in_end, uuid_t uu)
 {
        struct uuid     uuid;
        int             i;
        const char      *cp;
        char            buf[3];
 
-       if (strlen(in) != 36)
+       if ((in_end - in_start) != 36)
                return -1;
-       for (i=0, cp = in; i <= 36; i++,cp++) {
+       for (i=0, cp = in_start; i <= 36; i++,cp++) {
                if ((i == 8) || (i == 13) || (i == 18) ||
                    (i == 23)) {
                        if (*cp == '-')
@@ -62,11 +71,11 @@ int uuid_parse(const char *in, uuid_t uu)
                if (!isxdigit(*cp))
                        return -1;
        }
-       uuid.time_low = strtoul(in, NULL, 16);
-       uuid.time_mid = strtoul(in+9, NULL, 16);
-       uuid.time_hi_and_version = strtoul(in+14, NULL, 16);
-       uuid.clock_seq = strtoul(in+19, NULL, 16);
-       cp = in+24;
+       uuid.time_low = strtoul(in_start, NULL, 16);
+       uuid.time_mid = strtoul(in_start+9, NULL, 16);
+       uuid.time_hi_and_version = strtoul(in_start+14, NULL, 16);
+       uuid.clock_seq = strtoul(in_start+19, NULL, 16);
+       cp = in_start+24;
        buf[2] = 0;
        for (i=0; i < 6; i++) {
                buf[0] = *cp++;
index 03c232caad50b4998e44c8e5ca54aa22ba68211f..b90c88836cc6cef04a62b80776ad34d461f34b72 100644 (file)
@@ -100,6 +100,7 @@ extern int uuid_is_null(const uuid_t uu);
 
 /* parse.c */
 extern int uuid_parse(const char *in, uuid_t uu);
+extern int uuid_parse_range(const char *in_start, const char *in_end, uuid_t uu);
 
 /* unparse.c */
 extern void uuid_unparse(const uuid_t uu, char *out);