@@ -12,6 +12,18 @@ use core::fmt;
12
12
use core:: num:: TryFromIntError ;
13
13
use core:: str:: { self , Utf8Error } ;
14
14
15
+ macro_rules! declare_err {
16
+ ( $err: tt) => {
17
+ pub const $err: Self = Error ( -( bindings:: $err as i32 ) ) ;
18
+ } ;
19
+ ( $err: tt, $( $doc: expr) ,+) => {
20
+ $(
21
+ #[ doc = $doc]
22
+ ) *
23
+ pub const $err: Self = Error ( -( bindings:: $err as i32 ) ) ;
24
+ } ;
25
+ }
26
+
15
27
/// Generic integer kernel error.
16
28
///
17
29
/// The kernel defines a set of integer generic error codes based on C and
@@ -24,113 +36,81 @@ use core::str::{self, Utf8Error};
24
36
pub struct Error ( c_types:: c_int ) ;
25
37
26
38
impl Error {
27
- /// Operation not permitted.
28
- pub const EPERM : Self = Error ( -( bindings:: EPERM as i32 ) ) ;
39
+ declare_err ! ( EPERM , "Operation not permitted." ) ;
40
+
41
+ declare_err ! ( ENOENT , "No such file or directory." ) ;
42
+
43
+ declare_err ! ( ESRCH , "No such process." ) ;
29
44
30
- /// No such file or directory.
31
- pub const ENOENT : Self = Error ( -( bindings:: ENOENT as i32 ) ) ;
45
+ declare_err ! ( EINTR , "Interrupted system call." ) ;
32
46
33
- /// No such process.
34
- pub const ESRCH : Self = Error ( -( bindings:: ESRCH as i32 ) ) ;
47
+ declare_err ! ( EIO , "I/O error." ) ;
35
48
36
- /// Interrupted system call.
37
- pub const EINTR : Self = Error ( -( bindings:: EINTR as i32 ) ) ;
49
+ declare_err ! ( ENXIO , "No such device or address." ) ;
38
50
39
- /// I/O error.
40
- pub const EIO : Self = Error ( -( bindings:: EIO as i32 ) ) ;
51
+ declare_err ! ( E2BIG , "Argument list too long." ) ;
41
52
42
- /// No such device or address.
43
- pub const ENXIO : Self = Error ( -( bindings:: ENXIO as i32 ) ) ;
53
+ declare_err ! ( ENOEXEC , "Exec format error." ) ;
44
54
45
- /// Argument list too long.
46
- pub const E2BIG : Self = Error ( -( bindings:: E2BIG as i32 ) ) ;
55
+ declare_err ! ( EBADF , "Bad file number." ) ;
47
56
48
- /// Exec format error.
49
- pub const ENOEXEC : Self = Error ( -( bindings:: ENOEXEC as i32 ) ) ;
57
+ declare_err ! ( ECHILD , "Exec format error." ) ;
50
58
51
- /// Bad file number.
52
- pub const EBADF : Self = Error ( -( bindings:: EBADF as i32 ) ) ;
59
+ declare_err ! ( EAGAIN , "Try again." ) ;
53
60
54
- /// No child processes.
55
- pub const ECHILD : Self = Error ( -( bindings:: ECHILD as i32 ) ) ;
61
+ declare_err ! ( ENOMEM , "Out of memory." ) ;
56
62
57
- /// Try again.
58
- pub const EAGAIN : Self = Error ( -( bindings:: EAGAIN as i32 ) ) ;
63
+ declare_err ! ( EACCES , "Permission denied." ) ;
59
64
60
- /// Out of memory.
61
- pub const ENOMEM : Self = Error ( -( bindings:: ENOMEM as i32 ) ) ;
65
+ declare_err ! ( EFAULT , "Bad address." ) ;
62
66
63
- /// Permission denied.
64
- pub const EACCES : Self = Error ( -( bindings:: EACCES as i32 ) ) ;
67
+ declare_err ! ( ENOTBLK , "Block device required." ) ;
65
68
66
- /// Bad address.
67
- pub const EFAULT : Self = Error ( -( bindings:: EFAULT as i32 ) ) ;
69
+ declare_err ! ( EBUSY , "Device or resource busy." ) ;
68
70
69
- /// Block device required.
70
- pub const ENOTBLK : Self = Error ( -( bindings:: ENOTBLK as i32 ) ) ;
71
+ declare_err ! ( EEXIST , "File exists." ) ;
71
72
72
- /// Device or resource busy.
73
- pub const EBUSY : Self = Error ( -( bindings:: EBUSY as i32 ) ) ;
73
+ declare_err ! ( EXDEV , "Cross-device link." ) ;
74
74
75
- /// File exists.
76
- pub const EEXIST : Self = Error ( -( bindings:: EEXIST as i32 ) ) ;
75
+ declare_err ! ( ENODEV , "No such device." ) ;
77
76
78
- /// Cross-device link.
79
- pub const EXDEV : Self = Error ( -( bindings:: EXDEV as i32 ) ) ;
77
+ declare_err ! ( ENOTDIR , "Not a directory." ) ;
80
78
81
- /// No such device.
82
- pub const ENODEV : Self = Error ( -( bindings:: ENODEV as i32 ) ) ;
79
+ declare_err ! ( EISDIR , "Is a directory." ) ;
83
80
84
- /// Not a directory.
85
- pub const ENOTDIR : Self = Error ( -( bindings:: ENOTDIR as i32 ) ) ;
81
+ declare_err ! ( EINVAL , "Invalid argument." ) ;
86
82
87
- /// Is a directory.
88
- pub const EISDIR : Self = Error ( -( bindings:: EISDIR as i32 ) ) ;
83
+ declare_err ! ( ENFILE , "File table overflow." ) ;
89
84
90
- /// Invalid argument.
91
- pub const EINVAL : Self = Error ( -( bindings:: EINVAL as i32 ) ) ;
85
+ declare_err ! ( EMFILE , "Too many open files." ) ;
92
86
93
- /// File table overflow.
94
- pub const ENFILE : Self = Error ( -( bindings:: ENFILE as i32 ) ) ;
87
+ declare_err ! ( ENOTTY , "Not a typewriter." ) ;
95
88
96
- /// Too many open files.
97
- pub const EMFILE : Self = Error ( -( bindings:: EMFILE as i32 ) ) ;
89
+ declare_err ! ( ETXTBSY , "Text file busy." ) ;
98
90
99
- /// Not a typewriter.
100
- pub const ENOTTY : Self = Error ( -( bindings:: ENOTTY as i32 ) ) ;
91
+ declare_err ! ( EFBIG , "File too large." ) ;
101
92
102
- /// Text file busy.
103
- pub const ETXTBSY : Self = Error ( -( bindings:: ETXTBSY as i32 ) ) ;
93
+ declare_err ! ( ENOSPC , "No space left on device." ) ;
104
94
105
- /// File too large.
106
- pub const EFBIG : Self = Error ( -( bindings:: EFBIG as i32 ) ) ;
95
+ declare_err ! ( ESPIPE , "Illegal seek." ) ;
107
96
108
- /// No space left on device.
109
- pub const ENOSPC : Self = Error ( -( bindings:: ENOSPC as i32 ) ) ;
97
+ declare_err ! ( EROFS , "Read-only file system." ) ;
110
98
111
- /// Illegal seek.
112
- pub const ESPIPE : Self = Error ( -( bindings:: ESPIPE as i32 ) ) ;
99
+ declare_err ! ( EMLINK , "Too many links." ) ;
113
100
114
- /// Read-only file system.
115
- pub const EROFS : Self = Error ( -( bindings:: EROFS as i32 ) ) ;
101
+ declare_err ! ( EPIPE , "Broken pipe." ) ;
116
102
117
- /// Too many links.
118
- pub const EMLINK : Self = Error ( -( bindings:: EMLINK as i32 ) ) ;
103
+ declare_err ! ( EDOM , "Math argument out of domain of func." ) ;
119
104
120
- /// Broken pipe.
121
- pub const EPIPE : Self = Error ( -( bindings:: EPIPE as i32 ) ) ;
105
+ declare_err ! ( ERANGE , "Math result not representable." ) ;
122
106
123
- /// Math argument out of domain of func.
124
- pub const EDOM : Self = Error ( -( bindings:: EDOM as i32 ) ) ;
107
+ declare_err ! ( EDEADLK , "Resource deadlock would occur" ) ;
125
108
126
- /// Math result not representable.
127
- pub const ERANGE : Self = Error ( -( bindings:: ERANGE as i32 ) ) ;
109
+ declare_err ! ( ENAMETOOLONG , "File name too long" ) ;
128
110
129
- /// Cannot assign requested address.
130
- pub const EADDRNOTAVAIL : Self = Error ( -( bindings:: EADDRNOTAVAIL as i32 ) ) ;
111
+ declare_err ! ( EADDRNOTAVAIL , "Cannot assign requested address." ) ;
131
112
132
- /// Restart the system call.
133
- pub const ERESTARTSYS : Self = Error ( -( bindings:: ERESTARTSYS as i32 ) ) ;
113
+ declare_err ! ( ERESTARTSYS , "Restart the system call." ) ;
134
114
135
115
/// Creates an [`Error`] from a kernel error code.
136
116
///
0 commit comments