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
// This file is generated automatically. Do not modify it by hand.

// For code generated by `phf_codegen`.
#![cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]

use std;

use phf;

use ErrnoCode;
use ErrnoCodes;

/// Return structure describing error number.
///
/// Returns None on unknown errnum.
///
/// Returns only the first structure if there are multiple error
/// identifiers/messages defined for the same numeric constant.
pub fn info_by_num(errnum: std::os::raw::c_int) -> Option<&'static ErrnoCode> {
    BY_NUM.get(&errnum).map(|infos| &infos[0])
}

/// Return structure describing error identifier.
///
/// Returns None on unknown err_id.
pub fn info_by_id(err_id: &str) -> Option<&'static ErrnoCode> {
    BY_ID.get(err_id)
}

/// Return string describing error number.
///
/// Returns None on unknown errnum.
///
/// Returns only the first message if there are multiple error messages defined
/// for the same numeric constant.
pub fn strerror(errnum: std::os::raw::c_int) -> Option<&'static str> {
    info_by_num(errnum).map(|info| info.msg)
}

/// Operation not permitted.
pub const EPERM: std::os::raw::c_int = 1;
/// Human-readable message for EPERM.
pub const EPERM_MSG: &str = "Operation not permitted";
/// Identifier for EPERM as a string (equals to "EPERM").
pub const EPERM_ID: &str = "EPERM";

/// No such file or directory.
pub const ENOFILE: std::os::raw::c_int = 2;
/// Human-readable message for ENOFILE.
pub const ENOFILE_MSG: &str = "No such file or directory";
/// Identifier for ENOFILE as a string (equals to "ENOFILE").
pub const ENOFILE_ID: &str = "ENOFILE";

/// Same as ENOFILE (No such file or directory).
pub const ENOENT: std::os::raw::c_int = 2;
/// Human-readable message for ENOENT.
pub const ENOENT_MSG: &str = "Same as ENOFILE (No such file or directory)";
/// Identifier for ENOENT as a string (equals to "ENOENT").
pub const ENOENT_ID: &str = "ENOENT";

/// No such process.
pub const ESRCH: std::os::raw::c_int = 3;
/// Human-readable message for ESRCH.
pub const ESRCH_MSG: &str = "No such process";
/// Identifier for ESRCH as a string (equals to "ESRCH").
pub const ESRCH_ID: &str = "ESRCH";

/// Interrupted function call.
pub const EINTR: std::os::raw::c_int = 4;
/// Human-readable message for EINTR.
pub const EINTR_MSG: &str = "Interrupted function call";
/// Identifier for EINTR as a string (equals to "EINTR").
pub const EINTR_ID: &str = "EINTR";

/// Input/output error.
pub const EIO: std::os::raw::c_int = 5;
/// Human-readable message for EIO.
pub const EIO_MSG: &str = "Input/output error";
/// Identifier for EIO as a string (equals to "EIO").
pub const EIO_ID: &str = "EIO";

/// No such device or address.
pub const ENXIO: std::os::raw::c_int = 6;
/// Human-readable message for ENXIO.
pub const ENXIO_MSG: &str = "No such device or address";
/// Identifier for ENXIO as a string (equals to "ENXIO").
pub const ENXIO_ID: &str = "ENXIO";

/// Arg list too long.
pub const E2BIG: std::os::raw::c_int = 7;
/// Human-readable message for E2BIG.
pub const E2BIG_MSG: &str = "Arg list too long";
/// Identifier for E2BIG as a string (equals to "E2BIG").
pub const E2BIG_ID: &str = "E2BIG";

/// Exec format error.
pub const ENOEXEC: std::os::raw::c_int = 8;
/// Human-readable message for ENOEXEC.
pub const ENOEXEC_MSG: &str = "Exec format error";
/// Identifier for ENOEXEC as a string (equals to "ENOEXEC").
pub const ENOEXEC_ID: &str = "ENOEXEC";

/// Bad file descriptor.
pub const EBADF: std::os::raw::c_int = 9;
/// Human-readable message for EBADF.
pub const EBADF_MSG: &str = "Bad file descriptor";
/// Identifier for EBADF as a string (equals to "EBADF").
pub const EBADF_ID: &str = "EBADF";

/// No child processes.
pub const ECHILD: std::os::raw::c_int = 10;
/// Human-readable message for ECHILD.
pub const ECHILD_MSG: &str = "No child processes";
/// Identifier for ECHILD as a string (equals to "ECHILD").
pub const ECHILD_ID: &str = "ECHILD";

/// Resource temporarily unavailable.
pub const EAGAIN: std::os::raw::c_int = 11;
/// Human-readable message for EAGAIN.
pub const EAGAIN_MSG: &str = "Resource temporarily unavailable";
/// Identifier for EAGAIN as a string (equals to "EAGAIN").
pub const EAGAIN_ID: &str = "EAGAIN";

