2000-02-17 20:38:33 +01: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-02 18:28:18 +02:00
|
|
|
#include "winsup.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
2001-07-26 21:22:24 +02:00
|
|
|
#include "security.h"
|
2000-08-22 07:10:20 +02:00
|
|
|
#include "fhandler.h"
|
2000-08-12 07:35:42 +02:00
|
|
|
#include "dtable.h"
|
2001-04-18 23:10:15 +02:00
|
|
|
#include "cygheap.h"
|
2000-08-22 05:58:47 +02:00
|
|
|
#include "cygerrno.h"
|
2000-08-22 07:10:20 +02:00
|
|
|
#include "thread.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
extern "C"
|
|
|
|
int
|
|
|
|
_fcntl (int fd, int cmd,...)
|
|
|
|
{
|
2000-10-23 22:16:52 +02:00
|
|
|
void *arg = NULL;
|
2000-02-17 20:38:33 +01:00
|
|
|
va_list args;
|
|
|
|
int res;
|
|
|
|
|
2001-04-18 23:10:15 +02:00
|
|
|
if (cygheap->fdtab.not_open (fd))
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
set_errno (EBADF);
|
|
|
|
res = -1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2000-10-23 22:16:52 +02: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-18 23:10:15 +02:00
|
|
|
res = dup2 (fd, cygheap->fdtab.find_unused_handle ((int) arg));
|
2000-10-23 22:16:52 +02:00
|
|
|
else
|
2001-04-18 23:10:15 +02:00
|
|
|
res = cygheap->fdtab[fd]->fcntl(cmd, arg);
|
2000-10-23 22:16:52 +02:00
|
|
|
va_end (args);
|
2000-02-17 20:38:33 +01:00
|
|
|
ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"_fcntl");
|
|
|
|
|
2000-10-23 22:16:52 +02:00
|
|
|
done:
|
|
|
|
syscall_printf ("%d = fcntl (%d, %d, %p)", res, fd, cmd, arg);
|
2000-02-17 20:38:33 +01:00
|
|
|
return res;
|
|
|
|
}
|