id128-util: add new helper id128_equal_string()

Quite often we compare uuids/id128 formatted as strings with specific
values. So far we usually used streq() for that. let's add a new
explicit helper for this in id128_equal_string() that compares a string
with an sd_id128_t and is more robust than a simple string comparison.
Moreover, we can mroe easily reuse the various defines we have for
specific UUIDs, for example those from gpt.h.
This commit is contained in:
Lennart Poettering
2022-02-14 15:14:03 +01:00
parent b74163607b
commit 75a505c600
2 changed files with 18 additions and 0 deletions
+16
View File
@@ -206,3 +206,19 @@ int id128_get_product(sd_id128_t *ret) {
*ret = uuid;
return 0;
}
int id128_equal_string(const char *s, sd_id128_t id) {
sd_id128_t parsed;
int r;
if (!s)
return false;
/* Checks if the specified string matches a valid string representation of the specified 128 bit ID/uuid */
r = sd_id128_from_string(s, &parsed);
if (r < 0)
return r;
return sd_id128_equal(parsed, id);
}
+2
View File
@@ -34,3 +34,5 @@ extern const struct hash_ops id128_hash_ops;
sd_id128_t id128_make_v4_uuid(sd_id128_t id);
int id128_get_product(sd_id128_t *ret);
int id128_equal_string(const char *s, sd_id128_t id);