X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Flibc.so_src%2Ferrno.c;h=295183c4310c578594bc3809067432e7618d3f7f;hb=ba78deafcc3016555469ed263d7a0370fa99db4b;hp=987732821746028def0df9fe03f5e848ffb39241;hpb=8cf9dc88c488ba959a211f1ec653a366d16e1531;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libc.so_src/errno.c b/Usermode/Libraries/libc.so_src/errno.c index 98773282..295183c4 100644 --- a/Usermode/Libraries/libc.so_src/errno.c +++ b/Usermode/Libraries/libc.so_src/errno.c @@ -6,25 +6,85 @@ * - errno and strerror */ #include "lib.h" +#include #include #include +#include EXPORT int *libc_geterrno() { return &_errno; } -EXPORT const char *strerror(int errnum) +EXPORT char *strerror(int errnum) { - switch(errnum) + switch((enum libc_eErrorNumbers)errnum) { + case EOK: return "Success"; + case ERANGE: return "Value out of range"; + case EDOM: return "Value out of domain"; + case EILSEQ: return "Illegal character sequence"; + case ENOSYS: return "Invalid instruction/syscall"; + case EINVAL: return "Bad argument(s)"; + case EBADF: return "Invalid file"; + case ENOMEM: return "No free memory"; + case EACCES: return "Not permitted"; + case EBUSY: return "Resource is busy"; + case ENOTFOUND: return "Item not found"; + case EROFS: return "Read only filesystem"; + case ENOTIMPL: return "Not implimented"; case ENOENT: return "No such file or directory"; - case EINVAL: return "Bad arguments"; - case EPERM: return "Permissions error"; - default: - _SysDebug("strerror: errnum=%i unk", errnum); - return "unknown error"; + case EEXIST: return "Already exists"; + case ENFILE: return "Too many open files"; + case ENOTDIR: return "Not a directory"; + case EISDIR: return "Is a directory"; + case EIO: return "IO Error"; + case EINTR: return "Interrupted"; + case EWOULDBLOCK: return "Operation would have blocked"; + case ENODEV: return "No such device"; + case EADDRNOTAVAIL: return "Address not avaliable"; + case EINPROGRESS: return "Operation in process"; + case EPERM: return "Operation not permitted"; + case ENOTTY: return "Not a TTY"; + case EAGAIN: return "Try again"; + case EFBIG: return "File too big"; + case E2BIG: return "Value too big"; + case EALREADY: return "Operation was no-op"; + case ENOSPC: return "No space left on the device"; + + case EAFNOSUPPORT: return "Address family not supported"; + case EADDRINUSE: return "Address already in use"; + case ETIMEDOUT: return "Operation timed out"; + case EOPNOTSUPP: return "Operation not supported on socket"; + + case EINTERNAL: return "Internal error"; + } + _SysDebug("strerror: errnum=%i unk", errnum); + errno = EINVAL; + return "unknown error"; +} + +EXPORT int strerror_r(int errnum, char *buf, size_t bufsiz) +{ + const char *str = strerror(errnum); + if(!str) + return -1; + + strncpy(buf, str, bufsiz); + return 0; +} + +// stdio.h +EXPORT void perror(const char *s) +{ + int err = errno; + if( s && s[0] ) { + fprintf(stderr, "%s: (%i) %s\n", s, err, strerror(err)); + } + else { + fprintf(stderr, "(%i) %s\n", err, strerror(err)); } + _SysDebug("perror('%s'): %s (%i)", s, strerror(err), err); }