8
8
9
9
#include " src/__support/StringUtil/error_to_string.h"
10
10
11
+ #include " src/errno/libc_errno.h" // For error macros
12
+
13
+ #include " src/__support/CPP/array.h"
11
14
#include " src/__support/CPP/span.h"
12
15
#include " src/__support/CPP/string_view.h"
13
16
#include " src/__support/CPP/stringstream.h"
14
17
#include " src/__support/StringUtil/message_mapper.h"
15
18
#include " src/__support/integer_to_string.h"
16
- #include " src/errno/libc_errno.h" // For error macros
19
+
20
+ #include " src/__support/StringUtil/tables/error_table.h"
17
21
18
22
#include < stddef.h>
19
23
@@ -33,157 +37,21 @@ constexpr size_t max_buff_size() {
33
37
constexpr size_t ERR_BUFFER_SIZE = max_buff_size();
34
38
thread_local char error_buffer[ERR_BUFFER_SIZE];
35
39
40
+ constexpr size_t RAW_ARRAY_LEN = PLATFORM_ERRORS.size();
41
+ constexpr size_t TOTAL_STR_LEN =
42
+ total_str_len (PLATFORM_ERRORS.data(), RAW_ARRAY_LEN);
43
+
36
44
// Since the StringMappings array is a map from error numbers to their
37
45
// corresponding strings, we have to have an array large enough we can use the
38
- // error numbers as indexes. Thankfully there are 132 errors in the above list
39
- // (41 and 58 are skipped) and the highest number is 133. If other platforms use
40
- // different error numbers, then this number may need to be adjusted.
41
- // Also if negative numbers or particularly large numbers are used, then the
42
- // array should be turned into a proper hashmap.
43
- constexpr size_t ERR_ARRAY_SIZE = 134 ;
44
-
45
- constexpr MsgMapping raw_err_array[] = {
46
- MsgMapping (0 , " Success" ),
47
- MsgMapping (EPERM, " Operation not permitted" ),
48
- MsgMapping (ENOENT, " No such file or directory" ),
49
- MsgMapping (ESRCH, " No such process" ),
50
- MsgMapping (EINTR, " Interrupted system call" ),
51
- MsgMapping (EIO, " Input/output error" ),
52
- MsgMapping (ENXIO, " No such device or address" ),
53
- MsgMapping (E2BIG, " Argument list too long" ),
54
- MsgMapping (ENOEXEC, " Exec format error" ),
55
- MsgMapping (EBADF, " Bad file descriptor" ),
56
- MsgMapping (ECHILD, " No child processes" ),
57
- MsgMapping (EAGAIN, " Resource temporarily unavailable" ),
58
- MsgMapping (ENOMEM, " Cannot allocate memory" ),
59
- MsgMapping (EACCES, " Permission denied" ),
60
- MsgMapping (EFAULT, " Bad address" ),
61
- MsgMapping (ENOTBLK, " Block device required" ),
62
- MsgMapping (EBUSY, " Device or resource busy" ),
63
- MsgMapping (EEXIST, " File exists" ),
64
- MsgMapping (EXDEV, " Invalid cross-device link" ),
65
- MsgMapping (ENODEV, " No such device" ),
66
- MsgMapping (ENOTDIR, " Not a directory" ),
67
- MsgMapping (EISDIR, " Is a directory" ),
68
- MsgMapping (EINVAL, " Invalid argument" ),
69
- MsgMapping (ENFILE, " Too many open files in system" ),
70
- MsgMapping (EMFILE, " Too many open files" ),
71
- MsgMapping (ENOTTY, " Inappropriate ioctl for device" ),
72
- MsgMapping (ETXTBSY, " Text file busy" ),
73
- MsgMapping (EFBIG, " File too large" ),
74
- MsgMapping (ENOSPC, " No space left on device" ),
75
- MsgMapping (ESPIPE, " Illegal seek" ),
76
- MsgMapping (EROFS, " Read-only file system" ),
77
- MsgMapping (EMLINK, " Too many links" ),
78
- MsgMapping (EPIPE, " Broken pipe" ),
79
- MsgMapping (EDOM, " Numerical argument out of domain" ),
80
- MsgMapping (ERANGE, " Numerical result out of range" ),
81
- MsgMapping (EDEADLK, " Resource deadlock avoided" ),
82
- MsgMapping (ENAMETOOLONG, " File name too long" ),
83
- MsgMapping (ENOLCK, " No locks available" ),
84
- MsgMapping (ENOSYS, " Function not implemented" ),
85
- MsgMapping (ENOTEMPTY, " Directory not empty" ),
86
- MsgMapping (ELOOP, " Too many levels of symbolic links" ),
87
- // No error for 41. Would be EWOULDBLOCK
88
- MsgMapping (ENOMSG, " No message of desired type" ),
89
- MsgMapping (EIDRM, " Identifier removed" ),
90
- MsgMapping (ECHRNG, " Channel number out of range" ),
91
- MsgMapping (EL2NSYNC, " Level 2 not synchronized" ),
92
- MsgMapping (EL3HLT, " Level 3 halted" ),
93
- MsgMapping (EL3RST, " Level 3 reset" ),
94
- MsgMapping (ELNRNG, " Link number out of range" ),
95
- MsgMapping (EUNATCH, " Protocol driver not attached" ),
96
- MsgMapping (ENOCSI, " No CSI structure available" ),
97
- MsgMapping (EL2HLT, " Level 2 halted" ),
98
- MsgMapping (EBADE, " Invalid exchange" ),
99
- MsgMapping (EBADR, " Invalid request descriptor" ),
100
- MsgMapping (EXFULL, " Exchange full" ),
101
- MsgMapping (ENOANO, " No anode" ),
102
- MsgMapping (EBADRQC, " Invalid request code" ),
103
- MsgMapping (EBADSLT, " Invalid slot" ),
104
- // No error for 58. Would be EDEADLOCK.
105
- MsgMapping (EBFONT, " Bad font file format" ),
106
- MsgMapping (ENOSTR, " Device not a stream" ),
107
- MsgMapping (ENODATA, " No data available" ),
108
- MsgMapping (ETIME, " Timer expired" ),
109
- MsgMapping (ENOSR, " Out of streams resources" ),
110
- MsgMapping (ENONET, " Machine is not on the network" ),
111
- MsgMapping (ENOPKG, " Package not installed" ),
112
- MsgMapping (EREMOTE, " Object is remote" ),
113
- MsgMapping (ENOLINK, " Link has been severed" ),
114
- MsgMapping (EADV, " Advertise error" ),
115
- MsgMapping (ESRMNT, " Srmount error" ),
116
- MsgMapping (ECOMM, " Communication error on send" ),
117
- MsgMapping (EPROTO, " Protocol error" ),
118
- MsgMapping (EMULTIHOP, " Multihop attempted" ),
119
- MsgMapping (EDOTDOT, " RFS specific error" ),
120
- MsgMapping (EBADMSG, " Bad message" ),
121
- MsgMapping (EOVERFLOW, " Value too large for defined data type" ),
122
- MsgMapping (ENOTUNIQ, " Name not unique on network" ),
123
- MsgMapping (EBADFD, " File descriptor in bad state" ),
124
- MsgMapping (EREMCHG, " Remote address changed" ),
125
- MsgMapping (ELIBACC, " Can not access a needed shared library" ),
126
- MsgMapping (ELIBBAD, " Accessing a corrupted shared library" ),
127
- MsgMapping (ELIBSCN, " .lib section in a.out corrupted" ),
128
- MsgMapping (ELIBMAX, " Attempting to link in too many shared libraries" ),
129
- MsgMapping (ELIBEXEC, " Cannot exec a shared library directly" ),
130
- MsgMapping (EILSEQ, " Invalid or incomplete multibyte or wide character" ),
131
- MsgMapping (ERESTART, " Interrupted system call should be restarted" ),
132
- MsgMapping (ESTRPIPE, " Streams pipe error" ),
133
- MsgMapping (EUSERS, " Too many users" ),
134
- MsgMapping (ENOTSOCK, " Socket operation on non-socket" ),
135
- MsgMapping (EDESTADDRREQ, " Destination address required" ),
136
- MsgMapping (EMSGSIZE, " Message too long" ),
137
- MsgMapping (EPROTOTYPE, " Protocol wrong type for socket" ),
138
- MsgMapping (ENOPROTOOPT, " Protocol not available" ),
139
- MsgMapping (EPROTONOSUPPORT, " Protocol not supported" ),
140
- MsgMapping (ESOCKTNOSUPPORT, " Socket type not supported" ),
141
- MsgMapping (ENOTSUP, " Operation not supported" ),
142
- MsgMapping (EPFNOSUPPORT, " Protocol family not supported" ),
143
- MsgMapping (EAFNOSUPPORT, " Address family not supported by protocol" ),
144
- MsgMapping (EADDRINUSE, " Address already in use" ),
145
- MsgMapping (EADDRNOTAVAIL, " Cannot assign requested address" ),
146
- MsgMapping (ENETDOWN, " Network is down" ),
147
- MsgMapping (ENETUNREACH, " Network is unreachable" ),
148
- MsgMapping (ENETRESET, " Network dropped connection on reset" ),
149
- MsgMapping (ECONNABORTED, " Software caused connection abort" ),
150
- MsgMapping (ECONNRESET, " Connection reset by peer" ),
151
- MsgMapping (ENOBUFS, " No buffer space available" ),
152
- MsgMapping (EISCONN, " Transport endpoint is already connected" ),
153
- MsgMapping (ENOTCONN, " Transport endpoint is not connected" ),
154
- MsgMapping (ESHUTDOWN, " Cannot send after transport endpoint shutdown" ),
155
- MsgMapping (ETOOMANYREFS, " Too many references: cannot splice" ),
156
- MsgMapping (ETIMEDOUT, " Connection timed out" ),
157
- MsgMapping (ECONNREFUSED, " Connection refused" ),
158
- MsgMapping (EHOSTDOWN, " Host is down" ),
159
- MsgMapping (EHOSTUNREACH, " No route to host" ),
160
- MsgMapping (EALREADY, " Operation already in progress" ),
161
- MsgMapping (EINPROGRESS, " Operation now in progress" ),
162
- MsgMapping (ESTALE, " Stale file handle" ),
163
- MsgMapping (EUCLEAN, " Structure needs cleaning" ),
164
- MsgMapping (ENOTNAM, " Not a XENIX named type file" ),
165
- MsgMapping (ENAVAIL, " No XENIX semaphores available" ),
166
- MsgMapping (EISNAM, " Is a named type file" ),
167
- MsgMapping (EREMOTEIO, " Remote I/O error" ),
168
- MsgMapping (EDQUOT, " Disk quota exceeded" ),
169
- MsgMapping (ENOMEDIUM, " No medium found" ),
170
- MsgMapping (EMEDIUMTYPE, " Wrong medium type" ),
171
- MsgMapping (ECANCELED, " Operation canceled" ),
172
- MsgMapping (ENOKEY, " Required key not available" ),
173
- MsgMapping (EKEYEXPIRED, " Key has expired" ),
174
- MsgMapping (EKEYREVOKED, " Key has been revoked" ),
175
- MsgMapping (EKEYREJECTED, " Key was rejected by service" ),
176
- MsgMapping (EOWNERDEAD, " Owner died" ),
177
- MsgMapping (ENOTRECOVERABLE, " State not recoverable" ),
178
- MsgMapping (ERFKILL, " Operation not possible due to RF-kill" ),
179
- MsgMapping (EHWPOISON, " Memory page has hardware error" ),
180
- };
181
-
182
- constexpr size_t RAW_ARRAY_LEN = sizeof (raw_err_array) / sizeof (MsgMapping);
183
- constexpr size_t TOTAL_STR_LEN = total_str_len(raw_err_array, RAW_ARRAY_LEN);
46
+ // error numbers as indexes. The current linux configuration has 132 values with
47
+ // the maximum value being 133 (41 and 58 are skipped). If other platforms use
48
+ // negative numbers or discontiguous ranges, then the array should be turned
49
+ // into a proper hashmap.
50
+ constexpr size_t ERR_ARRAY_SIZE =
51
+ max_key_val (PLATFORM_ERRORS.data(), RAW_ARRAY_LEN) + 1 ;
184
52
185
53
static constexpr MessageMapper<ERR_ARRAY_SIZE, TOTAL_STR_LEN>
186
- error_mapper (raw_err_array , RAW_ARRAY_LEN);
54
+ error_mapper (PLATFORM_ERRORS.data() , RAW_ARRAY_LEN);
187
55
188
56
cpp::string_view build_error_string (int err_num, cpp::span<char > buffer) {
189
57
// if the buffer can't hold "Unknown error" + ' ' + num_str, then just
0 commit comments