mirror of
https://github.com/systemd/systemd.git
synced 2024-10-27 10:25:37 +03:00
Merge pull request #17493 from Villemoes/va-arg-simplifications
Some vararg simplifications
This commit is contained in:
commit
24309e6683
@ -49,16 +49,7 @@ static int sigaction_many_ap(const struct sigaction *sa, int sig, va_list ap) {
|
|||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
/* negative signal ends the list. 0 signal is skipped. */
|
/* negative signal ends the list. 0 signal is skipped. */
|
||||||
|
for (; sig >= 0; sig = va_arg(ap, int)) {
|
||||||
if (sig < 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (sig > 0) {
|
|
||||||
if (sigaction(sig, sa, NULL) < 0)
|
|
||||||
r = -errno;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((sig = va_arg(ap, int)) >= 0) {
|
|
||||||
|
|
||||||
if (sig == 0)
|
if (sig == 0)
|
||||||
continue;
|
continue;
|
||||||
|
@ -145,57 +145,32 @@ char *strnappend(const char *s, const char *suffix, size_t b) {
|
|||||||
|
|
||||||
char *strjoin_real(const char *x, ...) {
|
char *strjoin_real(const char *x, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
size_t l;
|
size_t l = 1;
|
||||||
char *r, *p;
|
char *r, *p;
|
||||||
|
|
||||||
va_start(ap, x);
|
va_start(ap, x);
|
||||||
|
for (const char *t = x; t; t = va_arg(ap, const char *)) {
|
||||||
|
size_t n;
|
||||||
|
|
||||||
if (x) {
|
n = strlen(t);
|
||||||
l = strlen(x);
|
if (n > SIZE_MAX - l) {
|
||||||
|
va_end(ap);
|
||||||
for (;;) {
|
return NULL;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
} else
|
l += n;
|
||||||
l = 0;
|
}
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
r = new(char, l+1);
|
p = r = new(char, l);
|
||||||
if (!r)
|
if (!r)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (x) {
|
va_start(ap, x);
|
||||||
p = stpcpy(r, x);
|
for (const char *t = x; t; t = va_arg(ap, const char *))
|
||||||
|
p = stpcpy(p, t);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
va_start(ap, x);
|
*p = 0;
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
const char *t;
|
|
||||||
|
|
||||||
t = va_arg(ap, const char *);
|
|
||||||
if (!t)
|
|
||||||
break;
|
|
||||||
|
|
||||||
p = stpcpy(p, t);
|
|
||||||
}
|
|
||||||
|
|
||||||
va_end(ap);
|
|
||||||
} else
|
|
||||||
r[0] = 0;
|
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,6 @@ size_t strv_length(char * const *l) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char **strv_new_ap(const char *x, va_list ap) {
|
char **strv_new_ap(const char *x, va_list ap) {
|
||||||
const char *s;
|
|
||||||
_cleanup_strv_free_ char **a = NULL;
|
_cleanup_strv_free_ char **a = NULL;
|
||||||
size_t n = 0, i = 0;
|
size_t n = 0, i = 0;
|
||||||
va_list aq;
|
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
|
* STRV_IFNOTNULL() macro to include possibly NULL strings in
|
||||||
* the string list. */
|
* the string list. */
|
||||||
|
|
||||||
if (x) {
|
va_copy(aq, ap);
|
||||||
n = x == STRV_IGNORE ? 0 : 1;
|
for (const char *s = x; s; s = va_arg(aq, const char*)) {
|
||||||
|
if (s == STRV_IGNORE)
|
||||||
|
continue;
|
||||||
|
|
||||||
va_copy(aq, ap);
|
n++;
|
||||||
while ((s = va_arg(aq, const char*))) {
|
|
||||||
if (s == STRV_IGNORE)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
|
|
||||||
va_end(aq);
|
|
||||||
}
|
}
|
||||||
|
va_end(aq);
|
||||||
|
|
||||||
a = new(char*, n+1);
|
a = new(char*, n+1);
|
||||||
if (!a)
|
if (!a)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (x) {
|
for (const char *s = x; s; s = va_arg(ap, const char*)) {
|
||||||
if (x != STRV_IGNORE) {
|
if (s == STRV_IGNORE)
|
||||||
a[i] = strdup(x);
|
continue;
|
||||||
if (!a[i])
|
|
||||||
return NULL;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((s = va_arg(ap, const char*))) {
|
a[i] = strdup(s);
|
||||||
|
if (!a[i])
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (s == STRV_IGNORE)
|
i++;
|
||||||
continue;
|
|
||||||
|
|
||||||
a[i] = strdup(s);
|
|
||||||
if (!a[i])
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
a[i] = NULL;
|
a[i] = NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user