2000-02-18 03:38:33 +08:00
|
|
|
/* fcntl.cc: fcntl syscall
|
|
|
|
|
|
|
|
Copyright 1996, 1997, 1998 Cygnus Solutions.
|
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "fhandler.h"
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "dtable.h"
|
2001-04-19 05:10:15 +08:00
|
|
|
#include "cygheap.h"
|
2000-08-22 11:58:47 +08:00
|
|
|
#include "cygerrno.h"
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "thread.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
extern "C"
|
|
|
|
int
|
|
|
|
_fcntl (int fd, int cmd,...)
|
|
|
|
{
|
2000-10-24 04:16:52 +08:00
|
|
|
void *arg = NULL;
|
2000-02-18 03:38:33 +08:00
|
|
|
va_list args;
|
|
|
|
int res;
|
|
|
|
|
2001-04-19 05:10:15 +08:00
|
|
|
if (cygheap->fdtab.not_open (fd))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
set_errno (EBADF);
|
|
|
|
res = -1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2000-10-24 04:16:52 +08:00
|
|
|
SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK, "_fcntl");
|
|
|
|
va_start (args, cmd);
|
|
|
|
arg = va_arg (args, void *);
|
|
|
|
if (cmd == F_DUPFD)
|
2001-04-19 05:10:15 +08:00
|
|
|
res = dup2 (fd, cygheap->fdtab.find_unused_handle ((int) arg));
|
2000-10-24 04:16:52 +08:00
|
|
|
else
|
2001-04-19 05:10:15 +08:00
|
|
|
res = cygheap->fdtab[fd]->fcntl(cmd, arg);
|
2000-10-24 04:16:52 +08:00
|
|
|
va_end (args);
|
2000-02-18 03:38:33 +08:00
|
|
|
ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"_fcntl");
|
|
|
|
|
2000-10-24 04:16:52 +08:00
|
|
|
done:
|
|
|
|
syscall_printf ("%d = fcntl (%d, %d, %p)", res, fd, cmd, arg);
|
2000-02-18 03:38:33 +08:00
|
|
|
return res;
|
|
|
|
}
|