2 Copyright (C) 2008 Mathias Gottschlag
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in the
6 Software without restriction, including without limitation the rights to use,
7 copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8 Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include <sys/select.h>
29 #include <planlos/syscalls.h>
31 int open(const char *path
, int oflag
, ...)
34 asm volatile("int $0x80" : "=b"(status
): "a"(SYS_OPEN
), "b"(path
), "c"(oflag
));
38 int creat(const char *path
, mode_t mode
)
40 return open(path
, O_CREAT
| O_TRUNC
| O_WRONLY
, mode
);
43 ssize_t
write(int fildes
, const void *buf
, size_t nbyte
)
46 asm volatile("int $0x80" : "=b"(status
): "a"(SYS_WRITE
), "b"(fildes
), "c"(buf
), "d"(nbyte
));
50 ssize_t
read(int fildes
, void *buf
, size_t nbyte
)
53 asm volatile("int $0x80" : "=b"(status
): "a"(SYS_READ
), "b"(fildes
), "c"(buf
), "d"(nbyte
));
60 asm volatile("int $0x80" : "=b"(status
): "a"(SYS_CLOSE
), "b"(fildes
));
64 off_t
lseek(int fildes
, off_t offset
, int whence
)
67 asm volatile("int $0x80" : "=b"(position
): "a"(SYS_SEEK
), "b"(fildes
), "c"(offset
), "d"(whence
));
71 int mknod(const char *path
, mode_t mode
, dev_t dev
)
74 asm volatile("int $0x80" : "=b"(status
): "a"(SYS_MKNOD
), "b"(path
), "c"(mode
));
77 int mkdir(const char *path
, mode_t mode
)
79 return mknod(path
, mode
| S_IFDIR
, 0);
90 DIR *opendir(const char *path
)
92 int fd
= open(path
, O_RDONLY
| O_DIR
);
93 if (fd
== -1) return 0;
94 DIR *dir
= malloc(sizeof(DIR));
98 int closedir(DIR *dir
)
104 struct dirent
*readdir(DIR *dir
)
107 if (read(dir
->fd
, dir
->dirent
.d_name
, NAME_MAX
+ 1) <= 0) return 0;
110 void rewinddir(DIR *dir
)
114 void seekdir(DIR *dir
, long index
)
118 lseek(dir
->fd
, index
, SEEK_SET
);
121 long telldir(DIR *dir
)
124 return lseek(dir
->fd
, 0, SEEK_CUR
);
127 int ioctl(int fd
, int request
, ...)
129 int param
= *(&request
+ 1);
131 asm volatile("int $0x80" : "=b"(status
): "a"(SYS_IOCTL
), "b"(fd
), "c"(request
), "d"(param
));
135 int unlink(const char *filename
)
144 asm volatile("int $0x80" : "=b"(in
), "=c"(out
): "a"(SYS_PIPE
));
152 int fcntl(int fd
, int cmd
, ...)
154 uintptr_t param
= *(uintptr_t*)(&cmd
+ 1);
156 asm volatile("int $0x80" : "=b"(status
): "a"(SYS_FCNTL
), "b"(fd
), "c"(cmd
), "d"(param
));
160 int stat(const char *path
, struct stat
*buf
)
165 void FD_CLR(int fd
, fd_set
*fdset
)
168 int FD_ISSET(int fd
, fd_set
*fdset
)
172 void FD_SET(int fd
, fd_set
*fdset
)
175 void FD_ZERO(fd_set
*fdset
)
179 /*int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds,
180 const struct timespec *timeout, const sigset_t *sigmask)
183 int select(int nfds
, fd_set
*readfds
, fd_set
*writefds
, fd_set
*errorfds
,
184 struct timeval
*timeout
)