Directory: | ./ |
---|---|
File: | s21_strerror.c |
Date: | 2025-07-13 17:59:14 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 5 | 5 | 100.0% |
Branches: | 4 | 4 | 100.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | #include "s21_string.h" | ||
2 | |||
3 | #ifdef __APPLE__ | ||
4 | #define UNKNOWN "Unknown error: " | ||
5 | static char *s21_errlist[] = {"Undefined error: 0", | ||
6 | "Operation not permitted", | ||
7 | "No such file or directory", | ||
8 | "No such process", | ||
9 | "Interrupted system call", | ||
10 | "Input/output error", | ||
11 | "Device not configured", | ||
12 | "Argument list too long", | ||
13 | "Exec format error", | ||
14 | "Bad file descriptor", | ||
15 | "No child processes", | ||
16 | "Resource deadlock avoided", | ||
17 | "Cannot allocate memory", | ||
18 | "Permission denied", | ||
19 | "Bad address", | ||
20 | "Block device required", | ||
21 | "Resource busy", | ||
22 | "File exists", | ||
23 | "Cross-device link", | ||
24 | "Operation not supported by device", | ||
25 | "Not a directory", | ||
26 | "Is a directory", | ||
27 | "Invalid argument", | ||
28 | "Too many open files in system", | ||
29 | "Too many open files", | ||
30 | "Inappropriate ioctl for device", | ||
31 | "Text file busy", | ||
32 | "File too large", | ||
33 | "No space left on device", | ||
34 | "Illegal seek", | ||
35 | "Read-only file system", | ||
36 | "Too many links", | ||
37 | "Broken pipe", | ||
38 | "Numerical argument out of domain", | ||
39 | "Result too large", | ||
40 | "Resource temporarily unavailable", | ||
41 | "Operation now in progress", | ||
42 | "Operation already in progress", | ||
43 | "Socket operation on non-socket", | ||
44 | "Destination address required", | ||
45 | "Message too long", | ||
46 | "Protocol wrong type for socket", | ||
47 | "Protocol not available", | ||
48 | "Protocol not supported", | ||
49 | "Socket type not supported", | ||
50 | "Operation not supported", | ||
51 | "Protocol family not supported", | ||
52 | "Address family not supported by protocol family", | ||
53 | "Address already in use", | ||
54 | "Can't assign requested address", | ||
55 | "Network is down", | ||
56 | "Network is unreachable", | ||
57 | "Network dropped connection on reset", | ||
58 | "Software caused connection abort", | ||
59 | "Connection reset by peer", | ||
60 | "No buffer space available", | ||
61 | "Socket is already connected", | ||
62 | "Socket is not connected", | ||
63 | "Can't send after socket shutdown", | ||
64 | "Too many references: can't splice", | ||
65 | "Operation timed out", | ||
66 | "Connection refused", | ||
67 | "Too many levels of symbolic links", | ||
68 | "File name too long", | ||
69 | "Host is down", | ||
70 | "No route to host", | ||
71 | "Directory not empty", | ||
72 | "Too many processes", | ||
73 | "Too many users", | ||
74 | "Disc quota exceeded", | ||
75 | "Stale NFS file handle", | ||
76 | "Too many levels of remote in path", | ||
77 | "RPC struct is bad", | ||
78 | "RPC version wrong", | ||
79 | "RPC prog. not avail", | ||
80 | "Program version wrong", | ||
81 | "Bad procedure for program", | ||
82 | "No locks available", | ||
83 | "Function not implemented", | ||
84 | "Inappropriate file type or format", | ||
85 | "Authentication error", | ||
86 | "Need authenticator", | ||
87 | "Device power is off", | ||
88 | "Device error", | ||
89 | "Value too large to be stored in data type", | ||
90 | "Bad executable (or shared library)", | ||
91 | "Bad CPU type in executable", | ||
92 | "Shared library version mismatch", | ||
93 | "Malformed Mach-o file", | ||
94 | "Operation canceled", | ||
95 | "Identifier removed", | ||
96 | "No message of desired type", | ||
97 | "Illegal byte sequence", | ||
98 | "Attribute not found", | ||
99 | "Bad message", | ||
100 | "EMULTIHOP (Reserved)", | ||
101 | "No message available on STREAM", | ||
102 | "ENOLINK (Reserved)", | ||
103 | "No STREAM resources", | ||
104 | "Not a STREAM", | ||
105 | "Protocol error", | ||
106 | "STREAM ioctl timeout", | ||
107 | "Operation not supported on socket", | ||
108 | "Policy not found", | ||
109 | "State not recoverable", | ||
110 | "Previous owner died", | ||
111 | "Interface output queue is full"}; | ||
112 | #endif | ||
113 | |||
114 | #ifdef __linux__ | ||
115 | #define UNKNOWN "Unknown error " | ||
116 | static char *s21_errlist[] = { | ||
117 | "Success", | ||
118 | "Operation not permitted", | ||
119 | "No such file or directory", | ||
120 | "No such process", | ||
121 | "Interrupted system call", | ||
122 | "Input/output error", | ||
123 | "No such device or address", | ||
124 | "Argument list too long", | ||
125 | "Exec format error", | ||
126 | "Bad file descriptor", | ||
127 | "No child processes", | ||
128 | "Resource temporarily unavailable", | ||
129 | "Cannot allocate memory", | ||
130 | "Permission denied", | ||
131 | "Bad address", | ||
132 | "Block device required", | ||
133 | "Device or resource busy", | ||
134 | "File exists", | ||
135 | "Invalid cross-device link", | ||
136 | "No such device", | ||
137 | "Not a directory", | ||
138 | "Is a directory", | ||
139 | "Invalid argument", | ||
140 | "Too many open files in system", | ||
141 | "Too many open files", | ||
142 | "Inappropriate ioctl for device", | ||
143 | "Text file busy", | ||
144 | "File too large", | ||
145 | "No space left on device", | ||
146 | "Illegal seek", | ||
147 | "Read-only file system", | ||
148 | "Too many links", | ||
149 | "Broken pipe", | ||
150 | "Numerical argument out of domain", | ||
151 | "Numerical result out of range", | ||
152 | "Resource deadlock avoided", | ||
153 | "File name too long", | ||
154 | "No locks available", | ||
155 | "Function not implemented", | ||
156 | "Directory not empty", | ||
157 | "Too many levels of symbolic links", | ||
158 | "Unknown error 41", | ||
159 | "No message of desired type", | ||
160 | "Identifier removed", | ||
161 | "Channel number out of range", | ||
162 | "Level 2 not synchronized", | ||
163 | "Level 3 halted", | ||
164 | "Level 3 reset", | ||
165 | "Link number out of range", | ||
166 | "Protocol driver not attached", | ||
167 | "No CSI structure available", | ||
168 | "Level 2 halted", | ||
169 | "Invalid exchange", | ||
170 | "Invalid request descriptor", | ||
171 | "Exchange full", | ||
172 | "No anode", | ||
173 | "Invalid request code", | ||
174 | "Invalid slot", | ||
175 | "Unknown error 58", | ||
176 | "Bad font file format", | ||
177 | "Device not a stream", | ||
178 | "No data available", | ||
179 | "Timer expired", | ||
180 | "Out of streams resources", | ||
181 | "Machine is not on the network", | ||
182 | "Package not installed", | ||
183 | "Object is remote", | ||
184 | "Link has been severed", | ||
185 | "Advertise error", | ||
186 | "Srmount error", | ||
187 | "Communication error on send", | ||
188 | "Protocol error", | ||
189 | "Multihop attempted", | ||
190 | "RFS specific error", | ||
191 | "Bad message", | ||
192 | "Value too large for defined data type", | ||
193 | "Name not unique on network", | ||
194 | "File descriptor in bad state", | ||
195 | "Remote address changed", | ||
196 | "Can not access a needed shared library", | ||
197 | "Accessing a corrupted shared library", | ||
198 | ".lib section in a.out corrupted", | ||
199 | "Attempting to link in too many shared libraries", | ||
200 | "Cannot exec a shared library directly", | ||
201 | "Invalid or incomplete multibyte or wide character", | ||
202 | "Interrupted system call should be restarted", | ||
203 | "Streams pipe error", | ||
204 | "Too many users", | ||
205 | "Socket operation on non-socket", | ||
206 | "Destination address required", | ||
207 | "Message too long", | ||
208 | "Protocol wrong type for socket", | ||
209 | "Protocol not available", | ||
210 | "Protocol not supported", | ||
211 | "Socket type not supported", | ||
212 | "Operation not supported", | ||
213 | "Protocol family not supported", | ||
214 | "Address family not supported by protocol", | ||
215 | "Address already in use", | ||
216 | "Cannot assign requested address", | ||
217 | "Network is down", | ||
218 | "Network is unreachable", | ||
219 | "Network dropped connection on reset", | ||
220 | "Software caused connection abort", | ||
221 | "Connection reset by peer", | ||
222 | "No buffer space available", | ||
223 | "Transport endpoint is already connected", | ||
224 | "Transport endpoint is not connected", | ||
225 | "Cannot send after transport endpoint shutdown", | ||
226 | "Too many references: cannot splice", | ||
227 | "Connection timed out", | ||
228 | "Connection refused", | ||
229 | "Host is down", | ||
230 | "No route to host", | ||
231 | "Operation already in progress", | ||
232 | "Operation now in progress", | ||
233 | "Stale file handle", | ||
234 | "Structure needs cleaning", | ||
235 | "Not a XENIX named type file", | ||
236 | "No XENIX semaphores available", | ||
237 | "Is a named type file", | ||
238 | "Remote I/O error", | ||
239 | "Disk quota exceeded", | ||
240 | "No medium found", | ||
241 | "Wrong medium type", | ||
242 | "Operation canceled", | ||
243 | "Required key not available", | ||
244 | "Key has expired", | ||
245 | "Key has been revoked", | ||
246 | "Key was rejected by service", | ||
247 | "Owner died", | ||
248 | "State not recoverable", | ||
249 | "Operation not possible due to RF-kill", | ||
250 | "Memory page has hardware error"}; | ||
251 | #endif | ||
252 | |||
253 | static const int s21_nerr = sizeof(s21_errlist) / sizeof(s21_errlist[0]); | ||
254 | |||
255 | 2049 | char *s21_strerror(int errnum) { | |
256 | static char message[512]; | ||
257 | |||
258 |
4/4✓ Branch 0 taken 1025 times.
✓ Branch 1 taken 1024 times.
✓ Branch 2 taken 134 times.
✓ Branch 3 taken 891 times.
|
2049 | if (errnum >= 0 && errnum < s21_nerr) { |
259 | 134 | s21_strncpy(message, s21_errlist[errnum], 512); | |
260 | } else { | ||
261 | 1915 | s21_sprintf(message, UNKNOWN "%d", errnum); | |
262 | } | ||
263 | |||
264 | 2049 | return message; | |
265 | } | ||
266 |