1433d6423SLionel Sambuc #include <sys/cdefs.h>
2433d6423SLionel Sambuc #include "namespace.h"
3433d6423SLionel Sambuc #include <lib.h>
4433d6423SLionel Sambuc
5433d6423SLionel Sambuc #include <string.h>
6433d6423SLionel Sambuc #include <fcntl.h>
7433d6423SLionel Sambuc #include <stdarg.h>
8433d6423SLionel Sambuc
fcntl(int fd,int cmd,...)9433d6423SLionel Sambuc int fcntl(int fd, int cmd, ...)
10433d6423SLionel Sambuc {
11433d6423SLionel Sambuc va_list argp;
12433d6423SLionel Sambuc message m;
13433d6423SLionel Sambuc
14433d6423SLionel Sambuc va_start(argp, cmd);
15433d6423SLionel Sambuc
16433d6423SLionel Sambuc /* Set up for the sensible case where there is no variable parameter. This
17433d6423SLionel Sambuc * covers F_GETFD, F_GETFL and invalid commands.
18433d6423SLionel Sambuc */
19433d6423SLionel Sambuc memset(&m, 0, sizeof(m));
20433d6423SLionel Sambuc
21433d6423SLionel Sambuc /* Adjust for the stupid cases. */
22433d6423SLionel Sambuc switch(cmd) {
23433d6423SLionel Sambuc case F_DUPFD:
24*424cad2cSDavid van Moolenbroek case F_DUPFD_CLOEXEC:
25433d6423SLionel Sambuc case F_SETFD:
26433d6423SLionel Sambuc case F_SETFL:
271f945e80SDavid van Moolenbroek case F_SETNOSIGPIPE:
28433d6423SLionel Sambuc m.m_lc_vfs_fcntl.arg_int = va_arg(argp, int);
29433d6423SLionel Sambuc break;
30433d6423SLionel Sambuc case F_GETLK:
31433d6423SLionel Sambuc case F_SETLK:
32433d6423SLionel Sambuc case F_SETLKW:
33433d6423SLionel Sambuc case F_FREESP:
345dd8da10SDavid van Moolenbroek m.m_lc_vfs_fcntl.arg_ptr = (vir_bytes)va_arg(argp, struct flock *);
35433d6423SLionel Sambuc break;
36433d6423SLionel Sambuc }
37433d6423SLionel Sambuc
38433d6423SLionel Sambuc /* Clean up and make the system call. */
39433d6423SLionel Sambuc va_end(argp);
40433d6423SLionel Sambuc m.m_lc_vfs_fcntl.fd = fd;
41433d6423SLionel Sambuc m.m_lc_vfs_fcntl.cmd = cmd;
42433d6423SLionel Sambuc return(_syscall(VFS_PROC_NR, VFS_FCNTL, &m));
43433d6423SLionel Sambuc }
44