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