diff options
Diffstat (limited to 'src/lib/errno.c')
-rw-r--r-- | src/lib/errno.c | 206 |
1 files changed, 206 insertions, 0 deletions
diff --git a/src/lib/errno.c b/src/lib/errno.c new file mode 100644 index 000000000..d38c197ad --- /dev/null +++ b/src/lib/errno.c | |||
@@ -0,0 +1,206 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014-2020 Firejail Authors | ||
3 | * | ||
4 | * This file is part of firejail project | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License along | ||
17 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
19 | */ | ||
20 | #include "../include/syscall.h" | ||
21 | |||
22 | #include <errno.h> | ||
23 | #include <stdio.h> | ||
24 | #include <string.h> | ||
25 | //#include <attr/xattr.h> | ||
26 | |||
27 | typedef struct { | ||
28 | char *name; | ||
29 | int nr; | ||
30 | } ErrnoEntry; | ||
31 | |||
32 | static ErrnoEntry errnolist[] = { | ||
33 | // | ||
34 | // code generated using tools/extract-errnos | ||
35 | // | ||
36 | {"EPERM", EPERM}, | ||
37 | {"ENOENT", ENOENT}, | ||
38 | {"ESRCH", ESRCH}, | ||
39 | {"EINTR", EINTR}, | ||
40 | {"EIO", EIO}, | ||
41 | {"ENXIO", ENXIO}, | ||
42 | {"E2BIG", E2BIG}, | ||
43 | {"ENOEXEC", ENOEXEC}, | ||
44 | {"EBADF", EBADF}, | ||
45 | {"ECHILD", ECHILD}, | ||
46 | {"EAGAIN", EAGAIN}, | ||
47 | {"ENOMEM", ENOMEM}, | ||
48 | {"EACCES", EACCES}, | ||
49 | {"EFAULT", EFAULT}, | ||
50 | {"ENOTBLK", ENOTBLK}, | ||
51 | {"EBUSY", EBUSY}, | ||
52 | {"EEXIST", EEXIST}, | ||
53 | {"EXDEV", EXDEV}, | ||
54 | {"ENODEV", ENODEV}, | ||
55 | {"ENOTDIR", ENOTDIR}, | ||
56 | {"EISDIR", EISDIR}, | ||
57 | {"EINVAL", EINVAL}, | ||
58 | {"ENFILE", ENFILE}, | ||
59 | {"EMFILE", EMFILE}, | ||
60 | {"ENOTTY", ENOTTY}, | ||
61 | {"ETXTBSY", ETXTBSY}, | ||
62 | {"EFBIG", EFBIG}, | ||
63 | {"ENOSPC", ENOSPC}, | ||
64 | {"ESPIPE", ESPIPE}, | ||
65 | {"EROFS", EROFS}, | ||
66 | {"EMLINK", EMLINK}, | ||
67 | {"EPIPE", EPIPE}, | ||
68 | {"EDOM", EDOM}, | ||
69 | {"ERANGE", ERANGE}, | ||
70 | {"EDEADLK", EDEADLK}, | ||
71 | {"ENAMETOOLONG", ENAMETOOLONG}, | ||
72 | {"ENOLCK", ENOLCK}, | ||
73 | {"ENOSYS", ENOSYS}, | ||
74 | {"ENOTEMPTY", ENOTEMPTY}, | ||
75 | {"ELOOP", ELOOP}, | ||
76 | {"EWOULDBLOCK", EWOULDBLOCK}, | ||
77 | {"ENOMSG", ENOMSG}, | ||
78 | {"EIDRM", EIDRM}, | ||
79 | {"ECHRNG", ECHRNG}, | ||
80 | {"EL2NSYNC", EL2NSYNC}, | ||
81 | {"EL3HLT", EL3HLT}, | ||
82 | {"EL3RST", EL3RST}, | ||
83 | {"ELNRNG", ELNRNG}, | ||
84 | {"EUNATCH", EUNATCH}, | ||
85 | {"ENOCSI", ENOCSI}, | ||
86 | {"EL2HLT", EL2HLT}, | ||
87 | {"EBADE", EBADE}, | ||
88 | {"EBADR", EBADR}, | ||
89 | {"EXFULL", EXFULL}, | ||
90 | {"ENOANO", ENOANO}, | ||
91 | {"EBADRQC", EBADRQC}, | ||
92 | {"EBADSLT", EBADSLT}, | ||
93 | {"EDEADLOCK", EDEADLOCK}, | ||
94 | {"EBFONT", EBFONT}, | ||
95 | {"ENOSTR", ENOSTR}, | ||
96 | {"ENODATA", ENODATA}, | ||
97 | {"ETIME", ETIME}, | ||
98 | {"ENOSR", ENOSR}, | ||
99 | {"ENONET", ENONET}, | ||
100 | {"ENOPKG", ENOPKG}, | ||
101 | {"EREMOTE", EREMOTE}, | ||
102 | {"ENOLINK", ENOLINK}, | ||
103 | {"EADV", EADV}, | ||
104 | {"ESRMNT", ESRMNT}, | ||
105 | {"ECOMM", ECOMM}, | ||
106 | {"EPROTO", EPROTO}, | ||
107 | {"EMULTIHOP", EMULTIHOP}, | ||
108 | {"EDOTDOT", EDOTDOT}, | ||
109 | {"EBADMSG", EBADMSG}, | ||
110 | {"EOVERFLOW", EOVERFLOW}, | ||
111 | {"ENOTUNIQ", ENOTUNIQ}, | ||
112 | {"EBADFD", EBADFD}, | ||
113 | {"EREMCHG", EREMCHG}, | ||
114 | {"ELIBACC", ELIBACC}, | ||
115 | {"ELIBBAD", ELIBBAD}, | ||
116 | {"ELIBSCN", ELIBSCN}, | ||
117 | {"ELIBMAX", ELIBMAX}, | ||
118 | {"ELIBEXEC", ELIBEXEC}, | ||
119 | {"EILSEQ", EILSEQ}, | ||
120 | {"ERESTART", ERESTART}, | ||
121 | {"ESTRPIPE", ESTRPIPE}, | ||
122 | {"EUSERS", EUSERS}, | ||
123 | {"ENOTSOCK", ENOTSOCK}, | ||
124 | {"EDESTADDRREQ", EDESTADDRREQ}, | ||
125 | {"EMSGSIZE", EMSGSIZE}, | ||
126 | {"EPROTOTYPE", EPROTOTYPE}, | ||
127 | {"ENOPROTOOPT", ENOPROTOOPT}, | ||
128 | {"EPROTONOSUPPORT", EPROTONOSUPPORT}, | ||
129 | {"ESOCKTNOSUPPORT", ESOCKTNOSUPPORT}, | ||
130 | {"EOPNOTSUPP", EOPNOTSUPP}, | ||
131 | {"EPFNOSUPPORT", EPFNOSUPPORT}, | ||
132 | {"EAFNOSUPPORT", EAFNOSUPPORT}, | ||
133 | {"EADDRINUSE", EADDRINUSE}, | ||
134 | {"EADDRNOTAVAIL", EADDRNOTAVAIL}, | ||
135 | {"ENETDOWN", ENETDOWN}, | ||
136 | {"ENETUNREACH", ENETUNREACH}, | ||
137 | {"ENETRESET", ENETRESET}, | ||
138 | {"ECONNABORTED", ECONNABORTED}, | ||
139 | {"ECONNRESET", ECONNRESET}, | ||
140 | {"ENOBUFS", ENOBUFS}, | ||
141 | {"EISCONN", EISCONN}, | ||
142 | {"ENOTCONN", ENOTCONN}, | ||
143 | {"ESHUTDOWN", ESHUTDOWN}, | ||
144 | {"ETOOMANYREFS", ETOOMANYREFS}, | ||
145 | {"ETIMEDOUT", ETIMEDOUT}, | ||
146 | {"ECONNREFUSED", ECONNREFUSED}, | ||
147 | {"EHOSTDOWN", EHOSTDOWN}, | ||
148 | {"EHOSTUNREACH", EHOSTUNREACH}, | ||
149 | {"EALREADY", EALREADY}, | ||
150 | {"EINPROGRESS", EINPROGRESS}, | ||
151 | {"ESTALE", ESTALE}, | ||
152 | {"EUCLEAN", EUCLEAN}, | ||
153 | {"ENOTNAM", ENOTNAM}, | ||
154 | {"ENAVAIL", ENAVAIL}, | ||
155 | {"EISNAM", EISNAM}, | ||
156 | {"EREMOTEIO", EREMOTEIO}, | ||
157 | {"EDQUOT", EDQUOT}, | ||
158 | {"ENOMEDIUM", ENOMEDIUM}, | ||
159 | {"EMEDIUMTYPE", EMEDIUMTYPE}, | ||
160 | {"ECANCELED", ECANCELED}, | ||
161 | {"ENOKEY", ENOKEY}, | ||
162 | {"EKEYEXPIRED", EKEYEXPIRED}, | ||
163 | {"EKEYREVOKED", EKEYREVOKED}, | ||
164 | {"EKEYREJECTED", EKEYREJECTED}, | ||
165 | {"EOWNERDEAD", EOWNERDEAD}, | ||
166 | {"ENOTRECOVERABLE", ENOTRECOVERABLE}, | ||
167 | {"ERFKILL", ERFKILL}, | ||
168 | {"EHWPOISON", EHWPOISON}, | ||
169 | {"ENOTSUP", ENOTSUP}, | ||
170 | #ifdef ENOATTR | ||
171 | {"ENOATTR", ENOATTR}, | ||
172 | #endif | ||
173 | }; | ||
174 | |||
175 | int errno_find_name(const char *name) { | ||
176 | int i; | ||
177 | int elems = sizeof(errnolist) / sizeof(errnolist[0]); | ||
178 | for (i = 0; i < elems; i++) { | ||
179 | if (strcasecmp(name, errnolist[i].name) == 0) | ||
180 | return errnolist[i].nr; | ||
181 | } | ||
182 | |||
183 | return -1; | ||
184 | } | ||
185 | |||
186 | char *errno_find_nr(int nr) { | ||
187 | int i; | ||
188 | int elems = sizeof(errnolist) / sizeof(errnolist[0]); | ||
189 | for (i = 0; i < elems; i++) { | ||
190 | if (nr == errnolist[i].nr) | ||
191 | return errnolist[i].name; | ||
192 | } | ||
193 | |||
194 | return "unknown"; | ||
195 | } | ||
196 | |||
197 | |||
198 | |||
199 | void errno_print(void) { | ||
200 | int i; | ||
201 | int elems = sizeof(errnolist) / sizeof(errnolist[0]); | ||
202 | for (i = 0; i < elems; i++) { | ||
203 | printf("%d\t- %s\n", errnolist[i].nr, errnolist[i].name); | ||
204 | } | ||
205 | printf("\n"); | ||
206 | } | ||