* add a new flag to chase() that stops chasing once the first missing
component is found and then allows the caller to create the rest.
-* make use of new glibc 2.32 APIs sigabbrev_np() and strerrorname_np().
+* make use of new glibc 2.32 APIs sigabbrev_np().
* if /usr/bin/swapoff fails due to OOM, log a friendly explanatory message about it
['fsmount', '''#include <sys/mount.h>'''],
['getdents64', '''#include <dirent.h>'''],
['pidfd_spawn', '''#include <spawn.h>'''],
+ ['strerrorname_np', '''#include <string.h>'''],
]
have = cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE')
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) {
return errno_names[id];
}
+#endif
int errno_from_name(const char *name) {
const struct errno_name *sc;
#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;
}
#include "tests.h"
TEST(errno_list) {
+ ASSERT_NULL(errno_names[0]);
+ ASSERT_NULL(errno_to_name(0));
+
for (size_t i = 0; i < ELEMENTSOF(errno_names); i++) {
if (errno_names[i]) {
ASSERT_STREQ(errno_to_name(i), errno_names[i]);