f5a142a84ea9af96261327210fb352a154a54994
[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 <stdio.h>
10 #include <errno.h>
11 #include <acess/sys.h>
12 #include <string.h>
13
14 EXPORT int *libc_geterrno()
15 {
16         return &_errno;
17 }
18
19 EXPORT char *strerror(int errnum)
20 {
21         switch((enum libc_eErrorNumbers)errnum)
22         {
23         case EOK:       return "Success";
24         case ERANGE:    return "Value out of range";
25         case EDOM:      return "Value out of domain";
26         case EILSEQ:    return "Illegal character sequence";
27
28         case ENOSYS:    return "Invalid instruction/syscall";
29         case EINVAL:    return "Bad argument(s)";
30         case EBADF:     return "Invalid file";
31         case ENOMEM:    return "No free memory";
32         case EACCES:    return "Not permitted";
33         case EBUSY:     return "Resource is busy";
34         case ENOTFOUND: return "Item not found";
35         case EROFS:     return "Read only filesystem";
36         case ENOTIMPL:  return "Not implimented";
37         case ENOENT:    return "No such file or directory";
38         case EEXIST:    return "Already exists";
39         case ENFILE:    return "Too many open files";
40         case ENOTDIR:   return "Not a directory";
41         case EISDIR:    return "Is a directory";
42         case EIO:       return "IO Error";
43         case EINTR:     return "Interrupted";
44         case EWOULDBLOCK:       return "Operation would have blocked";
45         case ENODEV:    return "No such device";
46         case EADDRNOTAVAIL:     return "Address not avaliable";
47         case EINPROGRESS:       return "Operation in process";
48         case EPERM:     return "Operation not permitted";
49         case ENOTTY:    return "Not a TTY";
50         case EAGAIN:    return "Try again";
51         case EFBIG:     return "File too big";
52         case E2BIG:     return "Value too big";
53         case EALREADY:  return "Operation was no-op";
54         case ENOSPC:    return "No space left on the device";
55
56         case EAFNOSUPPORT:      return "Address family not supported";
57         case EADDRINUSE:        return "Address already in use";
58         case ETIMEDOUT: return "Operation timed out";
59
60         case EINTERNAL: return "Internal error";
61         }
62         _SysDebug("strerror: errnum=%i unk", errnum);
63         errno = EINVAL;
64         return "unknown error";
65 }
66
67 EXPORT int strerror_r(int errnum, char *buf, size_t bufsiz)
68 {
69         const char *str = strerror(errnum);
70         if(!str)
71                 return -1;
72         
73         strncpy(buf, str, bufsiz);
74         return 0;
75 }
76
77 // stdio.h
78 EXPORT void perror(const char *s)
79 {
80         int err = errno;
81         if( s && s[0] ) {
82                 fprintf(stderr, "%s: (%i) %s\n", s, err, strerror(err));
83         }
84         else {
85                 fprintf(stderr, "(%i) %s\n", err, strerror(err));
86         }
87         _SysDebug("perror('%s'): %s (%i)", s, strerror(err), err);
88 }
89

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