]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/set.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / basic / set.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 This file is part of systemd.
4
5 Copyright 2017 Lennart Poettering
6
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19 ***/
20
21 #include "set.h"
22
23 int set_make(Set **ret, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS, void *add, ...) {
24 _cleanup_set_free_ Set *s = NULL;
25 int r;
26
27 assert(ret);
28
29 s = set_new(hash_ops HASHMAP_DEBUG_PASS_ARGS);
30 if (!s)
31 return -ENOMEM;
32
33 if (add) {
34 va_list ap;
35
36 r = set_put(s, add);
37 if (r < 0)
38 return r;
39
40 va_start(ap, add);
41
42 for(;;) {
43 void *arg = va_arg(ap, void*);
44
45 if (!arg)
46 break;
47
48 r = set_put(s, arg);
49 if (r < 0) {
50 va_end(ap);
51 return r;
52 }
53 }
54
55 va_end(ap);
56 }
57
58 *ret = s;
59 s = NULL;
60
61 return 0;
62 }