1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-30 06:25:37 +03:00

shared: Add specifier_id128() and specifier_uuid()

This commit is contained in:
Daan De Meyer 2022-09-19 15:35:17 +02:00
parent 780c805537
commit 74235f6d08
2 changed files with 28 additions and 14 deletions

View File

@ -151,9 +151,32 @@ int specifier_real_directory(char specifier, const void *data, const char *root,
return path_extract_directory(path, ret);
}
int specifier_id128(char specifier, const void *data, const char *root, const void *userdata, char **ret) {
const sd_id128_t *id = ASSERT_PTR(data);
char *n;
n = new(char, SD_ID128_STRING_MAX);
if (!n)
return -ENOMEM;
*ret = sd_id128_to_string(*id, n);
return 0;
}
int specifier_uuid(char specifier, const void *data, const char *root, const void *userdata, char **ret) {
const sd_id128_t *id = ASSERT_PTR(data);
char *n;
n = new(char, SD_ID128_UUID_STRING_MAX);
if (!n)
return -ENOMEM;
*ret = sd_id128_to_uuid_string(*id, n);
return 0;
}
int specifier_machine_id(char specifier, const void *data, const char *root, const void *userdata, char **ret) {
sd_id128_t id;
char *n;
int r;
assert(ret);
@ -172,17 +195,11 @@ int specifier_machine_id(char specifier, const void *data, const char *root, con
if (r < 0)
return r;
n = new(char, SD_ID128_STRING_MAX);
if (!n)
return -ENOMEM;
*ret = sd_id128_to_string(id, n);
return 0;
return specifier_id128(specifier, &id, root, userdata, ret);
}
int specifier_boot_id(char specifier, const void *data, const char *root, const void *userdata, char **ret) {
sd_id128_t id;
char *n;
int r;
assert(ret);
@ -191,12 +208,7 @@ int specifier_boot_id(char specifier, const void *data, const char *root, const
if (r < 0)
return r;
n = new(char, SD_ID128_STRING_MAX);
if (!n)
return -ENOMEM;
*ret = sd_id128_to_string(id, n);
return 0;
return specifier_id128(specifier, &id, root, userdata, ret);
}
int specifier_hostname(char specifier, const void *data, const char *root, const void *userdata, char **ret) {

View File

@ -16,6 +16,8 @@ int specifier_printf(const char *text, size_t max_length, const Specifier table[
int specifier_string(char specifier, const void *data, const char *root, const void *userdata, char **ret);
int specifier_real_path(char specifier, const void *data, const char *root, const void *userdata, char **ret);
int specifier_real_directory(char specifier, const void *data, const char *root, const void *userdata, char **ret);
int specifier_id128(char specifier, const void *data, const char *root, const void *userdata, char **ret);
int specifier_uuid(char specifier, const void *data, const char *root, const void *userdata, char **ret);
int specifier_machine_id(char specifier, const void *data, const char *root, const void *userdata, char **ret);
int specifier_boot_id(char specifier, const void *data, const char *root, const void *userdata, char **ret);