summaryrefslogtreecommitdiff
path: root/minix/lib/libc/sys/fcntl.c
blob: 8a243e5c19c29a4649a4290b0967a7f29722f2f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <sys/cdefs.h>
#include "namespace.h"
#include <lib.h>

#include <string.h>
#include <fcntl.h>
#include <stdarg.h>

int fcntl(int fd, int cmd, ...)
{
  va_list argp;
  message m;

  va_start(argp, cmd);

  /* Set up for the sensible case where there is no variable parameter.  This
   * covers F_GETFD, F_GETFL and invalid commands.
   */
  memset(&m, 0, sizeof(m));

  /* Adjust for the stupid cases. */
  switch(cmd) {
     case F_DUPFD:
     case F_DUPFD_CLOEXEC:
     case F_SETFD:
     case F_SETFL:
     case F_SETNOSIGPIPE:
	m.m_lc_vfs_fcntl.arg_int = va_arg(argp, int);
	break;
     case F_GETLK:
     case F_SETLK:
     case F_SETLKW:
     case F_FREESP:
	m.m_lc_vfs_fcntl.arg_ptr = (vir_bytes)va_arg(argp, struct flock *);
	break;
  }

  /* Clean up and make the system call. */
  va_end(argp);
  m.m_lc_vfs_fcntl.fd = fd;
  m.m_lc_vfs_fcntl.cmd = cmd;
  return(_syscall(VFS_PROC_NR, VFS_FCNTL, &m));
}