#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 */
return strerrorname_np(ABS(id));
}
#else
-#include "errno-to-name.inc"
+# include "errno-to-name.inc"
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;
-}
#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;
* 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;
}