]> granicus.if.org Git - strace/blob - term.c
Automated removal of non-Linux code
[strace] / term.c
1 /*
2  * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  *      $Id$
28  */
29
30 #include "defs.h"
31
32 /*
33  * The C library's definition of struct termios might differ from
34  * the kernel one, and we need to use the kernel layout.
35  */
36 #include <linux/termios.h>
37
38 #ifdef HAVE_SYS_FILIO_H
39 #include <sys/filio.h>
40 #endif
41
42 static const struct xlat tcxonc_options[] = {
43         { TCOOFF,       "TCOOFF"        },
44         { TCOON,        "TCOON"         },
45         { TCIOFF,       "TCIOFF"        },
46         { TCION,        "TCION"         },
47         { 0,            NULL            },
48 };
49
50 #ifdef TCLFLSH
51 static const struct xlat tcflsh_options[] = {
52         { TCIFLUSH,     "TCIFLUSH"      },
53         { TCOFLUSH,     "TCOFLUSH"      },
54         { TCIOFLUSH,    "TCIOFLUSH"     },
55         { 0,            NULL            },
56 };
57 #endif
58
59 static const struct xlat baud_options[] = {
60         { B0,           "B0"            },
61         { B50,          "B50"           },
62         { B75,          "B75"           },
63         { B110,         "B110"          },
64         { B134,         "B134"          },
65         { B150,         "B150"          },
66         { B200,         "B200"          },
67         { B300,         "B300"          },
68         { B600,         "B600"          },
69         { B1200,        "B1200"         },
70         { B1800,        "B1800"         },
71         { B2400,        "B2400"         },
72         { B4800,        "B4800"         },
73         { B9600,        "B9600"         },
74 #ifdef B19200
75         { B19200,       "B19200"        },
76 #endif
77 #ifdef B38400
78         { B38400,       "B38400"        },
79 #endif
80 #ifdef B57600
81         { B57600,       "B57600"        },
82 #endif
83 #ifdef B115200
84         { B115200,      "B115200"       },
85 #endif
86 #ifdef B230400
87         { B230400,      "B230400"       },
88 #endif
89 #ifdef B460800
90         { B460800,      "B460800"       },
91 #endif
92 #ifdef B500000
93         { B500000,      "B500000"       },
94 #endif
95 #ifdef B576000
96         { B576000,      "B576000"       },
97 #endif
98 #ifdef B921600
99         { B921600,      "B921600"       },
100 #endif
101 #ifdef B1000000
102         { B1000000,     "B1000000"      },
103 #endif
104 #ifdef B1152000
105         { B1152000,     "B1152000"      },
106 #endif
107 #ifdef B1500000
108         { B1500000,     "B1500000"      },
109 #endif
110 #ifdef B2000000
111         { B2000000,     "B2000000"      },
112 #endif
113 #ifdef B2500000
114         { B2500000,     "B2500000"      },
115 #endif
116 #ifdef B3000000
117         { B3000000,     "B3000000"      },
118 #endif
119 #ifdef B3500000
120         { B3500000,     "B3500000"      },
121 #endif
122 #ifdef B4000000
123         { B4000000,     "B4000000"      },
124 #endif
125 #ifdef EXTA
126         { EXTA,         "EXTA"          },
127 #endif
128 #ifdef EXTB
129         { EXTB,         "EXTB"          },
130 #endif
131         { 0,            NULL            },
132 };
133
134 static const struct xlat modem_flags[] = {
135 #ifdef TIOCM_LE
136         { TIOCM_LE,     "TIOCM_LE",     },
137 #endif
138 #ifdef TIOCM_DTR
139         { TIOCM_DTR,    "TIOCM_DTR",    },
140 #endif
141 #ifdef TIOCM_RTS
142         { TIOCM_RTS,    "TIOCM_RTS",    },
143 #endif
144 #ifdef TIOCM_ST
145         { TIOCM_ST,     "TIOCM_ST",     },
146 #endif
147 #ifdef TIOCM_SR
148         { TIOCM_SR,     "TIOCM_SR",     },
149 #endif
150 #ifdef TIOCM_CTS
151         { TIOCM_CTS,    "TIOCM_CTS",    },
152 #endif
153 #ifdef TIOCM_CAR
154         { TIOCM_CAR,    "TIOCM_CAR",    },
155 #endif
156 #ifdef TIOCM_CD
157         { TIOCM_CD,     "TIOCM_CD",     },
158 #endif
159 #ifdef TIOCM_RNG
160         { TIOCM_RNG,    "TIOCM_RNG",    },
161 #endif
162 #ifdef TIOCM_RI
163         { TIOCM_RI,     "TIOCM_RI",     },
164 #endif
165 #ifdef TIOCM_DSR
166         { TIOCM_DSR,    "TIOCM_DSR",    },
167 #endif
168         { 0,            NULL,           },
169 };
170
171
172 int term_ioctl(struct tcb *tcp, long code, long arg)
173 {
174         struct termios tios;
175         struct termio tio;
176         struct winsize ws;
177 #ifdef TIOCGSIZE
178         struct  ttysize ts;
179 #endif
180         int i;
181
182         if (entering(tcp))
183                 return 0;
184
185         switch (code) {
186
187         /* ioctls with termios or termio args */
188
189 #ifdef TCGETS
190         case TCGETS:
191                 if (syserror(tcp))
192                         return 0;
193         case TCSETS:
194         case TCSETSW:
195         case TCSETSF:
196                 if (!verbose(tcp) || umove(tcp, arg, &tios) < 0)
197                         return 0;
198                 if (abbrev(tcp)) {
199                         tprints(", {");
200                         printxval(baud_options, tios.c_cflag & CBAUD, "B???");
201                         tprintf(" %sopost %sisig %sicanon %secho ...}",
202                                 (tios.c_oflag & OPOST) ? "" : "-",
203                                 (tios.c_lflag & ISIG) ? "" : "-",
204                                 (tios.c_lflag & ICANON) ? "" : "-",
205                                 (tios.c_lflag & ECHO) ? "" : "-");
206                         return 1;
207                 }
208                 tprintf(", {c_iflags=%#lx, c_oflags=%#lx, ",
209                         (long) tios.c_iflag, (long) tios.c_oflag);
210                 tprintf("c_cflags=%#lx, c_lflags=%#lx, ",
211                         (long) tios.c_cflag, (long) tios.c_lflag);
212                 tprintf("c_line=%u, ", tios.c_line);
213                 if (!(tios.c_lflag & ICANON))
214                         tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ",
215                                 tios.c_cc[VMIN], tios.c_cc[VTIME]);
216                 tprintf("c_cc=\"");
217                 for (i = 0; i < NCCS; i++)
218                         tprintf("\\x%02x", tios.c_cc[i]);
219                 tprintf("\"}");
220                 return 1;
221 #endif /* TCGETS */
222
223 #ifdef TCGETA
224         case TCGETA:
225                 if (syserror(tcp))
226                         return 0;
227         case TCSETA:
228         case TCSETAW:
229         case TCSETAF:
230                 if (!verbose(tcp) || umove(tcp, arg, &tio) < 0)
231                         return 0;
232                 if (abbrev(tcp)) {
233                         tprints(", {");
234                         printxval(baud_options, tio.c_cflag & CBAUD, "B???");
235                         tprintf(" %sopost %sisig %sicanon %secho ...}",
236                                 (tio.c_oflag & OPOST) ? "" : "-",
237                                 (tio.c_lflag & ISIG) ? "" : "-",
238                                 (tio.c_lflag & ICANON) ? "" : "-",
239                                 (tio.c_lflag & ECHO) ? "" : "-");
240                         return 1;
241                 }
242                 tprintf(", {c_iflags=%#lx, c_oflags=%#lx, ",
243                         (long) tio.c_iflag, (long) tio.c_oflag);
244                 tprintf("c_cflags=%#lx, c_lflags=%#lx, ",
245                         (long) tio.c_cflag, (long) tio.c_lflag);
246                 tprintf("c_line=%u, ", tio.c_line);
247 #ifdef _VMIN
248                 if (!(tio.c_lflag & ICANON))
249                         tprintf("c_cc[_VMIN]=%d, c_cc[_VTIME]=%d, ",
250                                 tio.c_cc[_VMIN], tio.c_cc[_VTIME]);
251 #else /* !_VMIN */
252                 if (!(tio.c_lflag & ICANON))
253                         tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ",
254                                 tio.c_cc[VMIN], tio.c_cc[VTIME]);
255 #endif /* !_VMIN */
256                 tprintf("c_cc=\"");
257                 for (i = 0; i < NCC; i++)
258                         tprintf("\\x%02x", tio.c_cc[i]);
259                 tprintf("\"}");
260                 return 1;
261 #endif /* TCGETA */
262
263         /* ioctls with winsize or ttysize args */
264
265 #ifdef TIOCGWINSZ
266         case TIOCGWINSZ:
267                 if (syserror(tcp))
268                         return 0;
269         case TIOCSWINSZ:
270                 if (!verbose(tcp) || umove(tcp, arg, &ws) < 0)
271                         return 0;
272                 tprintf(", {ws_row=%d, ws_col=%d, ws_xpixel=%d, ws_ypixel=%d}",
273                         ws.ws_row, ws.ws_col, ws.ws_xpixel, ws.ws_ypixel);
274                 return 1;
275 #endif /* TIOCGWINSZ */
276
277 #ifdef TIOCGSIZE
278         case TIOCGSIZE:
279                 if (syserror(tcp))
280                         return 0;
281         case TIOCSSIZE:
282                 if (!verbose(tcp) || umove(tcp, arg, &ts) < 0)
283                         return 0;
284                 tprintf(", {ts_lines=%d, ts_cols=%d}",
285                         ts.ts_lines, ts.ts_cols);
286                 return 1;
287 #endif
288
289         /* ioctls with a direct decodable arg */
290 #ifdef TCXONC
291         case TCXONC:
292                 tprints(", ");
293                 printxval(tcxonc_options, arg, "TC???");
294                 return 1;
295 #endif
296 #ifdef TCLFLSH
297         case TCFLSH:
298                 tprints(", ");
299                 printxval(tcflsh_options, arg, "TC???");
300                 return 1;
301 #endif
302 #ifdef TIOCSCTTY
303         case TIOCSCTTY:
304                 tprintf(", %ld", arg);
305                 return 1;
306 #endif
307
308         /* ioctls with an indirect parameter displayed as modem flags */
309
310 #ifdef TIOCMGET
311         case TIOCMGET:
312         case TIOCMBIS:
313         case TIOCMBIC:
314         case TIOCMSET:
315                 if (umove(tcp, arg, &i) < 0)
316                         return 0;
317                 tprints(", [");
318                 printflags(modem_flags, i, "TIOCM_???");
319                 tprints("]");
320                 return 1;
321 #endif /* TIOCMGET */
322
323         /* ioctls with an indirect parameter displayed in decimal */
324
325         case TIOCSPGRP:
326         case TIOCGPGRP:
327 #ifdef TIOCGETPGRP
328         case TIOCGETPGRP:
329 #endif
330 #ifdef TIOCSETPGRP
331         case TIOCSETPGRP:
332 #endif
333 #ifdef FIONREAD
334         case FIONREAD:
335 #endif
336         case TIOCOUTQ:
337 #ifdef FIONBIO
338         case FIONBIO:
339 #endif
340 #ifdef FIOASYNC
341         case FIOASYNC:
342 #endif
343 #ifdef FIOGETOWN
344         case FIOGETOWN:
345 #endif
346 #ifdef FIOSETOWN
347         case FIOSETOWN:
348 #endif
349 #ifdef TIOCGETD
350         case TIOCGETD:
351 #endif
352 #ifdef TIOCSETD
353         case TIOCSETD:
354 #endif
355 #ifdef TIOCPKT
356         case TIOCPKT:
357 #endif
358 #ifdef TIOCREMOTE
359         case TIOCREMOTE:
360 #endif
361 #ifdef TIOCUCNTL
362         case TIOCUCNTL:
363 #endif
364 #ifdef TIOCTCNTL
365         case TIOCTCNTL:
366 #endif
367 #ifdef TIOCSIGNAL
368         case TIOCSIGNAL:
369 #endif
370 #ifdef TIOCSSOFTCAR
371         case TIOCSSOFTCAR:
372 #endif
373 #ifdef TIOCGSOFTCAR
374         case TIOCGSOFTCAR:
375 #endif
376 #ifdef TIOCISPACE
377         case TIOCISPACE:
378 #endif
379 #ifdef TIOCISIZE
380         case TIOCISIZE:
381 #endif
382 #ifdef TIOCSINTR
383         case TIOCSINTR:
384 #endif
385 #ifdef TIOCSPTLCK
386         case TIOCSPTLCK:
387 #endif
388 #ifdef TIOCGPTN
389         case TIOCGPTN:
390 #endif
391                 tprints(", ");
392                 printnum_int(tcp, arg, "%d");
393                 return 1;
394
395         /* ioctls with an indirect parameter displayed as a char */
396
397 #ifdef TIOCSTI
398         case TIOCSTI:
399 #endif
400                 tprints(", ");
401                 printstr(tcp, arg, 1);
402                 return 1;
403
404         /* ioctls with no parameters */
405
406 #ifdef TIOCNOTTY
407         case TIOCNOTTY:
408 #endif
409 #ifdef FIOCLEX
410         case FIOCLEX:
411 #endif
412 #ifdef FIONCLEX
413         case FIONCLEX:
414 #endif
415 #ifdef TIOCCONS
416         case TIOCCONS:
417 #endif
418                 return 1;
419
420         /* ioctls which are unknown */
421
422         default:
423                 return 0;
424         }
425 }