Kernel - Changed PTY code to not expose userland server node as a file
[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 ENOTTY:    return "Not a TTY";
46         case EAGAIN:    return "Try again";
47         case EALREADY:  return "Operation was no-op";
48         case EINTERNAL: return "Internal error";
49         }
50         _SysDebug("strerror: errnum=%i unk", errnum);
51         errno = EINVAL;
52         return "unknown error";
53 }
54
55 EXPORT int strerror_r(int errnum, char *buf, size_t bufsiz)
56 {
57         const char *str = strerror(errnum);
58         if(!str)
59                 return -1;
60         
61         strncpy(buf, str, bufsiz);
62         return 0;
63 }
64

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