summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/basic/signal-util.c11
-rw-r--r--src/basic/string-util.c55
-rw-r--r--src/basic/strv.c42
3 files changed, 29 insertions, 79 deletions
diff --git a/src/basic/signal-util.c b/src/basic/signal-util.c
index cb59f6ca0f..e976205d86 100644
--- a/src/basic/signal-util.c
+++ b/src/basic/signal-util.c
@@ -49,16 +49,7 @@ static int sigaction_many_ap(const struct sigaction *sa, int sig, va_list ap) {
int r = 0;
/* negative signal ends the list. 0 signal is skipped. */
-
- if (sig < 0)
- return 0;
-
- if (sig > 0) {
- if (sigaction(sig, sa, NULL) < 0)
- r = -errno;
- }
-
- while ((sig = va_arg(ap, int)) >= 0) {
+ for (; sig >= 0; sig = va_arg(ap, int)) {
if (sig == 0)
continue;
diff --git a/src/basic/string-util.c b/src/basic/string-util.c
index ab725d0dab..12c4ae177a 100644
--- a/src/basic/string-util.c
+++ b/src/basic/string-util.c
@@ -145,57 +145,32 @@ char *strnappend(const char *s, const char *suffix, size_t b) {
char *strjoin_real(const char *x, ...) {
va_list ap;
- size_t l;
+ size_t l = 1;
char *r, *p;
va_start(ap, x);
+ for (const char *t = x; t; t = va_arg(ap, const char *)) {
+ size_t n;
- if (x) {
- l = strlen(x);
-
- for (;;) {
- const char *t;
- size_t n;
-
- t = va_arg(ap, const char *);
- if (!t)
- break;
-
- n = strlen(t);
- if (n > ((size_t) -1) - l) {
- va_end(ap);
- return NULL;
- }
-
- l += n;
+ n = strlen(t);
+ if (n > SIZE_MAX - l) {
+ va_end(ap);
+ return NULL;
}
- } else
- l = 0;
-
+ l += n;
+ }
va_end(ap);
- r = new(char, l+1);
+ p = r = new(char, l);
if (!r)
return NULL;
- if (x) {
- p = stpcpy(r, x);
-
- va_start(ap, x);
-
- for (;;) {
- const char *t;
-
- t = va_arg(ap, const char *);
- if (!t)
- break;
-
- p = stpcpy(p, t);
- }
+ va_start(ap, x);
+ for (const char *t = x; t; t = va_arg(ap, const char *))
+ p = stpcpy(p, t);
+ va_end(ap);
- va_end(ap);
- } else
- r[0] = 0;
+ *p = 0;
return r;
}
diff --git a/src/basic/strv.c b/src/basic/strv.c
index c5e6dd5f21..dd3a164879 100644
--- a/src/basic/strv.c
+++ b/src/basic/strv.c
@@ -123,7 +123,6 @@ size_t strv_length(char * const *l) {
}
char **strv_new_ap(const char *x, va_list ap) {
- const char *s;
_cleanup_strv_free_ char **a = NULL;
size_t n = 0, i = 0;
va_list aq;
@@ -133,43 +132,28 @@ char **strv_new_ap(const char *x, va_list ap) {
* STRV_IFNOTNULL() macro to include possibly NULL strings in
* the string list. */
- if (x) {
- n = x == STRV_IGNORE ? 0 : 1;
-
- va_copy(aq, ap);
- while ((s = va_arg(aq, const char*))) {
- if (s == STRV_IGNORE)
- continue;
-
- n++;
- }
+ va_copy(aq, ap);
+ for (const char *s = x; s; s = va_arg(aq, const char*)) {
+ if (s == STRV_IGNORE)
+ continue;
- va_end(aq);
+ n++;
}
+ va_end(aq);
a = new(char*, n+1);
if (!a)
return NULL;
- if (x) {
- if (x != STRV_IGNORE) {
- a[i] = strdup(x);
- if (!a[i])
- return NULL;
- i++;
- }
-
- while ((s = va_arg(ap, const char*))) {
-
- if (s == STRV_IGNORE)
- continue;
+ for (const char *s = x; s; s = va_arg(ap, const char*)) {
+ if (s == STRV_IGNORE)
+ continue;
- a[i] = strdup(s);
- if (!a[i])
- return NULL;
+ a[i] = strdup(s);
+ if (!a[i])
+ return NULL;
- i++;
- }
+ i++;
}
a[i] = NULL;