1 /* fcntl.cc: fcntl syscall
3 This file is part of Cygwin.
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
20 fcntl (int fd
, int cmd
, ...)
26 pthread_testcancel ();
31 debug_printf ("fcntl(%d, %d, ...)", fd
, cmd
);
33 /* Don't lock the fd table when performing locking calls. */
34 cygheap_fdget
cfd (fd
, cmd
< F_GETLK
|| cmd
> F_SETLKW
);
38 /* FIXME? All numerical args to fcntl are defined as long on Linux.
39 This relies on a really dirty trick on x86_64: A 32 bit mov to
40 a register (e.g. mov $1, %edx) always sets the high 32 bit to 0.
41 We're following the Linux lead here since the third arg to any
42 function is in a register anyway (%r8 in MS ABI). That's the easy
43 case which is covered here by always reading the arg with
44 sizeof (intptr_t) == sizeof (long) == sizeof (void*) which matches
47 However, the POSIX standard defines all numerical args as type int.
48 If we take that literally, we had a (small) problem on 64 bit, since
49 sizeof (void*) != sizeof (int). If we would like to follow POSIX more
50 closely than Linux, we'd have to call va_arg on a per cmd basis. */
53 arg
= va_arg (args
, intptr_t);
60 if (arg
>= 0 && arg
< OPEN_MAX
)
62 int flags
= cmd
== F_DUPFD_CLOEXEC
? O_CLOEXEC
: 0;
63 res
= cygheap
->fdtab
.dup3 (fd
, cygheap_fdnew ((arg
) - 1), flags
);
72 res
= cfd
->fcntl (cmd
, arg
);
78 syscall_printf ("%R = fcntl(%d, %d, %ly)", res
, fd
, cmd
, arg
);
82 EXPORT_ALIAS (fcntl
, _fcntl
)