chiark / gitweb /
e6fc0baeb5294ca397e9da21b36cc3830b6f42e0
[elogind.git] / src / basic / errno-list.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3   This file is part of systemd.
4
5   Copyright 2013 Lennart Poettering
6 ***/
7
8 #include <errno.h>
9 #include <string.h>
10
11 #include "errno-list.h"
12 #include "macro.h"
13
14 static const struct errno_name* lookup_errno(register const char *str,
15                                              register GPERF_LEN_TYPE len);
16
17 #include "errno-from-name.h"
18 #include "errno-to-name.h"
19
20 const char *errno_to_name(int id) {
21
22         if (id < 0)
23                 id = -id;
24
25         if (id >= (int) ELEMENTSOF(errno_names))
26                 return NULL;
27
28         return errno_names[id];
29 }
30
31 int errno_from_name(const char *name) {
32         const struct errno_name *sc;
33
34         assert(name);
35
36         sc = lookup_errno(name, strlen(name));
37         if (!sc)
38                 return -EINVAL;
39
40         assert(sc->id > 0);
41         return sc->id;
42 }
43 #if 0 /// UNNEEDED by elogind
44 #endif // 0