OSDN Git Service

* fcntl.cc (_fcntl): Rearrange as wrapper function. Move all
[pf3gnuchains/pf3gnuchains4x.git] / winsup / cygwin / fcntl.cc
1 /* fcntl.cc: fcntl syscall
2
3    Copyright 1996, 1997, 1998 Cygnus Solutions.
4
5 This file is part of Cygwin.
6
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
9 details. */
10
11 #include "winsup.h"
12 #include <fcntl.h>
13 #include <stdarg.h>
14 #include <errno.h>
15 #include <unistd.h>
16 #include "fhandler.h"
17 #include "dtable.h"
18 #include "cygerrno.h"
19 #include "thread.h"
20
21 extern "C"
22 int
23 _fcntl (int fd, int cmd,...)
24 {
25   void *arg = NULL;
26   va_list args;
27   int res;
28
29   if (fdtab.not_open (fd))
30     {
31       set_errno (EBADF);
32       res = -1;
33       goto done;
34     }
35
36   SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK, "_fcntl");
37   va_start (args, cmd);
38   arg = va_arg (args, void *);
39   if (cmd == F_DUPFD)
40     res = dup2 (fd, fdtab.find_unused_handle ((int) arg));
41   else
42     res = fdtab[fd]->fcntl(cmd, arg);
43   va_end (args);
44   ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"_fcntl");
45
46 done:
47   syscall_printf ("%d = fcntl (%d, %d, %p)", res, fd, cmd, arg);
48   return res;
49 }