|
|
1 | /* |
|
|
2 | * consoletype.c |
|
|
3 | * simple app to figure out whether the current terminal |
|
|
4 | * is serial, console (vt), or remote (pty). |
|
|
5 | * |
|
|
6 | * Copyright 1999-2004 Gentoo Foundation |
|
|
7 | * Distributed under the terms of the GNU General Public License v2 |
|
|
8 | * $Header$ |
|
|
9 | */ |
|
|
10 | |
| 1 | #include <stdio.h> |
11 | #include <stdio.h> |
| 2 | #include <string.h> |
12 | #include <string.h> |
| 3 | #include <sys/ioctl.h> |
13 | #include <sys/ioctl.h> |
| 4 | #include <sys/stat.h> |
14 | #include <sys/stat.h> |
| 5 | #include <sys/sysmacros.h> |
15 | #include <sys/sysmacros.h> |
| 6 | |
16 | |
| 7 | int main(int argc, char **argv) |
17 | int main(int argc, char *argv[]) |
| 8 | { |
18 | { |
| 9 | unsigned char twelve = 12; |
19 | unsigned char twelve = 12; |
| 10 | int maj; |
20 | int maj; |
| 11 | struct stat sb; |
21 | struct stat sb; |
| 12 | |
22 | |
| 13 | fstat(0, &sb); |
23 | fstat(0, &sb); |
| 14 | maj = major(sb.st_rdev); |
24 | maj = major(sb.st_rdev); |
| 15 | if (maj != 3 && (maj < 136 || maj > 143)) { |
25 | if (maj != 3 && (maj < 136 || maj > 143)) { |
| 16 | if (ioctl (0, TIOCLINUX, &twelve) < 0) { |
26 | if (ioctl (0, TIOCLINUX, &twelve) < 0) { |
| 17 | printf ("serial\n"); |
27 | printf("serial\n"); |
| 18 | return 1; |
28 | return 1; |
|
|
29 | } else { |
|
|
30 | printf("vt\n"); |
|
|
31 | return 0; |
|
|
32 | } |
| 19 | } else { |
33 | } else { |
| 20 | printf ("vt\n"); |
34 | printf("pty\n"); |
| 21 | return 0; |
35 | return 2; |
| 22 | } |
36 | } |
| 23 | } else { |
37 | } |
| 24 | printf ("pty\n"); |
|
|
| 25 | return 2; |
|
|
| 26 | } |
|
|
| 27 | } |
|
|