Debian Codegraph @

share/libc/termios.h

raw
1 /**************************************************************************/
2 /* */
3 /* This file is part of Frama-C. */
4 /* */
5 /* Copyright (C) 2007-2022 */
6 /* CEA (Commissariat à l'énergie atomique et aux énergies */
7 /* alternatives) */
8 /* */
9 /* you can redistribute it and/or modify it under the terms of the GNU */
10 /* Lesser General Public License as published by the Free Software */
11 /* Foundation, version 2.1. */
12 /* */
13 /* It is distributed in the hope that it will be useful, */
14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
16 /* GNU Lesser General Public License for more details. */
17 /* */
18 /* See the GNU Lesser General Public License version 2.1 */
19 /* for more details (enclosed in the file licenses/LGPLv2.1). */
20 /* */
21 /**************************************************************************/
22
23 /* POSIX header */
24
25 /* c_iflag bits */
26 #ifndef _TERMIOS_H
27 #define _TERMIOS_H
28 #include "features.h"
29 __PUSH_FC_STDLIB
30 #include "__fc_define_pid_t.h"
31
32 extern volatile int Frama_C_entropy_source;
33
34 #define IGNBRK 0000001
35 #define BRKINT 0000002
36 #define IGNPAR 0000004
37 #define PARMRK 0000010
38 #define INPCK 0000020
39 #define ISTRIP 0000040
40 #define INLCR 0000100
41 #define IGNCR 0000200
42 #define ICRNL 0000400
43 #define IUCLC 0001000
44 #define IXON 0002000
45 #define IXANY 0004000
46 #define IXOFF 0010000
47 #define IMAXBEL 0020000
48 #define IUTF8 0040000
49
50 /* c_oflag bits */
51 #define OPOST 0000001
52 #define OLCUC 0000002
53 #define ONLCR 0000004
54 #define OCRNL 0000010
55 #define ONOCR 0000020
56 #define ONLRET 0000040
57 #define OFILL 0000100
58 #define OFDEL 0000200
59
60 #define VTDLY 0040000
61 #define VT0 0000000
62 #define VT1 0040000
63
64 /* c_cflag bit meaning */
65 #define B0 0000000 /* hang up */
66 #define B50 0000001
67 #define B75 0000002
68 #define B110 0000003
69 #define B134 0000004
70 #define B150 0000005
71 #define B200 0000006
72 #define B300 0000007
73 #define B600 0000010
74 #define B1200 0000011
75 #define B1800 0000012
76 #define B2400 0000013
77 #define B4800 0000014
78 #define B9600 0000015
79 #define B19200 0000016
80 #define B38400 0000017
81 #define CSIZE 0000060
82 #define CS5 0000000
83 #define CS6 0000020
84 #define CS7 0000040
85 #define CS8 0000060
86 #define CSTOPB 0000100
87 #define CREAD 0000200
88 #define PARENB 0000400
89 #define PARODD 0001000
90 #define HUPCL 0002000
91 #define CLOCAL 0004000
92 #define B57600 0010001
93 #define B115200 0010002
94 #define B230400 0010003
95 #define B460800 0010004
96 #define B500000 0010005
97 #define B576000 0010006
98 #define B921600 0010007
99 #define B1000000 0010010
100 #define B1152000 0010011
101 #define B1500000 0010012
102 #define B2000000 0010013
103 #define B2500000 0010014
104 #define B3000000 0010015
105 #define B3500000 0010016
106 #define B4000000 0010017
107 #define __MAX_BAUD B4000000
108 /* c_lflag bits */
109 #define ISIG 0000001
110 #define ICANON 0000002
111 #define ECHO 0000010
112 #define ECHOE 0000020
113 #define ECHOK 0000040
114 #define ECHONL 0000100
115 #define NOFLSH 0000200
116 #define TOSTOP 0000400
117 #define IEXTEN 0001000
118
119 /* tcflow() and TCXONC use these */
120 #define TCOOFF 0
121 #define TCOON 1
122 #define TCIOFF 2
123 #define TCION 3
124
125 /* tcflush() and TCFLSH use these */
126 #define TCIFLUSH 0
127 #define TCOFLUSH 1
128 #define TCIOFLUSH 2
129
130 /* tcsetattr uses these */
131 #define TCSANOW 0
132 #define TCSADRAIN 1
133 #define TCSAFLUSH 2
134
135 __BEGIN_DECLS
136
137 typedef unsigned int tcflag_t;
138 typedef unsigned char cc_t;
139 typedef unsigned int speed_t;
140
141 __END_DECLS
142
143 // cc_c characters
144 #define NCCS 32
145 #define VINTR 0
146 #define VQUIT 1
147 #define VERASE 2
148 #define VKILL 3
149 #define VEOF 4
150 #define VTIME 5
151 #define VMIN 6
152 #define VSWTC 7
153 #define VSTART 8
154 #define VSTOP 9
155 #define VSUSP 10
156 #define VEOL 11
157 #define VREPRINT 12
158 #define VDISCARD 13
159 #define VWERASE 14
160 #define VLNEXT 15
161 #define VEOL2 16
162
163 __BEGIN_DECLS
164
165 struct termios {
166 tcflag_t c_iflag; /* input specific flags (bitmask) */
167 tcflag_t c_oflag; /* output specific flags (bitmask) */
168 tcflag_t c_cflag; /* control flags (bitmask) */
169 tcflag_t c_lflag; /* local flags (bitmask) */
170 cc_t c_cc[NCCS]; /* special characters */
171 };
172
173 /*@
174 requires valid_termios_p: \valid_read(termios_p);
175 assigns \result \from indirect:termios_p, *termios_p;
176 // missing ensures result_is_valid_speed: speed \in {valid baud rates};
177 */
178 extern speed_t cfgetispeed(const struct termios *termios_p);
179
180 /*@
181 requires valid_termios_p: \valid_read(termios_p);
182 assigns \result \from indirect:termios_p, *termios_p;
183 // missing ensures result_is_valid_speed: speed \in {valid baud rates};
184 */
185 extern speed_t cfgetospeed(const struct termios *termios_p);
186
187 /*@
188 // missing requires valid_speed: speed \in {valid baud rates};
189 requires valid_termios_p: \valid(termios_p);
190 assigns \result, *termios_p \from indirect:termios_p, speed;
191 ensures result_ok_or_error: \result == 0 || \result == -1;
192 */
193 extern int cfsetispeed(struct termios *termios_p, speed_t speed);
194
195 /*@
196 // missing requires valid_speed: speed \in {valid baud rates};
197 requires valid_termios_p: \valid(termios_p);
198 assigns \result, *termios_p \from indirect:termios_p, speed;
199 ensures result_ok_or_error: \result == 0 || \result == -1;
200 */
201 extern int cfsetospeed(struct termios *termios_p, speed_t speed);
202
203 extern int tcdrain(int);
204 extern int tcflow(int, int);
205
206 /*@
207 // missing requires valid_fd: {fd is an open file descriptor
208 // associated with a terminal};
209 requires valid_queue_selector: queue_selector == TCIFLUSH
210 || queue_selector == TCOFLUSH
211 || queue_selector == TCIOFLUSH;
212 assigns \result \from indirect:fd, indirect:queue_selector,
213 indirect:Frama_C_entropy_source;
214 assigns Frama_C_entropy_source \from Frama_C_entropy_source;
215 ensures result_ok_or_error: \result == 0 || \result == -1;
216 */
217 extern int tcflush(int fd, int queue_selector);
218
219 /*@ requires valid_termios_p: \valid(termios_p);
220 assigns \result, *termios_p \from indirect:fd,
221 indirect:Frama_C_entropy_source;
222 assigns Frama_C_entropy_source \from Frama_C_entropy_source;
223 behavior ok:
224 assumes nondet: Frama_C_entropy_source == 0; // arbitrary condition
225 ensures initialization:termios_p: \initialized(termios_p);
226 ensures result_ok: \result == 0;
227 behavior error:
228 assumes nondet: Frama_C_entropy_source != 0; // arbitrary condition
229 ensures result_error: \result == -1;
230 disjoint behaviors;
231 complete behaviors;
232 */
233 extern int tcgetattr(int fd, struct termios *termios_p);
234
235 extern pid_t tcgetsid(int);
236 extern int tcsendbreak(int, int);
237
238 /*@
239 requires valid_termios_p: \valid(termios_p);
240 assigns *termios_p \from indirect:fd, indirect:optional_actions,
241 indirect:Frama_C_entropy_source, *termios_p;
242 assigns Frama_C_entropy_source \from Frama_C_entropy_source;
243 assigns \result \from indirect:fd, indirect:optional_actions,
244 indirect:Frama_C_entropy_source,
245 indirect:*termios_p;
246 ensures result_ok_or_error: \result == 0 || \result == -1;
247 */
248 extern int tcsetattr(int fd, int optional_actions, struct termios *termios_p);
249
250 __END_DECLS
251
252 __POP_FC_STDLIB
253 #endif