From: Mike Yuan Date: Mon, 26 May 2025 18:19:59 +0000 (+0200) Subject: errno-list: errno_from_name() is pure but not const X-Git-Tag: v258-rc1~477^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a881f7f71c8ac705767db20baa56f7f8db721a0;p=thirdparty%2Fsystemd.git errno-list: errno_from_name() is pure but not const Follow-up for 0c15577abe013e07dba47d5aac126a63ab2dfd33 --- diff --git a/src/basic/errno-list.c b/src/basic/errno-list.c index b39e15a7680..5bfd8aa076a 100644 --- a/src/basic/errno-list.c +++ b/src/basic/errno-list.c @@ -9,6 +9,19 @@ static const struct errno_name* lookup_errno(register const char *str, #include "errno-from-name.inc" +int errno_from_name(const char *name) { + const struct errno_name *sc; + + assert(name); + + sc = lookup_errno(name, strlen(name)); + if (!sc) + return -EINVAL; + + 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 */ @@ -17,7 +30,7 @@ const char* errno_to_name(int id) { return strerrorname_np(ABS(id)); } #else -#include "errno-to-name.inc" +# include "errno-to-name.inc" const char* errno_to_name(int id) { @@ -30,16 +43,3 @@ const char* errno_to_name(int id) { return errno_names[id]; } #endif - -int errno_from_name(const char *name) { - const struct errno_name *sc; - - assert(name); - - sc = lookup_errno(name, strlen(name)); - if (!sc) - return -EINVAL; - - assert(sc->id > 0); - return sc->id; -} diff --git a/src/basic/errno-list.h b/src/basic/errno-list.h index ce9516068d0..9040211b17f 100644 --- a/src/basic/errno-list.h +++ b/src/basic/errno-list.h @@ -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; diff --git a/src/basic/errno-util.h b/src/basic/errno-util.h index fa53744f614..ea54378d789 100644 --- a/src/basic/errno-util.h +++ b/src/basic/errno-util.h @@ -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; }