Use MPFR 4.2.0, MPC 1.3.1 in build-many-glibcs.py
[glibc.git] / termios / tcsetattr.c
blobad7fe3e404f05a69bc9a7fd1ede2c82d538707f3
1 /* Copyright (C) 1991-2023 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, see
16 <https://www.gnu.org/licenses/>. */
18 #include <errno.h>
19 #include <stddef.h>
20 #include <termios.h>
22 static int bad_speed (speed_t speed);
24 /* Set the state of FD to *TERMIOS_P. */
25 int
26 tcsetattr (int fd, int optional_actions, const struct termios *termios_p)
28 if (fd < 0)
30 __set_errno (EBADF);
31 return -1;
33 if (termios_p == NULL)
35 __set_errno (EINVAL);
36 return -1;
38 switch (optional_actions)
40 case TCSANOW:
41 case TCSADRAIN:
42 case TCSAFLUSH:
43 break;
44 default:
45 __set_errno (EINVAL);
46 return -1;
49 if (bad_speed(termios_p->__ospeed)
50 || bad_speed(termios_p->__ispeed == 0
51 ? termios_p->__ospeed : termios_p->__ispeed))
53 __set_errno (EINVAL);
54 return -1;
57 __set_errno (ENOSYS);
58 return -1;
60 libc_hidden_def (tcsetattr)
62 /* Strychnine checking. */
63 static int
64 bad_speed (speed_t speed)
66 switch (speed)
68 case B0:
69 case B50:
70 case B75:
71 case B110:
72 case B134:
73 case B150:
74 case B200:
75 case B300:
76 case B600:
77 case B1200:
78 case B1800:
79 case B2400:
80 case B4800:
81 case B9600:
82 case B19200:
83 case B38400:
84 case B57600:
85 case B115200:
86 case B230400:
87 case B460800:
88 case B500000:
89 case B576000:
90 case B921600:
91 case B1000000:
92 case B1152000:
93 case B1500000:
94 case B2000000:
95 case B2500000:
96 case B3000000:
97 case B3500000:
98 case B4000000:
99 return 0;
100 default:
101 return 1;
106 stub_warning (tcsetattr)