2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2013-11-22 04:01:46 +01:00
|
|
|
|
2018-01-11 00:39:12 +01:00
|
|
|
#include <errno.h>
|
2013-11-22 04:01:46 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "errno-list.h"
|
2015-11-30 21:43:37 +01:00
|
|
|
#include "macro.h"
|
2013-11-22 04:01:46 +01:00
|
|
|
|
|
|
|
static const struct errno_name* lookup_errno(register const char *str,
|
2017-01-10 08:39:05 +01:00
|
|
|
register GPERF_LEN_TYPE len);
|
2013-11-22 04:01:46 +01:00
|
|
|
|
|
|
|
#include "errno-from-name.h"
|
2015-11-16 22:09:36 +01:00
|
|
|
#include "errno-to-name.h"
|
2013-11-22 04:01:46 +01:00
|
|
|
|
|
|
|
const char *errno_to_name(int id) {
|
|
|
|
|
|
|
|
if (id < 0)
|
|
|
|
id = -id;
|
|
|
|
|
|
|
|
if (id >= (int) ELEMENTSOF(errno_names))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return errno_names[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
int errno_from_name(const char *name) {
|
|
|
|
const struct errno_name *sc;
|
|
|
|
|
|
|
|
assert(name);
|
|
|
|
|
|
|
|
sc = lookup_errno(name, strlen(name));
|
|
|
|
if (!sc)
|
2016-01-12 23:19:51 +01:00
|
|
|
return -EINVAL;
|
2013-11-22 04:01:46 +01:00
|
|
|
|
2016-01-12 23:19:51 +01:00
|
|
|
assert(sc->id > 0);
|
2013-11-22 04:01:46 +01:00
|
|
|
return sc->id;
|
|
|
|
}
|