Cygwin: flock: Fix overlap handling in lf_setlock() and lf_clearlock()
[newlib-cygwin.git] / winsup / cygwin / ioctl.cc
blob242ef60cd6d4fed169c6747baf603bc8997fb35c
1 /* ioctl.cc: ioctl routines.
3 Written by Doug Evans of Cygnus Support
4 dje@cygnus.com
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
10 details. */
12 #include "winsup.h"
13 #include "cygerrno.h"
14 #include "path.h"
15 #include "fhandler.h"
16 #include "dtable.h"
17 #include "cygheap.h"
19 extern "C" int
20 ioctl (int fd, int cmd, ...)
23 cygheap_fdget cfd (fd);
24 if (cfd < 0)
25 return -1;
27 /* check for optional mode argument */
28 va_list ap;
29 va_start (ap, cmd);
30 char *argp = va_arg (ap, char *);
31 va_end (ap);
33 debug_printf ("ioctl(fd %d, cmd %y)", fd, cmd);
34 int res;
35 if (cfd->get_flags () & O_PATH)
37 set_errno (EBADF);
38 return -1;
40 /* FIXME: This stinks. There are collisions between cmd types
41 depending on whether fd is associated with a pty master or not.
42 Something to fix for Cygwin2. CGF 2006-06-04 */
43 if (cfd->is_tty () && cfd->get_major () != DEV_PTYM_MAJOR)
44 switch (cmd)
46 case TCGETA:
47 res = tcgetattr (fd, (struct termios *) argp);
48 goto out;
49 case TCSETA:
50 res = tcsetattr (fd, TCSANOW, (struct termios *) argp);
51 goto out;
52 case TCSETAW:
53 res = tcsetattr (fd, TCSADRAIN, (struct termios *) argp);
54 goto out;
55 case TCSETAF:
56 res = tcsetattr (fd, TCSAFLUSH, (struct termios *) argp);
57 goto out;
60 res = cfd->ioctl (cmd, argp);
62 out:
63 syscall_printf ("%R = ioctl(%d, %y, ...)", res, fd, cmd);
64 return res;