AcessNative - Better error reporting in NativeFS
[tpg/acess2.git] / Usermode / Libraries / libposix.so_src / unistd.c
1 /*
2  * Acess2 POSIX Emulation Layer
3  * - By John Hodge
4  * 
5  * unistd.c
6  * - POSIX->Acess VFS call translation
7  */
8 #include <unistd.h>
9 #include <acess/sys.h>
10 #include <stdarg.h>
11
12 // === CODE ===
13 int unlink(const char *pathname)
14 {
15         return _SysUnlink(pathname);
16 }
17
18 int open(const char *path, int openmode, ...)
19 {
20         mode_t  create_mode = 0;
21         int openflags = 0;
22         
23         switch( openmode & O_RDWR )
24         {
25         case 0: // Special
26                 break;
27         case O_RDONLY:  openflags |= OPENFLAG_READ;     break;
28         case O_WRONLY:  openflags |= OPENFLAG_WRITE;    break;
29         case O_RDWR:    openflags |= OPENFLAG_READ|OPENFLAG_WRITE;      break;
30         }
31         
32         if( openmode & O_CREAT ) {
33                 openflags |= OPENFLAG_CREATE;
34                 va_list args;
35                 va_start(args, openmode);
36                 create_mode = va_arg(args, mode_t);
37                 va_end(args);
38         }
39         
40         return _SysOpen(path, openflags, create_mode);
41 }
42
43 int creat(const char *path, mode_t mode)
44 {
45         // TODO: Make native call to do this cheaper
46         int fd = _SysOpen(path, OPENFLAG_CREATE, mode);
47         if( fd == -1 )  return -1;
48         _SysClose(fd);
49         return 0;
50 }
51
52 int close(int fd)
53 {
54         _SysClose(fd);
55         return 0;
56 }
57
58 ssize_t write(int fd, const void *buf, size_t count)
59 {
60         return _SysWrite(fd, buf, count);
61 }
62
63 ssize_t read(int fd, void *buf, size_t count)
64 {
65         return _SysRead(fd, buf, count);
66 }
67
68 int seek(int fd, int whence, off_t dest)
69 {
70         return _SysSeek(fd, whence, dest);
71 }
72
73 off_t tell(int fd)
74 {
75         return _SysTell(fd);
76 }
77
78 int fork(void)
79 {
80         return _SysClone(CLONE_VM, 0);
81 }
82
83 int execv(const char *b, char *v[])
84 {
85         return _SysExecVE(b, v, NULL);
86 }
87
88 int dup2(int oldfd, int newfd)
89 {
90         // NOTE: Acess's CopyFD doesn't cause offset sharing
91         return _SysCopyFD(oldfd, newfd);
92 }
93

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