Usermode - More syscall renaming
[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 open(const char *path, int openmode, ...)
14 {
15         mode_t  create_mode = 0;
16         int openflags = 0;
17         
18         switch( openmode & O_RDWR )
19         {
20         case 0: // Special
21                 break;
22         case O_RDONLY:  openflags |= OPENFLAG_READ;     break;
23         case O_WRONLY:  openflags |= OPENFLAG_WRITE;    break;
24         case O_RDWR:    openflags |= OPENFLAG_READ|OPENFLAG_WRITE;      break;
25         }
26         
27         if( openmode & O_CREAT ) {
28                 openflags |= OPENFLAG_CREATE;
29                 va_list args;
30                 va_start(args, openmode);
31                 create_mode = va_arg(args, mode_t);
32                 va_end(args);
33         }
34         
35         return _SysOpen(path, openflags, create_mode);
36 }
37
38 int creat(const char *path, mode_t mode)
39 {
40         // TODO: Make native call to do this cheaper
41         int fd = _SysOpen(path, OPENFLAG_CREATE, mode);
42         if( fd == -1 )  return -1;
43         _SysClose(fd);
44         return 0;
45 }
46
47 int close(int fd)
48 {
49         _SysClose(fd);
50         return 0;
51 }
52
53 ssize_t write(int fd, const void *buf, size_t count)
54 {
55         return _SysWrite(fd, buf, count);
56 }
57
58 ssize_t read(int fd, void *buf, size_t count)
59 {
60         return _SysRead(fd, buf, count);
61 }
62
63 int fork(void)
64 {
65         return _SysClone(CLONE_VM, 0);
66 }
67
68 int execv(const char *b, char *v[])
69 {
70         return _SysExecVE(b, v, NULL);
71 }

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