diff options
author | Ben Pfaff <blp@nicira.com> | 2010-02-10 15:54:43 -0800 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2010-02-15 11:28:39 -0800 |
commit | d0d15d58c679d4a5ebbdf9a1dd5788782d4dc49d (patch) | |
tree | 0e2d3f1bd31817ae32c3e7e77914d37dd607f30e /lib/uuid.c | |
parent | c3a0bfd57e1eff6e46495251d8a5cada60916b1f (diff) |
uuid: New function uuid_from_string_prefix().
For use in an upcoming commit.
Diffstat (limited to 'lib/uuid.c')
-rw-r--r-- | lib/uuid.c | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -141,6 +141,22 @@ uuid_compare_3way(const struct uuid *a, const struct uuid *b) 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; } } |