2.9
[glibc/nacl-glibc.git] / sysdeps / unix / sysv / linux / tcsetattr.c
blobf73ec8883e61dee19ed349c6a64170dfefb59130
1 /* Copyright (C) 1993,1996,1997,1998,2002,2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
19 #include <errno.h>
20 #include <string.h>
21 #include <termios.h>
22 #include <sys/ioctl.h>
23 #include <sys/types.h>
24 #include <sysdep.h>
26 /* The difference here is that the termios structure used in the
27 kernel is not the same as we use in the libc. Therefore we must
28 translate it here. */
29 #include <kernel_termios.h>
32 /* This is a gross hack around a kernel bug. If the cfsetispeed functions
33 is called with the SPEED argument set to zero this means use the same
34 speed as for output. But we don't have independent input and output
35 speeds and therefore cannot record this.
37 We use an unused bit in the `c_iflag' field to keep track of this
38 use of `cfsetispeed'. The value here must correspond to the one used
39 in `speed.c'. */
40 #define IBAUD0 020000000000
43 /* Set the state of FD to *TERMIOS_P. */
44 int
45 tcsetattr (fd, optional_actions, termios_p)
46 int fd;
47 int optional_actions;
48 const struct termios *termios_p;
50 struct __kernel_termios k_termios;
51 unsigned long int cmd;
53 switch (optional_actions)
55 case TCSANOW:
56 cmd = TCSETS;
57 break;
58 case TCSADRAIN:
59 cmd = TCSETSW;
60 break;
61 case TCSAFLUSH:
62 cmd = TCSETSF;
63 break;
64 default:
65 __set_errno (EINVAL);
66 return -1;
69 k_termios.c_iflag = termios_p->c_iflag & ~IBAUD0;
70 k_termios.c_oflag = termios_p->c_oflag;
71 k_termios.c_cflag = termios_p->c_cflag;
72 k_termios.c_lflag = termios_p->c_lflag;
73 k_termios.c_line = termios_p->c_line;
74 #if defined _HAVE_C_ISPEED && defined _HAVE_STRUCT_TERMIOS_C_ISPEED
75 k_termios.c_ispeed = termios_p->c_ispeed;
76 #endif
77 #if defined _HAVE_C_OSPEED && defined _HAVE_STRUCT_TERMIOS_C_OSPEED
78 k_termios.c_ospeed = termios_p->c_ospeed;
79 #endif
80 memcpy (&k_termios.c_cc[0], &termios_p->c_cc[0],
81 __KERNEL_NCCS * sizeof (cc_t));
83 return INLINE_SYSCALL (ioctl, 3, fd, cmd, &k_termios);
85 libc_hidden_def (tcsetattr)