OrionLibC
Barry Importing existing Orion LibC 03048a9 (2 years, 2 months ago)diff --git a/stdio/perror.c b/stdio/perror.c new file mode 100644 index 0000000..c852582 --- /dev/null +++ b/stdio/perror.c @@ -0,0 +1,39 @@ +#include <stdio.h> +#include <errno.h> + +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]); +}