]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/ordered-set.c
pkgconfig: define variables relative to ${prefix}/${rootprefix}/${sysconfdir}
[thirdparty/systemd.git] / src / basic / ordered-set.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include "ordered-set.h"
4 #include "strv.h"
5
6 int ordered_set_consume(OrderedSet *s, void *p) {
7 int r;
8
9 r = ordered_set_put(s, p);
10 if (r <= 0)
11 free(p);
12
13 return r;
14 }
15
16 int ordered_set_put_strdup(OrderedSet *s, const char *p) {
17 char *c;
18 int r;
19
20 assert(s);
21 assert(p);
22
23 c = strdup(p);
24 if (!c)
25 return -ENOMEM;
26
27 r = ordered_set_consume(s, c);
28 if (r == -EEXIST)
29 return 0;
30
31 return r;
32 }
33
34 int ordered_set_put_strdupv(OrderedSet *s, char **l) {
35 int n = 0, r;
36 char **i;
37
38 STRV_FOREACH(i, l) {
39 r = ordered_set_put_strdup(s, *i);
40 if (r < 0)
41 return r;
42
43 n += r;
44 }
45
46 return n;
47 }