From: 0xAX <0xAX@users.noreply.github.com> Date: Mon, 27 Jun 2016 21:26:07 +0000 (+0300) Subject: basic/strv: introduce STRV_IGNORE macro (#3601) X-Git-Tag: v231.3~85 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=65a63c6468ba3ecfef370c477d03e39cc15e7e92;p=elogind.git basic/strv: introduce STRV_IGNORE macro (#3601) to hide casting of '-1' strings and make code cleaner. --- diff --git a/src/basic/strv.c b/src/basic/strv.c index 87b11d00d..47f7a7295 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -139,16 +139,16 @@ char **strv_new_ap(const char *x, va_list ap) { va_list aq; /* As a special trick we ignore all listed strings that equal - * (const char*) -1. This is supposed to be used with the + * STRV_IGNORE. This is supposed to be used with the * STRV_IFNOTNULL() macro to include possibly NULL strings in * the string list. */ if (x) { - n = x == (const char*) -1 ? 0 : 1; + n = x == STRV_IGNORE ? 0 : 1; va_copy(aq, ap); while ((s = va_arg(aq, const char*))) { - if (s == (const char*) -1) + if (s == STRV_IGNORE) continue; n++; @@ -162,7 +162,7 @@ char **strv_new_ap(const char *x, va_list ap) { return NULL; if (x) { - if (x != (const char*) -1) { + if (x != STRV_IGNORE) { a[i] = strdup(x); if (!a[i]) goto fail; @@ -171,7 +171,7 @@ char **strv_new_ap(const char *x, va_list ap) { while ((s = va_arg(ap, const char*))) { - if (s == (const char*) -1) + if (s == STRV_IGNORE) continue; a[i] = strdup(s); diff --git a/src/basic/strv.h b/src/basic/strv.h index 591a452e9..c95a637b4 100644 --- a/src/basic/strv.h +++ b/src/basic/strv.h @@ -77,8 +77,10 @@ bool strv_equal(char **a, char **b); char **strv_new(const char *x, ...) _sentinel_; char **strv_new_ap(const char *x, va_list ap); +#define STRV_IGNORE ((const char *) -1) + static inline const char* STRV_IFNOTNULL(const char *x) { - return x ? x : (const char *) -1; + return x ? x : STRV_IGNORE; } static inline bool strv_isempty(char * const *l) {