1 /* fcntl.cc: fcntl syscall
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2008,
4 2009, 2010, 2011 Red Hat, Inc.
6 This file is part of Cygwin.
8 This software is a copyrighted work licensed under the terms of the
9 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
23 fcntl64 (int fd, int cmd, ...)
29 pthread_testcancel ();
32 if (efault.faulted (EFAULT))
35 cygheap_fdget cfd (fd, true);
40 arg = va_arg (args, void *);
47 if ((int) arg >= 0 && (int) arg < OPEN_MAX_MAX)
48 res = dup3 (fd, cygheap_fdnew (((int) arg) - 1),
49 cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
60 struct __flock64 *fl = (struct __flock64 *) arg;
61 fl->l_type &= F_RDLCK | F_WRLCK | F_UNLCK;
62 res = cfd->lock (cmd, fl);
66 res = cfd->fcntl (cmd, arg);
70 syscall_printf ("%R = fcntl(%d, %d, %p)", res, fd, cmd, arg);
75 _fcntl (int fd, int cmd, ...)
79 struct __flock32 *src = NULL;
83 if (efault.faulted (EFAULT))
87 arg = va_arg (args, void *);
89 if (cmd == F_GETLK || cmd == F_SETLK || cmd == F_SETLKW)
91 src = (struct __flock32 *) arg;
92 dst.l_type = src->l_type;
93 dst.l_whence = src->l_whence;
94 dst.l_start = src->l_start;
95 dst.l_len = src->l_len;
96 dst.l_pid = src->l_pid;
99 int res = fcntl64 (fd, cmd, arg);
102 src->l_type = dst.l_type;
103 src->l_whence = dst.l_whence;
104 src->l_start = dst.l_start;
105 src->l_len = dst.l_len;
106 src->l_pid = (short) dst.l_pid;