/// Not enough space.
pub const ENOMEM: std::os::raw::c_int = 12;
/// Human-readable message for ENOMEM.
pub const ENOMEM_MSG: &str = "Not enough space";
/// Identifier for ENOMEM as a string (equals to "ENOMEM").
pub const ENOMEM_ID: &str = "ENOMEM";

/// Permission denied.
pub const EACCES: std::os::raw::c_int = 13;
/// Human-readable message for EACCES.
pub const EACCES_MSG: &str = "Permission denied";
/// Identifier for EACCES as a string (equals to "EACCES").
pub const EACCES_ID: &str = "EACCES";

/// Bad address.
pub const EFAULT: std::os::raw::c_int = 14;
/// Human-readable message for EFAULT.
pub const EFAULT_MSG: &str = "Bad address";
/// Identifier for EFAULT as a string (equals to "EFAULT").
pub const EFAULT_ID: &str = "EFAULT";

/// strerror reports \"Resource device\".
pub const EBUSY: std::os::raw::c_int = 16;
/// Human-readable message for EBUSY.
pub const EBUSY_MSG: &str = "strerror reports \"Resource device\"";
/// Identifier for EBUSY as a string (equals to "EBUSY").
pub const EBUSY_ID: &str = "EBUSY";

/// File exists.
pub const EEXIST: std::os::raw::c_int = 17;
/// Human-readable message for EEXIST.
pub const EEXIST_MSG: &str = "File exists";
/// Identifier for EEXIST as a string (equals to "EEXIST").
pub const EEXIST_ID: &str = "EEXIST";

/// Improper link (cross-device link?).
pub const EXDEV: std::os::raw::c_int = 18;
/// Human-readable message for EXDEV.
pub const EXDEV_MSG: &str = "Improper link (cross-device link?)";
/// Identifier for EXDEV as a string (equals to "EXDEV").
pub const EXDEV_ID: &str = "EXDEV";

/// No such device.
pub const ENODEV: std::os::raw::c_int = 19;
/// Human-readable message for ENODEV.
pub const ENODEV_MSG: &str = "No such device";
/// Identifier for ENODEV as a string (equals to "ENODEV").
pub const ENODEV_ID: &str = "ENODEV";

/// Not a directory.
pub const ENOTDIR: std::os::raw::c_int = 20;
/// Human-readable message for ENOTDIR.
pub const ENOTDIR_MSG: &str = "Not a directory";
/// Identifier for ENOTDIR as a string (equals to "ENOTDIR").
pub const ENOTDIR_ID: &str = "ENOTDIR";

/// Is a directory.
pub const EISDIR: std::os::raw::c_int = 21;
/// Human-readable message for EISDIR.
pub const EISDIR_MSG: &str = "Is a directory";
/// Identifier for EISDIR as a string (equals to "EISDIR").
pub const EISDIR_ID: &str = "EISDIR";

/// Invalid argument.
pub const EINVAL: std::os::raw::c_int = 22;
/// Human-readable message for EINVAL.
pub const EINVAL_MSG: &str = "Invalid argument";
/// Identifier for EINVAL as a string (equals to "EINVAL").
pub const EINVAL_ID: &str = "EINVAL";

/// Too many open files in system.
pub const ENFILE: std::os::raw::c_int = 23;
/// Human-readable message for ENFILE.
pub const ENFILE_MSG: &str = "Too many open files in system";
/// Identifier for ENFILE as a string (equals to "ENFILE").
pub const ENFILE_ID: &str = "ENFILE";

/// Too many open files.
pub const EMFILE: std::os::raw::c_int = 24;
/// Human-readable message for EMFILE.
pub const EMFILE_MSG: &str = "Too many open files";
/// Identifier for EMFILE as a string (equals to "EMFILE").
pub const EMFILE_ID: &str = "EMFILE";

/// Inappropriate I/O control operation.
pub const ENOTTY: std::os::raw::c_int = 25;
/// Human-readable message for ENOTTY.
pub const ENOTTY_MSG: &str = "Inappropriate I/O control operation";
/// Identifier for ENOTTY as a string (equals to "ENOTTY").
pub const ENOTTY_ID: &str = "ENOTTY";

/// File too large.
pub const EFBIG: std::os::raw::c_int = 27;
/// Human-readable message for EFBIG.
pub const EFBIG_MSG: &str = "File too large";
/// Identifier for EFBIG as a string (equals to "EFBIG").
pub const EFBIG_ID: &str = "EFBIG";

/// No space left on device.
pub const ENOSPC: std::os::raw::c_int = 28;
/// Human-readable message for ENOSPC.
pub const ENOSPC_MSG: &str = "No space left on device";
/// Identifier for ENOSPC as a string (equals to "ENOSPC").
pub const ENOSPC_ID: &str = "ENOSPC";

