]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
780896a4 LP |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2013 Lennart Poettering | |
780896a4 LP |
6 | ***/ |
7 | ||
dccca82b | 8 | #include <errno.h> |
780896a4 LP |
9 | #include <string.h> |
10 | ||
780896a4 | 11 | #include "errno-list.h" |
11c3a366 | 12 | #include "macro.h" |
780896a4 LP |
13 | |
14 | static const struct errno_name* lookup_errno(register const char *str, | |
c9f7b4d3 | 15 | register GPERF_LEN_TYPE len); |
780896a4 | 16 | |
780896a4 | 17 | #include "errno-from-name.h" |
cf0fbc49 | 18 | #include "errno-to-name.h" |
780896a4 LP |
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) | |
d469dd44 | 38 | return -EINVAL; |
780896a4 | 39 | |
d469dd44 | 40 | assert(sc->id > 0); |
780896a4 LP |
41 | return sc->id; |
42 | } |