]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
00616955 LP |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2016 Lennart Poettering | |
00616955 LP |
6 | ***/ |
7 | ||
8 | #include "ordered-set.h" | |
9 | #include "strv.h" | |
10 | ||
11 | int ordered_set_consume(OrderedSet *s, void *p) { | |
12 | int r; | |
13 | ||
14 | r = ordered_set_put(s, p); | |
15 | if (r <= 0) | |
16 | free(p); | |
17 | ||
18 | return r; | |
19 | } | |
20 | ||
21 | int ordered_set_put_strdup(OrderedSet *s, const char *p) { | |
22 | char *c; | |
23 | int r; | |
24 | ||
25 | assert(s); | |
26 | assert(p); | |
27 | ||
28 | c = strdup(p); | |
29 | if (!c) | |
30 | return -ENOMEM; | |
31 | ||
32 | r = ordered_set_consume(s, c); | |
33 | if (r == -EEXIST) | |
34 | return 0; | |
35 | ||
36 | return r; | |
37 | } | |
38 | ||
39 | int ordered_set_put_strdupv(OrderedSet *s, char **l) { | |
40 | int n = 0, r; | |
41 | char **i; | |
42 | ||
43 | STRV_FOREACH(i, l) { | |
44 | r = ordered_set_put_strdup(s, *i); | |
45 | if (r < 0) | |
46 | return r; | |
47 | ||
48 | n += r; | |
49 | } | |
50 | ||
51 | return n; | |
52 | } |