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[] = {
143 #ifdef EREMOTERELEASE
169 E(ECANCELED), /* ECANCELLED */
170 E(EAGAIN), /* EWOULDBLOCK */
171 E(ECONNREFUSED), /* EREFUSED */
172 E(EDEADLK), /* EDEADLOCK */
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;