Print this page
4118 libuuid should provide uuid_unparse_{upper,lower} functions
Reviewed by: Serghei Samsi <sscdvp@gmail.com>
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Garrett D'Amore <garrett@damore.org>
@@ -21,10 +21,11 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright 2012 Milan Jurik. All rights reserved.
* Copyright 2013 Joyent, Inc. All rights reserved.
+ * Copyright 2014 Andrew Stormont.
*/
/*
* The copyright in this file is taken from the original Leach & Salz
* UUID specification, from which this implementation is derived.
@@ -576,12 +577,12 @@
/*
* This function converts the supplied UUID uu from the internal
* binary format into a 36-byte string (plus trailing null char)
* and stores this value in the character string pointed to by out.
*/
-void
-uuid_unparse(uuid_t uu, char *out)
+static void
+uuid_unparse_common(uuid_t uu, char *out, boolean_t upper)
{
struct uuid uuid;
uint16_t clock_seq;
char etheraddr[13];
int index = 0, i;
@@ -589,30 +590,48 @@
/* basic sanity checking */
if (uu == NULL) {
return;
}
- /* XXX user should have allocated enough memory */
- /*
- * if (strlen(out) < UUID_PRINTABLE_STRING_LENGTH) {
- * return;
- * }
- */
string_to_struct(&uuid, uu);
clock_seq = uuid.clock_seq_hi_and_reserved;
clock_seq = (clock_seq << 8) | uuid.clock_seq_low;
for (i = 0; i < 6; i++) {
- (void) sprintf(ðeraddr[index++], "%.2x", uuid.node_addr[i]);
+ (void) sprintf(ðeraddr[index++], upper ? "%.2X" : "%.2x",
+ uuid.node_addr[i]);
index++;
}
etheraddr[index] = '\0';
- (void) snprintf(out, 25, "%08x-%04x-%04x-%04x-",
+ (void) snprintf(out, 25,
+ upper ? "%08X-%04X-%04X-%04X-" : "%08x-%04x-%04x-%04x-",
uuid.time_low, uuid.time_mid, uuid.time_hi_and_version, clock_seq);
(void) strlcat(out, etheraddr, UUID_PRINTABLE_STRING_LENGTH);
}
+void
+uuid_unparse_upper(uuid_t uu, char *out)
+{
+ uuid_unparse_common(uu, out, B_TRUE);
+}
+
+void
+uuid_unparse_lower(uuid_t uu, char *out)
+{
+ uuid_unparse_common(uu, out, B_FALSE);
+}
+
+void
+uuid_unparse(uuid_t uu, char *out)
+{
+ /*
+ * Historically uuid_unparse on Solaris returns lower case,
+ * for compatibility we preserve this behaviour.
+ */
+ uuid_unparse_common(uu, out, B_FALSE);
+}
+
/*
* The uuid_is_null function compares the value of the supplied
* UUID variable uu to the NULL value. If the value is equal
* to the NULL UUID, 1 is returned, otherwise 0 is returned.
*/