From d3d741fc383d3eb1f8636393bc1c68c9bd467cc0 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 22 Mar 2004 16:22:28 -0500 Subject: [PATCH] Add the uuid_unparse_upper and uuid_unparse_lower functions to the uuid library. --- lib/uuid/ChangeLog | 5 +++++ lib/uuid/unparse.c | 31 ++++++++++++++++++++++++++++--- lib/uuid/uuid.h | 2 ++ lib/uuid/uuid_unparse.3.in | 17 ++++++++++++++--- 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/lib/uuid/ChangeLog b/lib/uuid/ChangeLog index e6de9f00a..7a043a1f5 100644 --- a/lib/uuid/ChangeLog +++ b/lib/uuid/ChangeLog @@ -1,3 +1,8 @@ +2004-03-22 Theodore Ts'o + + * unparse.c (uuid_unparse_lower, uuid_unparse_upper), + uuid_unparse.3.in, uuid.h: Add new functions. + 2004-03-19 Theodore Ts'o * Change the license to be the 3-clause BSD-style license diff --git a/lib/uuid/unparse.c b/lib/uuid/unparse.c index b5b9f58bf..c0e08ef49 100644 --- a/lib/uuid/unparse.c +++ b/lib/uuid/unparse.c @@ -36,16 +36,41 @@ #include "uuidP.h" -void uuid_unparse(const uuid_t uu, char *out) +static const char *fmt_lower = + "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"; + +static const char *fmt_upper = + "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X"; + +#ifdef UUID_UNPARSE_DEFAULT_UPPER +#define FMT_DEFAULT fmt_upper +#else +#define FMT_DEFAULT fmt_lower +#endif + +static void uuid_unparse_x(const uuid_t uu, char *out, const char *fmt) { struct uuid uuid; uuid_unpack(uu, &uuid); - sprintf(out, - "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", + sprintf(out, fmt, uuid.time_low, uuid.time_mid, uuid.time_hi_and_version, uuid.clock_seq >> 8, uuid.clock_seq & 0xFF, uuid.node[0], uuid.node[1], uuid.node[2], uuid.node[3], uuid.node[4], uuid.node[5]); } +void uuid_unparse_lower(const uuid_t uu, char *out) +{ + uuid_unparse_x(uu, out, fmt_lower); +} + +void uuid_unparse_upper(const uuid_t uu, char *out) +{ + uuid_unparse_x(uu, out, fmt_upper); +} + +void uuid_unparse(const uuid_t uu, char *out) +{ + uuid_unparse_x(uu, out, FMT_DEFAULT); +} diff --git a/lib/uuid/uuid.h b/lib/uuid/uuid.h index a037c7bc6..ff5459ed1 100644 --- a/lib/uuid/uuid.h +++ b/lib/uuid/uuid.h @@ -81,6 +81,8 @@ int uuid_parse(const char *in, uuid_t uu); /* unparse.c */ void uuid_unparse(const uuid_t uu, char *out); +void uuid_unparse_lower(const uuid_t uu, char *out); +void uuid_unparse_upper(const uuid_t uu, char *out); /* uuid_time.c */ time_t uuid_time(const uuid_t uu, struct timeval *ret_tv); diff --git a/lib/uuid/uuid_unparse.3.in b/lib/uuid/uuid_unparse.3.in index 7099ed22a..80aa9a81b 100644 --- a/lib/uuid/uuid_unparse.3.in +++ b/lib/uuid/uuid_unparse.3.in @@ -13,6 +13,8 @@ uuid_unparse \- output UUID variable in string format .B #include .sp .BI "void uuid_unparse(uuid_t " uu ", char *" out ); +.BI "void uuid_unparse_upper(uuid_t " uu ", char *" out ); +.BI "void uuid_unparse_lower(uuid_t " uu ", char *" out ); .fi .SH DESCRIPTION The @@ -22,9 +24,18 @@ function converts the supplied UUID from the internal binary format into a 36\-byte string (plus tailing '\\0') of the form 1b4e28ba\-2fa1\-11d2\-883f\-b9a76 and stores this value in the character string pointed to by -.IR out . -.SH "CONFORMING TO" -OSF DCE 1.1 +.IR out . +The case of the hex digits returned by +.B uuid_unparse +may be upper or lower case, and is +dependent on the system-dependent local default. +.PP +If the case of the +hex digits is important then the functions +.B uuid_unparse_upper +and +.B uuid_unparse_lower +may be used. .SH AUTHOR .B uuid_unparse was written by Theodore Y. Ts'o for the ext2 filesystem utilties. -- 2.47.2