mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 00:14:32 +09:00
errno-list: prefer strerrorname_np() as errno_to_name() provider
This commit is contained in:
committed by
Lennart Poettering
parent
89c4fe6c21
commit
03ccee1939
2
TODO
2
TODO
@@ -1571,7 +1571,7 @@ Features:
|
||||
* 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
|
||||
|
||||
|
||||
@@ -675,6 +675,7 @@ foreach ident : [
|
||||
['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')
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
#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]);
|
||||
|
||||
Reference in New Issue
Block a user