From: Karel Zak Date: Tue, 15 Sep 2009 18:36:46 +0000 (+0200) Subject: libblkid: create a generic blkid_unparse_uuid() X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=201529bd71b0a20f2303be4f0b839af59ecf43c2;p=util-linux libblkid: create a generic blkid_unparse_uuid() Signed-off-by: Karel Zak --- diff --git a/shlibs/blkid/src/blkidP.h b/shlibs/blkid/src/blkidP.h index e0e5cb81..c12fdb13 100644 --- a/shlibs/blkid/src/blkidP.h +++ b/shlibs/blkid/src/blkidP.h @@ -338,6 +338,8 @@ extern int blkid_probe_strncpy_uuid(blkid_probe pr, unsigned char *str, size_t l extern int blkid_probe_set_uuid(blkid_probe pr, unsigned char *uuid); extern int blkid_probe_set_uuid_as(blkid_probe pr, unsigned char *uuid, const char *name); +extern void blkid_unparse_uuid(const unsigned char *uuid, char *str, size_t len); + #define BLKID_ENC_UTF16BE 0 #define BLKID_ENC_UTF16LE 1 diff --git a/shlibs/blkid/src/probe.c b/shlibs/blkid/src/probe.c index 4677389e..1b7d4b8b 100644 --- a/shlibs/blkid/src/probe.c +++ b/shlibs/blkid/src/probe.c @@ -862,21 +862,9 @@ int blkid_probe_set_uuid_as(blkid_probe pr, unsigned char *uuid, const char *nam } else v = blkid_probe_assign_value(pr, name); -#ifdef HAVE_LIBUUID - { - uuid_unparse(uuid, (char *) v->data); - v->len = 37; - } -#else - v->len = snprintf(v->data, sizeof(v->data), - "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", - uuid[0], uuid[1], uuid[2], uuid[3], - uuid[4], uuid[5], - uuid[6], uuid[7], - uuid[8], uuid[9], - uuid[10], uuid[11], uuid[12], uuid[13], uuid[14],uuid[15]); - v->len++; -#endif + blkid_unparse_uuid(uuid, (char *) v->data, sizeof(v->data)); + v->len = 37; + return 0; } @@ -935,3 +923,21 @@ int blkid_probe_has_value(blkid_probe pr, const char *name) return 0; } + +/* converts DCE UUID (uuid[16]) to human readable string + * - the @len should be always 37 */ +void blkid_unparse_uuid(const unsigned char *uuid, char *str, size_t len) +{ +#ifdef HAVE_LIBUUID + uuid_unparse(uuid, str); +#else + snprintf(str, len, + "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", + uuid[0], uuid[1], uuid[2], uuid[3], + uuid[4], uuid[5], + uuid[6], uuid[7], + uuid[8], uuid[9], + uuid[10], uuid[11], uuid[12], uuid[13], uuid[14],uuid[15]); +#endif +} +