1 | /* libc/sys/linux/io.c - Basic input/output system calls */ |
---|
2 | |
---|
3 | /* Written 2000 by Werner Almesberger */ |
---|
4 | |
---|
5 | |
---|
6 | #define __KERNEL_PROTOTYPES |
---|
7 | |
---|
8 | #include <stdarg.h> |
---|
9 | #include <unistd.h> |
---|
10 | #include <fcntl.h> |
---|
11 | #include <sys/types.h> |
---|
12 | #include <sys/uio.h> |
---|
13 | #include <sys/stat.h> |
---|
14 | #include <sys/ioctl.h> |
---|
15 | #include <poll.h> |
---|
16 | #include <machine/syscall.h> |
---|
17 | |
---|
18 | |
---|
19 | #define __NR___ioctl __NR_ioctl |
---|
20 | #define __NR___flock __NR_flock |
---|
21 | #define __NR___mknod __NR_mknod |
---|
22 | |
---|
23 | _syscall3(ssize_t,read,int,fd,void *,buf,size_t,count) |
---|
24 | _syscall3(ssize_t,write,int,fd,const void *,buf,size_t,count) |
---|
25 | _syscall3(int,open,const char *,file,int,flag,mode_t,mode) |
---|
26 | _syscall1(int,close,int,fd) |
---|
27 | _syscall3(off_t,lseek,int,fd,off_t,offset,int,count) |
---|
28 | _syscall0(int,sync) |
---|
29 | _syscall1(int,dup,int,fd) |
---|
30 | _syscall2(int,dup2,int,oldfd,int,newfd) |
---|
31 | _syscall3(int,fcntl,int,fd,int,cmd,long,arg) |
---|
32 | _syscall1(int,fdatasync,int,fd) |
---|
33 | _syscall1(int,fsync,int,fd) |
---|
34 | _syscall3(int,poll,struct pollfd *,fds,nfds_t,nfds,int,timeout) |
---|
35 | |
---|
36 | #if !defined(_ELIX_LEVEL) || _ELIX_LEVEL >= 2 |
---|
37 | _syscall3(ssize_t,readv,int,fd,const struct iovec *,vec,int,count) |
---|
38 | _syscall3(ssize_t,writev,int,fd,const struct iovec *,buf,int,count) |
---|
39 | #endif |
---|
40 | |
---|
41 | #if !defined(_ELIX_LEVEL) || _ELIX_LEVEL >= 4 |
---|
42 | _syscall2(int,ftruncate,int,fd,off_t,len) |
---|
43 | _syscall2(int,truncate,const char *,path,off_t,len) |
---|
44 | #endif |
---|
45 | |
---|
46 | static _syscall3(int,__ioctl,int,fd,int,request,void *,arg) |
---|
47 | |
---|
48 | int ioctl(int fd,int request,...) |
---|
49 | { |
---|
50 | va_list ap; |
---|
51 | int res; |
---|
52 | |
---|
53 | va_start(ap,request); |
---|
54 | res = __ioctl(fd,request,va_arg(ap,void *)); |
---|
55 | va_end(ap); |
---|
56 | return res; |
---|
57 | } |
---|
58 | |
---|
59 | static _syscall2(long,__flock,unsigned int,fd,unsigned int,cmd) |
---|
60 | |
---|
61 | int flock(int fd,int operation) |
---|
62 | { |
---|
63 | return __flock(fd,operation); |
---|
64 | } |
---|
65 | |
---|
66 | #if !defined(_ELIX_LEVEL) || _ELIX_LEVEL >= 3 |
---|
67 | |
---|
68 | static _syscall3(int,__mknod,const char *,path,mode_t,mode,dev_t,dev) |
---|
69 | |
---|
70 | int mkfifo(const char *path, mode_t mode) |
---|
71 | { |
---|
72 | dev_t dev = 0; |
---|
73 | return __mknod(path, mode | S_IFIFO, dev); |
---|
74 | } |
---|
75 | #endif |
---|
76 | |
---|
77 | weak_alias(__libc_close,__close); |
---|
78 | weak_alias(__libc_fcntl,__fcntl); |
---|
79 | weak_alias(__libc_lseek,__lseek); |
---|
80 | weak_alias(__libc_open,__open); |
---|
81 | weak_alias(__libc_read,__read); |
---|
82 | weak_alias(__libc_write,__write); |
---|
83 | weak_alias(__libc_poll,__poll); |
---|
84 | |
---|