1 /* SPDX-License-Identifier: LGPL-2.1-or-later */ 2 3 #include <errno.h> 4 #include <string.h> 5 6 #include "errno-list.h" 7 #include "macro.h" 8 9 static const struct errno_name* lookup_errno(register const char *str, 10 register GPERF_LEN_TYPE len); 11 12 #include "errno-from-name.h" 13 #include "errno-to-name.h" 14 errno_to_name(int id)15const char *errno_to_name(int id) { 16 17 if (id < 0) 18 id = -id; 19 20 if ((size_t) id >= ELEMENTSOF(errno_names)) 21 return NULL; 22 23 return errno_names[id]; 24 } 25 errno_from_name(const char * name)26int 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) 33 return -EINVAL; 34 35 assert(sc->id > 0); 36 return sc->id; 37 } 38