OSDN Git Service

* globals.cc (enum exit_states::ES_GLOBAL_DTORS): Delete.
[pf3gnuchains/pf3gnuchains4x.git] / winsup / cygwin / ioctl.cc
1 /* ioctl.cc: ioctl routines.
2
3    Copyright 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2006, 2008, 2009
4    Red Hat, Inc.
5
6    Written by Doug Evans of Cygnus Support
7    dje@cygnus.com
8
9 This file is part of Cygwin.
10
11 This software is a copyrighted work licensed under the terms of the
12 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
13 details. */
14
15 #include "winsup.h"
16 #include "cygerrno.h"
17 #include "path.h"
18 #include "fhandler.h"
19 #include "dtable.h"
20 #include "cygheap.h"
21
22 extern "C" int
23 ioctl (int fd, int cmd, ...)
24 {
25
26   cygheap_fdget cfd (fd);
27   if (cfd < 0)
28     return -1;
29
30   /* check for optional mode argument */
31   va_list ap;
32   va_start (ap, cmd);
33   char *argp = va_arg (ap, char *);
34   va_end (ap);
35
36   debug_printf ("fd %d, cmd %x", fd, cmd);
37   int res;
38   /* FIXME: This stinks.  There are collisions between cmd types
39      depending on whether fd is associated with a pty master or not.
40      Something to fix for Cygwin2.  CGF 2006-06-04 */
41   if (cfd->is_tty () && cfd->get_major () != DEV_TTYM_MAJOR)
42     switch (cmd)
43       {
44         case TCGETA:
45           res = tcgetattr (fd, (struct termios *) argp);
46           goto out;
47         case TCSETA:
48           res = tcsetattr (fd, TCSANOW, (struct termios *) argp);
49           goto out;
50         case TCSETAW:
51           res = tcsetattr (fd, TCSADRAIN, (struct termios *) argp);
52           goto out;
53         case TCSETAF:
54           res = tcsetattr (fd, TCSAFLUSH, (struct termios *) argp);
55           goto out;
56       }
57
58   res = cfd->ioctl (cmd, argp);
59
60 out:
61   debug_printf ("returning %d", res);
62   return res;
63 }