]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
errno-list: fallback to use our errno name table
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 25 Jul 2025 00:40:00 +0000 (09:40 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 25 Jul 2025 09:50:45 +0000 (10:50 +0100)
Some architecture specific errno may not be known by glibc.
Let's fallback to our table when strerrorname_np() returns NULL.

Fixes the following error in mips:
```
src/test/test-errno-list.c:14: Assertion failed: Expected "errno_to_name(i) == errno_names[i]", got "(null) != EINIT"
```

Follow-up for 03ccee19396ae604d9ac1570dddb8b41ec0e7253.

src/basic/errno-list.c

index 8de9888083980ea04ab952a20da0135d3da1d760..1cad1f6a5d00f2911d1607a78261e9bed2dc5a81 100644 (file)
@@ -10,6 +10,7 @@ static const struct errno_name* lookup_errno(register const char *str,
                                              register GPERF_LEN_TYPE len);
 
 #include "errno-from-name.inc"
+#include "errno-to-name.inc"
 
 int errno_from_name(const char *name) {
         const struct errno_name *sc;
@@ -24,26 +25,24 @@ int errno_from_name(const char *name) {
         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 HAVE_STRERRORNAME_NP
+        const char *n = strerrorname_np(id);
+        if (n)
+                return n;
+#endif
+
         if ((size_t) id >= ELEMENTSOF(errno_names))
                 return NULL;
 
         return errno_names[id];
 }
-#endif
 
 const char* errno_name_full(int id, char buf[static ERRNO_NAME_BUF_LEN]) {
         const char *a = errno_to_name(id);