/// Invalid seek (seek on a pipe?).
pub const ESPIPE: std::os::raw::c_int = 29;
/// Human-readable message for ESPIPE.
pub const ESPIPE_MSG: &str = "Invalid seek (seek on a pipe?)";
/// Identifier for ESPIPE as a string (equals to "ESPIPE").
pub const ESPIPE_ID: &str = "ESPIPE";

/// Read-only file system.
pub const EROFS: std::os::raw::c_int = 30;
/// Human-readable message for EROFS.
pub const EROFS_MSG: &str = "Read-only file system";
/// Identifier for EROFS as a string (equals to "EROFS").
pub const EROFS_ID: &str = "EROFS";

/// Too many links.
pub const EMLINK: std::os::raw::c_int = 31;
/// Human-readable message for EMLINK.
pub const EMLINK_MSG: &str = "Too many links";
/// Identifier for EMLINK as a string (equals to "EMLINK").
pub const EMLINK_ID: &str = "EMLINK";

/// Broken pipe.
pub const EPIPE: std::os::raw::c_int = 32;
/// Human-readable message for EPIPE.
pub const EPIPE_MSG: &str = "Broken pipe";
/// Identifier for EPIPE as a string (equals to "EPIPE").
pub const EPIPE_ID: &str = "EPIPE";

/// Domain error (math functions).
pub const EDOM: std::os::raw::c_int = 33;
/// Human-readable message for EDOM.
pub const EDOM_MSG: &str = "Domain error (math functions)";
/// Identifier for EDOM as a string (equals to "EDOM").
pub const EDOM_ID: &str = "EDOM";

/// Result too large (possibly too small).
pub const ERANGE: std::os::raw::c_int = 34;
/// Human-readable message for ERANGE.
pub const ERANGE_MSG: &str = "Result too large (possibly too small)";
/// Identifier for ERANGE as a string (equals to "ERANGE").
pub const ERANGE_ID: &str = "ERANGE";

/// Resource deadlock avoided (non-Cyg).
pub const EDEADLOCK: std::os::raw::c_int = 36;
/// Human-readable message for EDEADLOCK.
pub const EDEADLOCK_MSG: &str = "Resource deadlock avoided (non-Cyg)";
/// Identifier for EDEADLOCK as a string (equals to "EDEADLOCK").
pub const EDEADLOCK_ID: &str = "EDEADLOCK";

/// Same as EDEADLOCK (Resource deadlock avoided (non-Cyg)).
pub const EDEADLK: std::os::raw::c_int = 36;
/// Human-readable message for EDEADLK.
pub const EDEADLK_MSG: &str = "Same as EDEADLOCK (Resource deadlock avoided (non-Cyg))";
/// Identifier for EDEADLK as a string (equals to "EDEADLK").
pub const EDEADLK_ID: &str = "EDEADLK";

/// Filename too long (91 in Cyg?).
pub const ENAMETOOLONG: std::os::raw::c_int = 38;
/// Human-readable message for ENAMETOOLONG.
pub const ENAMETOOLONG_MSG: &str = "Filename too long (91 in Cyg?)";
/// Identifier for ENAMETOOLONG as a string (equals to "ENAMETOOLONG").
pub const ENAMETOOLONG_ID: &str = "ENAMETOOLONG";

/// No locks available (46 in Cyg?).
pub const ENOLCK: std::os::raw::c_int = 39;
/// Human-readable message for ENOLCK.
pub const ENOLCK_MSG: &str = "No locks available (46 in Cyg?)";
/// Identifier for ENOLCK as a string (equals to "ENOLCK").
pub const ENOLCK_ID: &str = "ENOLCK";

/// Function not implemented (88 in Cyg?).
pub const ENOSYS: std::os::raw::c_int = 40;
/// Human-readable message for ENOSYS.
pub const ENOSYS_MSG: &str = "Function not implemented (88 in Cyg?)";
/// Identifier for ENOSYS as a string (equals to "ENOSYS").
pub const ENOSYS_ID: &str = "ENOSYS";

/// Directory not empty (90 in Cyg?).
pub const ENOTEMPTY: std::os::raw::c_int = 41;
/// Human-readable message for ENOTEMPTY.
pub const ENOTEMPTY_MSG: &str = "Directory not empty (90 in Cyg?)";
/// Identifier for ENOTEMPTY as a string (equals to "ENOTEMPTY").
pub const ENOTEMPTY_ID: &str = "ENOTEMPTY";

/// Illegal byte sequence.
pub const EILSEQ: std::os::raw::c_int = 42;
/// Human-readable message for EILSEQ.
pub const EILSEQ_MSG: &str = "Illegal byte sequence";
/// Identifier for EILSEQ as a string (equals to "EILSEQ").
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);
    }
}