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