2000-02-17 20:38:33 +01:00
|
|
|
/* fcntl.cc: fcntl syscall
|
|
|
|
|
2002-06-05 06:01:43 +02:00
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
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 <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"
|
2001-10-01 06:10:07 +02:00
|
|
|
#include "path.h"
|
2000-08-12 07:35:42 +02:00
|
|
|
#include "dtable.h"
|
2000-08-22 05:58:47 +02:00
|
|
|
#include "cygerrno.h"
|
2001-10-16 01:39:33 +02:00
|
|
|
#include "cygheap.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-10-16 01:39:33 +02:00
|
|
|
cygheap_fdget cfd (fd, true);
|
|
|
|
if (cfd < 0)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
res = -1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2000-10-23 22:16:52 +02:00
|
|
|
va_start (args, cmd);
|
|
|
|
arg = va_arg (args, void *);
|
2001-10-16 01:39:33 +02:00
|
|
|
if (cmd != F_DUPFD)
|
|
|
|
res = cfd->fcntl(cmd, arg);
|
2000-10-23 22:16:52 +02:00
|
|
|
else
|
2001-10-16 05:31:50 +02:00
|
|
|
res = dup2 (fd, cygheap_fdnew (((int) arg) - 1));
|
2000-10-23 22:16:52 +02:00
|
|
|
va_end (args);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
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;
|
|
|
|
}
|