1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#![cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]
use std;
use phf;
use ErrnoCode;
use ErrnoCodes;
pub fn info_by_num(errnum: std::os::raw::c_int) -> Option<&'static ErrnoCode> {
BY_NUM.get(&errnum).map(|infos| &infos[0])
}
pub fn info_by_id(err_id: &str) -> Option<&'static ErrnoCode> {
BY_ID.get(err_id)
}
pub fn strerror(errnum: std::os::raw::c_int) -> Option<&'static str> {
info_by_num(errnum).map(|info| info.msg)
}
pub const EPERM: std::os::raw::c_int = 1;
pub const EPERM_MSG: &str = "Operation not permitted";
pub const EPERM_ID: &str = "EPERM";
pub const ENOFILE: std::os::raw::c_int = 2;
pub const ENOFILE_MSG: &str = "No such file or directory";
pub const ENOFILE_ID: &str = "ENOFILE";
pub const ENOENT: std::os::raw::c_int = 2;
pub const ENOENT_MSG: &str = "Same as ENOFILE (No such file or directory)";
pub const ENOENT_ID: &str = "ENOENT";
pub const ESRCH: std::os::raw::c_int = 3;
pub const ESRCH_MSG: &str = "No such process";
pub const ESRCH_ID: &str = "ESRCH";
pub const EINTR: std::os::raw::c_int = 4;
pub const EINTR_MSG: &str = "Interrupted function call";
pub const EINTR_ID: &str = "EINTR";
pub const EIO: std::os::raw::c_int = 5;
pub const EIO_MSG: &str = "Input/output error";
pub const EIO_ID: &str = "EIO";
pub const ENXIO: std::os::raw::c_int = 6;
pub const ENXIO_MSG: &str = "No such device or address";
pub const ENXIO_ID: &str = "ENXIO";
pub const E2BIG: std::os::raw::c_int = 7;
pub const E2BIG_MSG: &str = "Arg list too long";
pub const E2BIG_ID: &str = "E2BIG";
pub const ENOEXEC: std::os::raw::c_int = 8;
pub const ENOEXEC_MSG: &str = "Exec format error";
pub const ENOEXEC_ID: &str = "ENOEXEC";
pub const EBADF: std::os::raw::c_int = 9;
pub const EBADF_MSG: &str = "Bad file descriptor";
pub const EBADF_ID: &str = "EBADF";
pub const ECHILD: std::os::raw::c_int = 10;
pub const ECHILD_MSG: &str = "No child processes";
pub const ECHILD_ID: &str = "ECHILD";
pub const EAGAIN: std::os::raw::c_int = 11;
pub const EAGAIN_MSG: &str = "Resource temporarily unavailable";
pub const EAGAIN_ID: &str = "EAGAIN";
pub const ENOMEM: std::os::raw::c_int = 12;
pub const ENOMEM_MSG: &str = "Not enough space";
pub const ENOMEM_ID: &str = "ENOMEM";
pub const EACCES: std::os::raw::c_int = 13;
pub const EACCES_MSG: &str = "Permission denied";
pub const EACCES_ID: &str = "EACCES";
pub const EFAULT: std::os::raw::c_int = 14;
pub const EFAULT_MSG: &str = "Bad address";
pub const EFAULT_ID: &str = "EFAULT";
pub const EBUSY: std::os::raw::c_int = 16;
pub const EBUSY_MSG: &str = "strerror reports \"Resource device\"";
pub const EBUSY_ID: &str = "EBUSY";
pub const EEXIST: std::os::raw::c_int = 17;
pub const EEXIST_MSG: &str = "File exists";
pub const EEXIST_ID: &str = "EEXIST";
pub const EXDEV: std::os::raw::c_int = 18;
pub const EXDEV_MSG: &str = "Improper link (cross-device link?)";
pub const EXDEV_ID: &str = "EXDEV";
pub const ENODEV: std::os::raw::c_int = 19;
pub const ENODEV_MSG: &str = "No such device";
pub const ENODEV_ID: &str = "ENODEV";
pub const ENOTDIR: std::os::raw::c_int = 20;
pub const ENOTDIR_MSG: &str = "Not a directory";
pub const ENOTDIR_ID: &str = "ENOTDIR";
pub const EISDIR: std::os::raw::c_int = 21;
pub const EISDIR_MSG: &str = "Is a directory";
pub const EISDIR_ID: &str = "EISDIR";
pub const EINVAL: std::os::raw::c_int = 22;
pub const EINVAL_MSG: &str = "Invalid argument";
pub const EINVAL_ID: &str = "EINVAL";
pub const ENFILE: std::os::raw::c_int = 23;
pub const ENFILE_MSG: &str = "Too many open files in system";
pub const ENFILE_ID: &str = "ENFILE";
pub const EMFILE: std::os::raw::c_int = 24;
pub const EMFILE_MSG: &str = "Too many open files";
pub const EMFILE_ID: &str = "EMFILE";
pub const ENOTTY: std::os::raw::c_int = 25;
pub const ENOTTY_MSG: &str = "Inappropriate I/O control operation";
pub const ENOTTY_ID: &str = "ENOTTY";
pub const EFBIG: std::os::raw::c_int = 27;
pub const EFBIG_MSG: &str = "File too large";
pub const EFBIG_ID: &str = "EFBIG";
pub const ENOSPC: std::os::raw::c_int = 28;
pub const ENOSPC_MSG: &str = "No space left on device";
pub const ENOSPC_ID: &str = "ENOSPC";
pub const ESPIPE: std::os::raw::c_int = 29;
pub const ESPIPE_MSG: &str = "Invalid seek (seek on a pipe?)";
pub const ESPIPE_ID: &str = "ESPIPE";
pub const EROFS: std::os::raw::c_int = 30;
pub const EROFS_MSG: &str = "Read-only file system";
pub const EROFS_ID: &str = "EROFS";
pub const EMLINK: std::os::raw::c_int = 31;
pub const EMLINK_MSG: &str = "Too many links";
pub const EMLINK_ID: &str = "EMLINK";
pub const EPIPE: std::os::raw::c_int = 32;
pub const EPIPE_MSG: &str = "Broken pipe";
pub const EPIPE_ID: &str = "EPIPE";
pub const EDOM: std::os::raw::c_int = 33;
pub const EDOM_MSG: &str = "Domain error (math functions)";
pub const EDOM_ID: &str = "EDOM";
pub const ERANGE: std::os::raw::c_int = 34;
pub const ERANGE_MSG: &str = "Result too large (possibly too small)";
pub const ERANGE_ID: &str = "ERANGE";
pub const EDEADLOCK: std::os::raw::c_int = 36;
pub const EDEADLOCK_MSG: &str = "Resource deadlock avoided (non-Cyg)";
pub const EDEADLOCK_ID: &str = "EDEADLOCK";
pub const EDEADLK: std::os::raw::c_int = 36;
pub const EDEADLK_MSG: &str = "Same as EDEADLOCK (Resource deadlock avoided (non-Cyg))";
pub const EDEADLK_ID: &str = "EDEADLK";
pub const ENAMETOOLONG: std::os::raw::c_int = 38;
pub const ENAMETOOLONG_MSG: &str = "Filename too long (91 in Cyg?)";
pub const ENAMETOOLONG_ID: &str = "ENAMETOOLONG";
pub const ENOLCK: std::os::raw::c_int = 39;
pub const ENOLCK_MSG: &str = "No locks available (46 in Cyg?)";
pub const ENOLCK_ID: &str = "ENOLCK";
pub const ENOSYS: std::os::raw::c_int = 40;
pub const ENOSYS_MSG: &str = "Function not implemented (88 in Cyg?)";
pub const ENOSYS_ID: &str = "ENOSYS";
pub const ENOTEMPTY: std::os::raw::c_int = 41;
pub const ENOTEMPTY_MSG: &str = "Directory not empty (90 in Cyg?)";
pub const ENOTEMPTY_ID: &str = "ENOTEMPTY";
pub const EILSEQ: std::os::raw::c_int = 42;
pub const EILSEQ_MSG: &str = "Illegal byte sequence";
pub const EILSEQ_ID: &str = "EILSEQ";
include!(concat!(env!("OUT_DIR"), "/windows.rs"));
#[cfg(test)]
mod tests {
use ErrnoCode;
#[test]
fn info_by_num() {
assert_eq!(
super::info_by_num(super::EDOM),
Some(&ErrnoCode {
num: super::EDOM,
msg: super::EDOM_MSG,
id: super::EDOM_ID,
})
);
}
#[test]
fn info_by_id() {
assert_eq!(
super::info_by_id(super::EDOM_ID),
Some(&ErrnoCode {
num: super::EDOM,
msg: super::EDOM_MSG,
id: super::EDOM_ID,
})
);
}
#[test]
fn strerror() {
assert_eq!(super::strerror(super::EDOM), Some(super::EDOM_MSG));
assert_eq!(super::strerror(0), None);
}
}