1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/build_bug.h>
3 #include <linux/errno.h>
4 #include <linux/errname.h>
5 #include <linux/kernel.h>
8 * Ensure these tables do not accidentally become gigantic if some
9 * huge errno makes it in. On most architectures, the first table will
10 * only have about 140 entries, but mips and parisc have more sparsely
11 * allocated errnos (with EHWPOISON = 257 on parisc, and EDQUOT = 1133
12 * on mips), so this wastes a bit of space on those - though we
13 * special case the EDQUOT case.
15 #define E(err) [err + BUILD_BUG_ON_ZERO(err <= 0 || err > 300)] = "-" #err
16 static const char *names_0[] = {
23 E(EAGAIN), /* EWOULDBLOCK */
34 E(ECANCELED), /* ECANCELLED */
39 E(ECONNREFUSED), /* EREFUSED */
41 E(EDEADLK), /* EDEADLOCK */
42 #if EDEADLK != EDEADLOCK /* mips, sparc, powerpc */
168 #ifdef EREFUSED /* parisc */
169 static_assert(EREFUSED == ECONNREFUSED);
171 #ifdef ECANCELLED /* parisc */
172 static_assert(ECANCELLED == ECANCELED);
174 static_assert(EAGAIN == EWOULDBLOCK); /* everywhere */
176 #define E(err) [err - 512 + BUILD_BUG_ON_ZERO(err < 512 || err > 550)] = "-" #err
177 static const char *names_512[] = {
182 E(ERESTART_RESTARTBLOCK),
200 static const char *__errname(unsigned err)
202 if (err < ARRAY_SIZE(names_0))
204 if (err >= 512 && err - 512 < ARRAY_SIZE(names_512))
205 return names_512[err - 512];
207 if (IS_ENABLED(CONFIG_MIPS) && err == EDQUOT) /* 1133 */
213 * errname(EIO) -> "EIO"
214 * errname(-EIO) -> "-EIO"
216 const char *errname(int err)
218 const char *name = __errname(abs(err));
222 return err > 0 ? name + 1 : name;