From 664e4f6f0ddbe30ebc78053a7b16634bac926e37 Mon Sep 17 00:00:00 2001 From: Derrick Brashear Date: Sat, 22 Jun 2002 05:26:52 +0000 Subject: [PATCH] Add afsUUID_to_string() and afsUUID_from_string() utility functions, from arla. --- src/util/uuid.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/util/uuid.c b/src/util/uuid.c index f4629c3..d7f11e5 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; -- 1.9.4