newlib/winsup/cygwin/fcntl.cc
Christopher Faylor 025c1fac6e Remove unneeded whitespace.
* fhandler_fifo.cc (fhandler_fifo::open): Rework to cause errno to be set to
ENXIO when opening a fifo write/nonblocking.
* environ.cc (ucreqenv): Rename to ucenv.  Move code from old ucenv here and
conditionalize it on create_upcaseenv.
(ucenv): Delete.
(environ_init): Fix compiler warning by moving create_upcaseenv test to ucenv.
Don't bother checking for child_proc_info when calling ucenv since it is
assumed to be NULL at the point where the function is called.
* path.cc (symlink_worker): Turn off MS-DOS path warnings when dealing with
devices since the device handler passes in a translated MS-DOS path.
* sec_auth.cc (lsaprivkeyauth): Avoid variable initialization which causes a
compiler error.
* fhandler_netdrive.cc: Update copyright.
2008-11-26 17:21:04 +00:00

99 lines
2.0 KiB
C++

/* fcntl.cc: fcntl syscall
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2008 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 <unistd.h>
#include "cygerrno.h"
#include "security.h"
#include "path.h"
#include "fhandler.h"
#include "dtable.h"
#include "cygheap.h"
#include "cygtls.h"
extern "C" int
fcntl64 (int fd, int cmd, ...)
{
int res = -1;
void *arg = NULL;
va_list args;
myfault efault;
if (efault.faulted (EFAULT))
return -1;
cygheap_fdget cfd (fd, true);
if (cfd < 0)
goto done;
va_start (args, cmd);
arg = va_arg (args, void *);
va_end (args);
switch (cmd)
{
case F_DUPFD:
res = dup2 (fd, cygheap_fdnew (((int) arg) - 1));
break;
case F_GETLK:
case F_SETLK:
case F_SETLKW:
{
struct __flock64 *fl = (struct __flock64 *) arg;
fl->l_type &= F_RDLCK | F_WRLCK | F_UNLCK;
res = cfd->lock (cmd, fl);
}
break;
default:
res = cfd->fcntl (cmd, arg);
break;
}
done:
syscall_printf ("%d = fcntl (%d, %d, %p)", res, fd, cmd, arg);
return res;
}
extern "C" int
_fcntl (int fd, int cmd, ...)
{
void *arg = NULL;
va_list args;
struct __flock32 *src = NULL;
struct __flock64 dst;
myfault efault;
if (efault.faulted (EFAULT))
return -1;
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 = fcntl64 (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;
}