]> err.no Git - util-linux/commitdiff
libblkid: create a generic blkid_unparse_uuid()
authorKarel Zak <kzak@redhat.com>
Tue, 15 Sep 2009 18:36:46 +0000 (20:36 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 15 Sep 2009 18:36:46 +0000 (20:36 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/blkid/src/blkidP.h
shlibs/blkid/src/probe.c

index e0e5cb81d5cf28ce2581f5ea8405bb10f8015c7d..c12fdb13f4a7b401aa4e71d1be0ab12335a825fd 100644 (file)
@@ -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
 
index 4677389ec309abcfc50b5a65aa839079008dcd70..1b7d4b8b3c8c822ebdb8d1b31825801eedd65f9b 100644 (file)
@@ -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
+}
+