mirror of
https://github.com/systemd/systemd.git
synced 2025-01-10 05:18:17 +03:00
json-util: Add JSON_BUILD_PAIR_INTEGER_NON_NEGATIVE()
This commit is contained in:
parent
ab8a5e1f99
commit
7606139e61
@ -144,6 +144,7 @@ enum {
|
||||
_JSON_BUILD_RATELIMIT,
|
||||
|
||||
_JSON_BUILD_PAIR_INTEGER_NON_ZERO,
|
||||
_JSON_BUILD_PAIR_INTEGER_NON_NEGATIVE,
|
||||
_JSON_BUILD_PAIR_UNSIGNED_NON_ZERO,
|
||||
_JSON_BUILD_PAIR_FINITE_USEC,
|
||||
_JSON_BUILD_PAIR_STRING_NON_EMPTY,
|
||||
@ -178,6 +179,7 @@ enum {
|
||||
#define JSON_BUILD_RATELIMIT(rl) _JSON_BUILD_RATELIMIT, (const RateLimit*) { rl }
|
||||
|
||||
#define JSON_BUILD_PAIR_INTEGER_NON_ZERO(name, i) _JSON_BUILD_PAIR_INTEGER_NON_ZERO, (const char*) { name }, (int64_t) { i }
|
||||
#define JSON_BUILD_PAIR_INTEGER_NON_NEGATIVE(name, i) _JSON_BUILD_PAIR_INTEGER_NON_NEGATIVE, (const char*) { name }, (int64_t) { i }
|
||||
#define JSON_BUILD_PAIR_UNSIGNED_NON_ZERO(name, u) _JSON_BUILD_PAIR_UNSIGNED_NON_ZERO, (const char*) { name }, (uint64_t) { u }
|
||||
#define JSON_BUILD_PAIR_FINITE_USEC(name, u) _JSON_BUILD_PAIR_FINITE_USEC, (const char*) { name }, (usec_t) { u }
|
||||
#define JSON_BUILD_PAIR_STRING_NON_EMPTY(name, s) _JSON_BUILD_PAIR_STRING_NON_EMPTY, (const char*) { name }, (const char*) { s }
|
||||
|
@ -4330,9 +4330,11 @@ _public_ int sd_json_buildv(sd_json_variant **ret, va_list ap) {
|
||||
break;
|
||||
}
|
||||
|
||||
case _JSON_BUILD_PAIR_INTEGER_NON_ZERO: {
|
||||
case _JSON_BUILD_PAIR_INTEGER_NON_ZERO:
|
||||
case _JSON_BUILD_PAIR_INTEGER_NON_NEGATIVE: {
|
||||
const char *n;
|
||||
int64_t i;
|
||||
bool include;
|
||||
|
||||
if (current->expect != EXPECT_OBJECT_KEY) {
|
||||
r = -EINVAL;
|
||||
@ -4342,7 +4344,14 @@ _public_ int sd_json_buildv(sd_json_variant **ret, va_list ap) {
|
||||
n = va_arg(ap, const char*);
|
||||
i = va_arg(ap, int64_t);
|
||||
|
||||
if (i != 0 && current->n_suppress == 0) {
|
||||
if (command == _JSON_BUILD_PAIR_INTEGER_NON_ZERO)
|
||||
include = i != 0;
|
||||
else if (command == _JSON_BUILD_PAIR_INTEGER_NON_NEGATIVE)
|
||||
include = i >= 0;
|
||||
else
|
||||
assert_not_reached();
|
||||
|
||||
if (include && current->n_suppress == 0) {
|
||||
r = sd_json_variant_new_string(&add, n);
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
|
Loading…
Reference in New Issue
Block a user