]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
780896a4 | 2 | |
dccca82b | 3 | #include <errno.h> |
780896a4 LP |
4 | #include <string.h> |
5 | ||
780896a4 | 6 | #include "errno-list.h" |
11c3a366 | 7 | #include "macro.h" |
780896a4 LP |
8 | |
9 | static const struct errno_name* lookup_errno(register const char *str, | |
c9f7b4d3 | 10 | register GPERF_LEN_TYPE len); |
780896a4 | 11 | |
780896a4 | 12 | #include "errno-from-name.h" |
cf0fbc49 | 13 | #include "errno-to-name.h" |
780896a4 LP |
14 | |
15 | const char *errno_to_name(int id) { | |
16 | ||
17 | if (id < 0) | |
18 | id = -id; | |
19 | ||
cedfe0b0 | 20 | if ((size_t) id >= ELEMENTSOF(errno_names)) |
780896a4 LP |
21 | return NULL; |
22 | ||
23 | return errno_names[id]; | |
24 | } | |
25 | ||
26 | int errno_from_name(const char *name) { | |
27 | const struct errno_name *sc; | |
28 | ||
29 | assert(name); | |
30 | ||
31 | sc = lookup_errno(name, strlen(name)); | |
32 | if (!sc) | |
d469dd44 | 33 | return -EINVAL; |
780896a4 | 34 | |
d469dd44 | 35 | assert(sc->id > 0); |
780896a4 LP |
36 | return sc->id; |
37 | } |