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