]>
Commit | Line | Data |
---|---|---|
d614a753 | 1 | /* Copyright (C) 1991-2020 Free Software Foundation, Inc. |
6d52618b | 2 | This file is part of the GNU C Library. |
28f540f4 | 3 | |
6d52618b | 4 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
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. | |
28f540f4 | 8 | |
6d52618b UD |
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 | |
41bdb6e2 | 12 | Lesser General Public License for more details. |
28f540f4 | 13 | |
41bdb6e2 | 14 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 15 | License along with the GNU C Library; if not, see |
5a82c748 | 16 | <https://www.gnu.org/licenses/>. */ |
28f540f4 | 17 | |
28f540f4 RM |
18 | #include <errno.h> |
19 | #include <stddef.h> | |
20 | #include <termios.h> | |
21 | ||
bcaad6ee | 22 | static int bad_speed (speed_t speed); |
28f540f4 RM |
23 | |
24 | /* Set the state of FD to *TERMIOS_P. */ | |
25 | int | |
bcaad6ee | 26 | tcsetattr (int fd, int optional_actions, const struct termios *termios_p) |
28f540f4 RM |
27 | { |
28 | if (fd < 0) | |
29 | { | |
c4029823 | 30 | __set_errno (EBADF); |
28f540f4 RM |
31 | return -1; |
32 | } | |
33 | if (termios_p == NULL) | |
34 | { | |
c4029823 | 35 | __set_errno (EINVAL); |
28f540f4 RM |
36 | return -1; |
37 | } | |
38 | switch (optional_actions) | |
39 | { | |
40 | case TCSANOW: | |
41 | case TCSADRAIN: | |
42 | case TCSAFLUSH: | |
43 | break; | |
44 | default: | |
c4029823 | 45 | __set_errno (EINVAL); |
28f540f4 RM |
46 | return -1; |
47 | } | |
48 | ||
34a5a146 JM |
49 | if (bad_speed(termios_p->__ospeed) |
50 | || bad_speed(termios_p->__ispeed == 0 | |
51 | ? termios_p->__ospeed : termios_p->__ispeed)) | |
28f540f4 | 52 | { |
c4029823 | 53 | __set_errno (EINVAL); |
28f540f4 RM |
54 | return -1; |
55 | } | |
56 | ||
c4029823 | 57 | __set_errno (ENOSYS); |
28f540f4 RM |
58 | return -1; |
59 | } | |
df962917 | 60 | libc_hidden_def (tcsetattr) |
28f540f4 | 61 | |
6d52618b | 62 | /* Strychnine checking. */ |
28f540f4 | 63 | static int |
bcaad6ee | 64 | bad_speed (speed_t speed) |
28f540f4 RM |
65 | { |
66 | switch (speed) | |
67 | { | |
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: | |
15c64502 RM |
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: | |
28f540f4 RM |
99 | return 0; |
100 | default: | |
101 | return 1; | |
102 | } | |
103 | } | |
104 | ||
105 | ||
3f33a4ce | 106 | stub_warning (tcsetattr) |