From 38df8d3f521c8d76c507c092f4a8e4bb84f9f48a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 5 Apr 2019 13:46:33 +0200 Subject: [PATCH] sd-id128: expose ID128_UUID_FORMAT_STR It is generally useful, and can be made public in the same manner that SD_ID128_FORMAT_STR is. --- man/rules/meson.build | 1 + man/sd-id128.xml | 6 ++++++ src/libsystemd/sd-id128/id128-util.h | 3 --- src/systemd/sd-id128.h | 3 +++ src/test/test-id128.c | 2 +- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/man/rules/meson.build b/man/rules/meson.build index d949900ddc..6f9f4c4443 100644 --- a/man/rules/meson.build +++ b/man/rules/meson.build @@ -101,6 +101,7 @@ manpages = [ 'SD_ID128_MAKE', 'SD_ID128_MAKE_STR', 'SD_ID128_NULL', + 'SD_ID128_UUID_FORMAT_STR', 'sd_id128_equal', 'sd_id128_is_null', 'sd_id128_t'], diff --git a/man/sd-id128.xml b/man/sd-id128.xml index 74d838df2e..22d5e0e3ed 100644 --- a/man/sd-id128.xml +++ b/man/sd-id128.xml @@ -24,6 +24,7 @@ SD_ID128_NULL SD_ID128_CONST_STR SD_ID128_FORMAT_STR + SD_ID128_UUID_FORMAT_STR SD_ID128_FORMAT_VAL sd_id128_equal sd_id128_is_null @@ -119,6 +120,11 @@ int main(int argc, char **argv) { return 0; } + SD_ID128_UUID_FORMAT_STR() is similar to + SD_ID128_FORMAT_STR() but includes separating hyphens to conform to the + "canonical representation". + + Use sd_id128_equal() to compare two 128-bit IDs: int main(int argc, char *argv[]) { diff --git a/src/libsystemd/sd-id128/id128-util.h b/src/libsystemd/sd-id128/id128-util.h index 65f14ab252..82a69a77f3 100644 --- a/src/libsystemd/sd-id128/id128-util.h +++ b/src/libsystemd/sd-id128/id128-util.h @@ -10,9 +10,6 @@ char *id128_to_uuid_string(sd_id128_t id, char s[37]); -/* Like SD_ID128_FORMAT_STR, but formats as UUID, not in plain format */ -#define ID128_UUID_FORMAT_STR "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" - bool id128_is_valid(const char *s) _pure_; typedef enum Id128Format { diff --git a/src/systemd/sd-id128.h b/src/systemd/sd-id128.h index bdf88ed53f..c5fbe0a4f1 100644 --- a/src/systemd/sd-id128.h +++ b/src/systemd/sd-id128.h @@ -63,6 +63,9 @@ int sd_id128_get_boot_app_specific(sd_id128_t app_id, sd_id128_t *ret); #define SD_ID128_FORMAT_STR "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" #define SD_ID128_FORMAT_VAL(x) (x).bytes[0], (x).bytes[1], (x).bytes[2], (x).bytes[3], (x).bytes[4], (x).bytes[5], (x).bytes[6], (x).bytes[7], (x).bytes[8], (x).bytes[9], (x).bytes[10], (x).bytes[11], (x).bytes[12], (x).bytes[13], (x).bytes[14], (x).bytes[15] +/* Like SD_ID128_FORMAT_STR, but formats as UUID, not in plain format */ +#define SD_ID128_UUID_FORMAT_STR "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" + #define SD_ID128_CONST_STR(x) \ ((const char[SD_ID128_STRING_MAX]) { \ ((x).bytes[0] >> 4) >= 10 ? 'a' + ((x).bytes[0] >> 4) - 10 : '0' + ((x).bytes[0] >> 4), \ diff --git a/src/test/test-id128.c b/src/test/test-id128.c index 8840788310..eea0765b7a 100644 --- a/src/test/test-id128.c +++ b/src/test/test-id128.c @@ -52,7 +52,7 @@ int main(int argc, char *argv[]) { assert_se(streq(q, UUID_WALDI)); b = mfree(b); - assert_se(asprintf(&b, ID128_UUID_FORMAT_STR, SD_ID128_FORMAT_VAL(ID128_WALDI)) == 36); + assert_se(asprintf(&b, SD_ID128_UUID_FORMAT_STR, SD_ID128_FORMAT_VAL(ID128_WALDI)) == 36); printf("waldi4: %s\n", b); assert_se(streq(q, b));