newlib/winsup/cygwin/fcntl.cc
Corinna Vinschen dc3998682a * Makefile.in (OBSOLETE_FUNCTIONS): Add fcntl.
(NEW_FUNCTIONS): Add fcntl64.
	* cygwin.din: Export fcntl64.  Make fcntl being SIGFE.
	* fcntl.cc (fcntl_worker): New function.
	(fcntl64): New function.
	(_fcntl): Call fcntl_worker.  Convert 32 bit flock structure into
	64 bit flock structure and vice versa.
	* fhandler.cc (fhandler_base::lock): Change 2nd parameter to
	struct __flock64 *.
	* fhandler_disk_file.cc (fhandler_disk_file::lock): Ditto.  Rework
	to be 64 bit aware.
	* fhandler.h: Accomodate above method argument changes.
	* include/cygwin/types.h: Add struct __flock32 and __flock64.
	Define struct flock according to setting of __CYGWIN_USE_BIG_TYPES__.
	* include/cygwin/version.h: Bump API minor number.
2003-12-01 17:26:28 +00:00

86 lines
1.7 KiB
C++

/* fcntl.cc: fcntl syscall
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
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. */
#include "winsup.h"
#include <stdarg.h>
#include <unistd.h>
#include "security.h"
#include "path.h"
#include "fhandler.h"
#include "dtable.h"
#include "cygerrno.h"
#include "cygheap.h"
#include "thread.h"
static int
fcntl_worker (int fd, int cmd, void *arg)
{
int res;
cygheap_fdget cfd (fd, true);
if (cfd < 0)
{
res = -1;
goto done;
}
if (cmd != F_DUPFD)
res = cfd->fcntl(cmd, arg);
else
res = dup2 (fd, cygheap_fdnew (((int) arg) - 1));
done:
syscall_printf ("%d = fcntl (%d, %d, %p)", res, fd, cmd, arg);
return res;
}
extern "C" int
fcntl64 (int fd, int cmd,...)
{
void *arg = NULL;
va_list args;
va_start (args, cmd);
arg = va_arg (args, void *);
va_end (args);
return fcntl_worker (fd, cmd, arg);
}
extern "C" int
_fcntl (int fd, int cmd,...)
{
void *arg = NULL;
va_list args;
struct __flock32 *src;
struct __flock64 dst;
va_start (args, cmd);
arg = va_arg (args, void *);
va_end (args);
if (cmd == F_GETLK || cmd == F_SETLK || cmd == F_SETLKW)
{
src = (struct __flock32 *)arg;
dst.l_type = src->l_type;
dst.l_whence = src->l_whence;
dst.l_start = src->l_start;
dst.l_len = src->l_len;
dst.l_pid = src->l_pid;
arg = &dst;
}
int res = fcntl_worker (fd, cmd, arg);
if (cmd == F_GETLK)
{
src->l_type = dst.l_type;
src->l_whence = dst.l_whence;
src->l_start = dst.l_start;
src->l_len = dst.l_len;
src->l_pid = (short)dst.l_pid;
}
return res;
}