]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/af-list.c
meson: make user $PATH configurable
[thirdparty/systemd.git] / src / basic / af-list.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
4298d0b5 2
acf4d158 3#include <errno.h>
4298d0b5 4#include <string.h>
cf0fbc49 5#include <sys/socket.h>
4298d0b5 6
4298d0b5 7#include "af-list.h"
11c3a366 8#include "macro.h"
4298d0b5 9
c9f7b4d3 10static const struct af_name* lookup_af(register const char *str, register GPERF_LEN_TYPE len);
4298d0b5 11
4298d0b5 12#include "af-from-name.h"
cf0fbc49 13#include "af-to-name.h"
4298d0b5
LP
14
15const char *af_to_name(int id) {
16
17 if (id <= 0)
18 return NULL;
19
cedfe0b0 20 if ((size_t) id >= ELEMENTSOF(af_names))
4298d0b5
LP
21 return NULL;
22
23 return af_names[id];
24}
25
26int af_from_name(const char *name) {
27 const struct af_name *sc;
28
29 assert(name);
30
31 sc = lookup_af(name, strlen(name));
32 if (!sc)
acf4d158 33 return -EINVAL;
4298d0b5
LP
34
35 return sc->id;
36}
37
38int af_max(void) {
39 return ELEMENTSOF(af_names);
40}