uuid: New function uuid_from_string_prefix().
authorBen Pfaff <blp@nicira.com>
Wed, 10 Feb 2010 23:54:43 +0000 (15:54 -0800)
committerBen Pfaff <blp@nicira.com>
Mon, 15 Feb 2010 19:28:39 +0000 (11:28 -0800)
For use in an upcoming commit.

lib/uuid.c
lib/uuid.h

index 620c039..9aaa915 100644 (file)
@@ -140,6 +140,22 @@ uuid_compare_3way(const struct uuid *a, const struct uuid *b)
  * be set to all-zero-bits. */
 bool
 uuid_from_string(struct uuid *uuid, const char *s)
+{
+    if (!uuid_from_string_prefix(uuid, s)) {
+        return false;
+    } else if (s[UUID_LEN] != '\0') {
+        uuid_zero(uuid);
+        return false;
+    } else {
+        return true;
+    }
+}
+
+/* Same as uuid_from_string() but s[UUID_LEN] is not required to be a null byte
+ * to succeed; that is, 's' need only begin with UUID syntax, not consist
+ * entirely of it. */
+bool
+uuid_from_string_prefix(struct uuid *uuid, const char *s)
 {
     static const char template[] = "00000000-1111-1111-2222-222233333333";
     const char *t;
@@ -152,10 +168,10 @@ uuid_from_string(struct uuid *uuid, const char *s)
                 goto error;
             }
             *part = (*part << 4) + hexit_value(*s);
-        } else if (*t != *s) {
-            goto error;
         } else if (*t == 0) {
             return true;
+        } else if (*t != *s) {
+            goto error;
         }
     }
 
index 1059c26..8159779 100644 (file)
@@ -77,5 +77,6 @@ void uuid_zero(struct uuid *);
 bool uuid_is_zero(const struct uuid *);
 int uuid_compare_3way(const struct uuid *, const struct uuid *);
 bool uuid_from_string(struct uuid *, const char *);
+bool uuid_from_string_prefix(struct uuid *, const char *);
 
 #endif /* vswitchd/cfgdb.h */