]>
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 | |
6 | ||
7 | systemd is free software; you can redistribute it and/or modify it | |
8 | under the terms of the GNU Lesser General Public License as published by | |
9 | the Free Software Foundation; either version 2.1 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | systemd is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public License | |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ***/ | |
20 | ||
780896a4 LP |
21 | #include <string.h> |
22 | ||
780896a4 | 23 | #include "errno-list.h" |
11c3a366 | 24 | #include "macro.h" |
780896a4 LP |
25 | |
26 | static const struct errno_name* lookup_errno(register const char *str, | |
c9f7b4d3 | 27 | register GPERF_LEN_TYPE len); |
780896a4 | 28 | |
780896a4 | 29 | #include "errno-from-name.h" |
cf0fbc49 | 30 | #include "errno-to-name.h" |
780896a4 LP |
31 | |
32 | const char *errno_to_name(int id) { | |
33 | ||
34 | if (id < 0) | |
35 | id = -id; | |
36 | ||
37 | if (id >= (int) ELEMENTSOF(errno_names)) | |
38 | return NULL; | |
39 | ||
40 | return errno_names[id]; | |
41 | } | |
42 | ||
43 | int errno_from_name(const char *name) { | |
44 | const struct errno_name *sc; | |
45 | ||
46 | assert(name); | |
47 | ||
48 | sc = lookup_errno(name, strlen(name)); | |
49 | if (!sc) | |
d469dd44 | 50 | return -EINVAL; |
780896a4 | 51 | |
d469dd44 | 52 | assert(sc->id > 0); |
780896a4 LP |
53 | return sc->id; |
54 | } |