From: Derrick Brashear Date: Wed, 10 Jul 2002 21:03:54 +0000 (+0000) Subject: STABLE12-add-uuid-utility-functions-20020622 X-Git-Tag: openafs-stable-1_2_6~45 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=84cd9267782c9062d16edc3d3a794d338edbbd9b;p=packages%2Fo%2Fopenafs.git STABLE12-add-uuid-utility-functions-20020622 Add afsUUID_to_string() and afsUUID_from_string() utility functions, from arla. (cherry picked from commit 664e4f6f0ddbe30ebc78053a7b16634bac926e37) --- diff --git a/src/util/uuid.c b/src/util/uuid.c index f4629c39a..d7f11e5dc 100644 --- a/src/util/uuid.c +++ b/src/util/uuid.c @@ -141,6 +141,64 @@ uuid_time_p_t time2; { return (0); } +/* + * Converts a string UUID to binary representation. + */ + +int +afsUUID_from_string(const char *str, afsUUID *uuid) +{ + unsigned int time_low, time_mid, time_hi_and_version; + unsigned int clock_seq_hi_and_reserved, clock_seq_low; + unsigned int node[6]; + int i; + + i = sscanf(str, "%08x-%04x-%04x-%02x-%02x-%02x%02x%02x%02x%02x%02x", + &time_low, + &time_mid, + &time_hi_and_version, + &clock_seq_hi_and_reserved, + &clock_seq_low, + &node[0], &node[1], &node[2], &node[3], &node[4], &node[5]); + if (i != 11) + return -1; + + uuid->time_low = time_low; + uuid->time_mid = time_mid; + uuid->time_hi_and_version = time_hi_and_version; + uuid->clock_seq_hi_and_reserved = clock_seq_hi_and_reserved; + uuid->clock_seq_low = clock_seq_low; + + for (i = 0; i < 6; i++) + uuid->node[i] = node[i]; + + return 0; +} + +/* + * Converts a UUID from binary representation to a string representation. + */ + +int +afsUUID_to_string(const afsUUID *uuid, char *str, size_t strsz) +{ + snprintf(str, strsz, + "%08x-%04x-%04x-%02x-%02x-%02x%02x%02x%02x%02x%02x", + uuid->time_low, + uuid->time_mid, + uuid->time_hi_and_version, + (unsigned char)uuid->clock_seq_hi_and_reserved, + (unsigned char)uuid->clock_seq_low, + (unsigned char)uuid->node[0], + (unsigned char)uuid->node[1], + (unsigned char)uuid->node[2], + (unsigned char)uuid->node[3], + (unsigned char)uuid->node[4], + (unsigned char)uuid->node[5]); + + return 0; +} + afs_int32 afs_uuid_create (uuid) afsUUID *uuid; { uuid_address_t eaddr;