#include #include int errno; const char *errorList[] = { [ENONE] = "No error", [EPERM] = "Operation not permitted", [ENOENT] = "No such file or directory", [ESRCH] = "No such process", [EINVAL] = "Invalid argument", [EBADF] = "Bad file descriptor", [ENOEXEC] = "Exec format error", [EMFILE] = "Too many open files", [EFAULT] = "Bad address", [EISDIR] = "Is a directory", [ENOTDIR] = "Not a directory", [EACCES] = "Permission denied", [ENODEV] = "No such device", [EEXIST] = "File exists", [ENXIO] = "No such device or address", [ENOTBLK] = "Block device required", [ENOMEM] = "Cannot allocate memory", [ECHILD] = "No child processes", [ENOTTY] = "Inappropriate ioctl for device", }; /* Display an error message for errno */ void perror(const char *s) { if (errno < 0 || errno >= (sizeof(errorList)/sizeof(errorList[0]))) return; if (!s) printf("%s\n", errorList[errno]); else if (!s[0]) printf("%s\n", errorList[errno]); else printf("%s: %s\n", s, errorList[errno]); }