diff options
author | Lennart Poettering <lennart@poettering.net> | 2019-07-04 18:27:02 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2019-12-02 09:47:00 +0100 |
commit | a832b08e6e1bb93829b488615006bba768c50121 (patch) | |
tree | bebf52eab608ce2567bb0a654249b0850230f0c5 /src/shared/json.c | |
parent | json: add json_variant_unbase64() helper (diff) | |
download | systemd-a832b08e6e1bb93829b488615006bba768c50121.tar.xz systemd-a832b08e6e1bb93829b488615006bba768c50121.zip |
json: add json_variant_set_field_integer() and json_variant_set_field_boolean() helpers
Diffstat (limited to 'src/shared/json.c')
-rw-r--r-- | src/shared/json.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/shared/json.c b/src/shared/json.c index d1a477c36d..7c62136703 100644 --- a/src/shared/json.c +++ b/src/shared/json.c @@ -1905,6 +1905,17 @@ int json_variant_set_field_string(JsonVariant **v, const char *field, const char return json_variant_set_field(v, field, m); } +int json_variant_set_field_integer(JsonVariant **v, const char *field, intmax_t i) { + _cleanup_(json_variant_unrefp) JsonVariant *m = NULL; + int r; + + r = json_variant_new_integer(&m, i); + if (r < 0) + return r; + + return json_variant_set_field(v, field, m); +} + int json_variant_set_field_unsigned(JsonVariant **v, const char *field, uintmax_t u) { _cleanup_(json_variant_unrefp) JsonVariant *m = NULL; int r; @@ -1916,6 +1927,17 @@ int json_variant_set_field_unsigned(JsonVariant **v, const char *field, uintmax_ return json_variant_set_field(v, field, m); } +int json_variant_set_field_boolean(JsonVariant **v, const char *field, bool b) { + _cleanup_(json_variant_unrefp) JsonVariant *m = NULL; + int r; + + r = json_variant_new_boolean(&m, b); + if (r < 0) + return r; + + return json_variant_set_field(v, field, m); +} + int json_variant_merge(JsonVariant **v, JsonVariant *m) { _cleanup_(json_variant_unrefp) JsonVariant *w = NULL; _cleanup_free_ JsonVariant **array = NULL; |