]> git.proxmox.com Git - systemd.git/blame - src/basic/errno-list.c
New upstream version 236
[systemd.git] / src / basic / errno-list.c
CommitLineData
52ad194e 1/* SPDX-License-Identifier: LGPL-2.1+ */
663996b3
MS
2/***
3 This file is part of systemd.
4
60f067b4 5 Copyright 2013 Lennart Poettering
663996b3
MS
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
663996b3
MS
21#include <string.h>
22
60f067b4 23#include "errno-list.h"
4c89c718 24#include "macro.h"
663996b3 25
60f067b4 26static const struct errno_name* lookup_errno(register const char *str,
2897b343 27 register GPERF_LEN_TYPE len);
663996b3 28
60f067b4 29#include "errno-from-name.h"
db2df898 30#include "errno-to-name.h"
60f067b4
JS
31
32const char *errno_to_name(int id) {
33
34 if (id < 0)
35 id = -id;
663996b3 36
60f067b4 37 if (id >= (int) ELEMENTSOF(errno_names))
663996b3
MS
38 return NULL;
39
60f067b4 40 return errno_names[id];
663996b3
MS
41}
42
60f067b4
JS
43int errno_from_name(const char *name) {
44 const struct errno_name *sc;
663996b3
MS
45
46 assert(name);
47
60f067b4 48 sc = lookup_errno(name, strlen(name));
663996b3 49 if (!sc)
4c89c718 50 return -EINVAL;
663996b3 51
4c89c718 52 assert(sc->id > 0);
663996b3
MS
53 return sc->id;
54}