errno-list: prefer strerrorname_np() as errno_to_name() provider
This commit is contained in:
committed by
Lennart Poettering
parent
89c4fe6c21
commit
03ccee1939
@@ -10,6 +10,8 @@ static const struct errno_name* lookup_errno(register const char *str,
|
||||
register GPERF_LEN_TYPE len);
|
||||
|
||||
#include "errno-from-name.h"
|
||||
|
||||
#if !HAVE_STRERRORNAME_NP
|
||||
#include "errno-to-name.h"
|
||||
|
||||
const char* errno_to_name(int id) {
|
||||
@@ -22,6 +24,7 @@ const char* errno_to_name(int id) {
|
||||
|
||||
return errno_names[id];
|
||||
}
|
||||
#endif
|
||||
|
||||
int errno_from_name(const char *name) {
|
||||
const struct errno_name *sc;
|
||||
|
||||
@@ -2,14 +2,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* MAX_ERRNO is defined as 4095 in linux/err.h
|
||||
* We use the same value here.
|
||||
*/
|
||||
#define ERRNO_MAX 4095
|
||||
|
||||
#if HAVE_STRERRORNAME_NP
|
||||
static inline const char* errno_to_name(int id) {
|
||||
if (id == 0) /* To stay in line with our own impl */
|
||||
return NULL;
|
||||
|
||||
return strerrorname_np(abs(id));
|
||||
}
|
||||
#else
|
||||
const char* errno_to_name(int id);
|
||||
#endif
|
||||
|
||||
int errno_from_name(const char *name);
|
||||
|
||||
static inline bool errno_is_valid(int n) {
|
||||
return n > 0 && n <= ERRNO_MAX;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user