errno-list: errno_from_name() is pure but not const

Follow-up for 0c15577abe
This commit is contained in:
Mike Yuan
2025-05-26 20:24:43 +02:00
parent 82775307c5
commit 5a881f7f71
3 changed files with 23 additions and 25 deletions
+22 -22
View File
@@ -9,28 +9,6 @@ static const struct errno_name* lookup_errno(register const char *str,
#include "errno-from-name.inc"
#if HAVE_STRERRORNAME_NP
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
#include "errno-to-name.inc"
const char* errno_to_name(int id) {
if (id < 0)
id = -id;
if ((size_t) id >= ELEMENTSOF(errno_names))
return NULL;
return errno_names[id];
}
#endif
int errno_from_name(const char *name) {
const struct errno_name *sc;
@@ -43,3 +21,25 @@ int errno_from_name(const char *name) {
assert(sc->id > 0);
return sc->id;
}
#if HAVE_STRERRORNAME_NP
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
# include "errno-to-name.inc"
const char* errno_to_name(int id) {
if (id < 0)
id = -id;
if ((size_t) id >= ELEMENTSOF(errno_names))
return NULL;
return errno_names[id];
}
#endif
+1 -2
View File
@@ -4,8 +4,7 @@
#include "forward.h"
const char* errno_to_name(int id);
int errno_from_name(const char *name) _const_;
int errno_from_name(const char *name) _pure_;
static inline bool errno_is_valid(int n) {
return n > 0 && n <= ERRNO_MAX;
-1
View File
@@ -52,7 +52,6 @@ static inline int negative_errno(void) {
* It will suppress bogus gcc warnings in case it assumes 'errno' might
* be 0 and thus the caller's error-handling might not be triggered. */
assert_return(errno > 0, -EINVAL);
return -errno;
}