xref: /minix/minix/lib/libc/sys/fcntl.c (revision 0a6a1f1d)
1 #include <sys/cdefs.h>
2 #include "namespace.h"
3 #include <lib.h>
4 
5 #include <string.h>
6 #include <fcntl.h>
7 #include <stdarg.h>
8 
9 int fcntl(int fd, int cmd, ...)
10 {
11   va_list argp;
12   message m;
13 
14   va_start(argp, cmd);
15 
16   /* Set up for the sensible case where there is no variable parameter.  This
17    * covers F_GETFD, F_GETFL and invalid commands.
18    */
19   memset(&m, 0, sizeof(m));
20 
21   /* Adjust for the stupid cases. */
22   switch(cmd) {
23      case F_DUPFD:
24      case F_DUPFD_CLOEXEC:
25      case F_SETFD:
26      case F_SETFL:
27      case F_SETNOSIGPIPE:
28 	m.m_lc_vfs_fcntl.arg_int = va_arg(argp, int);
29 	break;
30      case F_GETLK:
31      case F_SETLK:
32      case F_SETLKW:
33      case F_FREESP:
34 	m.m_lc_vfs_fcntl.arg_ptr = (vir_bytes)va_arg(argp, struct flock *);
35 	break;
36   }
37 
38   /* Clean up and make the system call. */
39   va_end(argp);
40   m.m_lc_vfs_fcntl.fd = fd;
41   m.m_lc_vfs_fcntl.cmd = cmd;
42   return(_syscall(VFS_PROC_NR, VFS_FCNTL, &m));
43 }
44