Usermode/libc - Improved strerror, added some basic time functions
[tpg/acess2.git] / Usermode / Libraries / libc.so_src / errno.c
1 /*
2  * Acess2 C Library
3  * - By John Hodge (thePowersGang)
4  * 
5  * errno.c
6  * - errno and strerror
7  */
8 #include "lib.h"
9 #include <errno.h>
10 #include <acess/sys.h>
11 #include <string.h>
12
13 EXPORT int *libc_geterrno()
14 {
15         return &_errno;
16 }
17
18 EXPORT char *strerror(int errnum)
19 {
20         switch((enum libc_eErrorNumbers)errnum)
21         {
22         case EOK:       return "Success";
23         case ENOSYS:    return "Invalid instruction/syscall";
24         case EINVAL:    return "Bad argument(s)";
25         case EBADF:     return "Invalid file";
26         case ENOMEM:    return "No free memory";
27         case EACCES:    return "Not permitted";
28         case EBUSY:     return "Resource is busy";
29         case ERANGE:    return "Value out of range";
30         case ENOTFOUND: return "Item not found";
31         case EROFS:     return "Read only filesystem";
32         case ENOTIMPL:  return "Not implimented";
33         case ENOENT:    return "No such file or directory";
34         case EEXIST:    return "Already exists";
35         case ENFILE:    return "Too many open files";
36         case ENOTDIR:   return "Not a directory";
37         case EISDIR:    return "Is a directory";
38         case EIO:       return "IO Error";
39         case EINTR:     return "Interrupted";
40         case EWOULDBLOCK:       return "Operation would have blocked";
41         case ENODEV:    return "No such device";
42         case EADDRNOTAVAIL:     return "Address not avaliable";
43         case EINPROGRESS:       return "Operation in process";
44         case EPERM:     return "Operation not permitted";
45         case EAGAIN:    return "Try again";
46         case EALREADY:  return "Operation was no-op";
47         case EINTERNAL: return "Internal error";
48         }
49         _SysDebug("strerror: errnum=%i unk", errnum);
50         errno = EINVAL;
51         return "unknown error";
52 }
53
54 EXPORT int strerror_r(int errnum, char *buf, size_t bufsiz)
55 {
56         const char *str = strerror(errnum);
57         if(!str)
58                 return -1;
59         
60         strncpy(buf, str, bufsiz);
61         return 0;
62 }
63

UCC git Repository :: git.ucc.asn.au