| Directory: | ./ |
|---|---|
| File: | s21_strerror.c |
| Date: | 2025-11-01 23:04:41 |
| 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 | "Capabilities insufficient"}; | ||
| 113 | #endif | ||
| 114 | |||
| 115 | #ifdef __linux__ | ||
| 116 | #define UNKNOWN "Unknown error " | ||
| 117 | static char *s21_errlist[] = { | ||
| 118 | "Success", | ||
| 119 | "Operation not permitted", | ||
| 120 | "No such file or directory", | ||
| 121 | "No such process", | ||
| 122 | "Interrupted system call", | ||
| 123 | "Input/output error", | ||
| 124 | "No such device or address", | ||
| 125 | "Argument list too long", | ||
| 126 | "Exec format error", | ||
| 127 | "Bad file descriptor", | ||
| 128 | "No child processes", | ||
| 129 | "Resource temporarily unavailable", | ||
| 130 | "Cannot allocate memory", | ||
| 131 | "Permission denied", | ||
| 132 | "Bad address", | ||
| 133 | "Block device required", | ||
| 134 | "Device or resource busy", | ||
| 135 | "File exists", | ||
| 136 | "Invalid cross-device link", | ||
| 137 | "No such device", | ||
| 138 | "Not a directory", | ||
| 139 | "Is a directory", | ||
| 140 | "Invalid argument", | ||
| 141 | "Too many open files in system", | ||
| 142 | "Too many open files", | ||
| 143 | "Inappropriate ioctl for device", | ||
| 144 | "Text file busy", | ||
| 145 | "File too large", | ||
| 146 | "No space left on device", | ||
| 147 | "Illegal seek", | ||
| 148 | "Read-only file system", | ||
| 149 | "Too many links", | ||
| 150 | "Broken pipe", | ||
| 151 | "Numerical argument out of domain", | ||
| 152 | "Numerical result out of range", | ||
| 153 | "Resource deadlock avoided", | ||
| 154 | "File name too long", | ||
| 155 | "No locks available", | ||
| 156 | "Function not implemented", | ||
| 157 | "Directory not empty", | ||
| 158 | "Too many levels of symbolic links", | ||
| 159 | "Unknown error 41", | ||
| 160 | "No message of desired type", | ||
| 161 | "Identifier removed", | ||
| 162 | "Channel number out of range", | ||
| 163 | "Level 2 not synchronized", | ||
| 164 | "Level 3 halted", | ||
| 165 | "Level 3 reset", | ||
| 166 | "Link number out of range", | ||
| 167 | "Protocol driver not attached", | ||
| 168 | "No CSI structure available", | ||
| 169 | "Level 2 halted", | ||
| 170 | "Invalid exchange", | ||
| 171 | "Invalid request descriptor", | ||
| 172 | "Exchange full", | ||
| 173 | "No anode", | ||
| 174 | "Invalid request code", | ||
| 175 | "Invalid slot", | ||
| 176 | "Unknown error 58", | ||
| 177 | "Bad font file format", | ||
| 178 | "Device not a stream", | ||
| 179 | "No data available", | ||
| 180 | "Timer expired", | ||
| 181 | "Out of streams resources", | ||
| 182 | "Machine is not on the network", | ||
| 183 | "Package not installed", | ||
| 184 | "Object is remote", | ||
| 185 | "Link has been severed", | ||
| 186 | "Advertise error", | ||
| 187 | "Srmount error", | ||
| 188 | "Communication error on send", | ||
| 189 | "Protocol error", | ||
| 190 | "Multihop attempted", | ||
| 191 | "RFS specific error", | ||
| 192 | "Bad message", | ||
| 193 | "Value too large for defined data type", | ||
| 194 | "Name not unique on network", | ||
| 195 | "File descriptor in bad state", | ||
| 196 | "Remote address changed", | ||
| 197 | "Can not access a needed shared library", | ||
| 198 | "Accessing a corrupted shared library", | ||
| 199 | ".lib section in a.out corrupted", | ||
| 200 | "Attempting to link in too many shared libraries", | ||
| 201 | "Cannot exec a shared library directly", | ||
| 202 | "Invalid or incomplete multibyte or wide character", | ||
| 203 | "Interrupted system call should be restarted", | ||
| 204 | "Streams pipe error", | ||
| 205 | "Too many users", | ||
| 206 | "Socket operation on non-socket", | ||
| 207 | "Destination address required", | ||
| 208 | "Message too long", | ||
| 209 | "Protocol wrong type for socket", | ||
| 210 | "Protocol not available", | ||
| 211 | "Protocol not supported", | ||
| 212 | "Socket type not supported", | ||
| 213 | "Operation not supported", | ||
| 214 | "Protocol family not supported", | ||
| 215 | "Address family not supported by protocol", | ||
| 216 | "Address already in use", | ||
| 217 | "Cannot assign requested address", | ||
| 218 | "Network is down", | ||
| 219 | "Network is unreachable", | ||
| 220 | "Network dropped connection on reset", | ||
| 221 | "Software caused connection abort", | ||
| 222 | "Connection reset by peer", | ||
| 223 | "No buffer space available", | ||
| 224 | "Transport endpoint is already connected", | ||
| 225 | "Transport endpoint is not connected", | ||
| 226 | "Cannot send after transport endpoint shutdown", | ||
| 227 | "Too many references: cannot splice", | ||
| 228 | "Connection timed out", | ||
| 229 | "Connection refused", | ||
| 230 | "Host is down", | ||
| 231 | "No route to host", | ||
| 232 | "Operation already in progress", | ||
| 233 | "Operation now in progress", | ||
| 234 | "Stale file handle", | ||
| 235 | "Structure needs cleaning", | ||
| 236 | "Not a XENIX named type file", | ||
| 237 | "No XENIX semaphores available", | ||
| 238 | "Is a named type file", | ||
| 239 | "Remote I/O error", | ||
| 240 | "Disk quota exceeded", | ||
| 241 | "No medium found", | ||
| 242 | "Wrong medium type", | ||
| 243 | "Operation canceled", | ||
| 244 | "Required key not available", | ||
| 245 | "Key has expired", | ||
| 246 | "Key has been revoked", | ||
| 247 | "Key was rejected by service", | ||
| 248 | "Owner died", | ||
| 249 | "State not recoverable", | ||
| 250 | "Operation not possible due to RF-kill", | ||
| 251 | "Memory page has hardware error"}; | ||
| 252 | #endif | ||
| 253 | |||
| 254 | static const int s21_nerr = sizeof(s21_errlist) / sizeof(s21_errlist[0]); | ||
| 255 | |||
| 256 | 2049 | char *s21_strerror(int errnum) { | |
| 257 | static char message[512]; | ||
| 258 | |||
| 259 |
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) { |
| 260 | 134 | s21_strncpy(message, s21_errlist[errnum], 512); | |
| 261 | } else { | ||
| 262 | 1915 | s21_sprintf(message, UNKNOWN "%d", errnum); | |
| 263 | } | ||
| 264 | |||
| 265 | 2049 | return message; | |
| 266 | } | ||
| 267 |