aboutsummaryrefslogtreecommitdiffstats
path: root/src/consoletype.c
blob: 40b20ab0f44fcc442cb024a0e7dd2951708ac662 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>

int main(int argc, char **argv)
{
    unsigned char twelve = 12;
    char *type;
    int maj, min, ret = 0, fg = -1;
    struct stat sb;
	
    fstat(0, &sb);
    maj = major(sb.st_rdev);
    min = minor(sb.st_rdev);
    if (maj != 3 && (maj < 136 || maj > 143)) {
	if ((fg = ioctl (0, TIOCLINUX, &twelve)) < 0) {
	    type = "serial";
	    ret = 1;
	} else {
#ifdef __powerpc__
	    int fd;
	    char buf[65536];
	    
	    fd = open("/proc/tty/drivers",O_RDONLY);
	    read(fd, buf, 65535);
	    if (strstr(buf,"vioconsole           /dev/tty")) {
		    type = "vio";
		    ret = 3;
	    } else {
		    type = "vt";
		    ret = 0;
	    }
#else
	    type = "vt";
	    ret = 0;
#endif
	}
    } else {
	type = "pty";
	ret = 2;
    }
    if (argc > 1 && !strcmp(argv[1],"fg")) {
	    if (fg < 0 || fg != (min-1))
		    return 1;
	    return 0;
    } else {
	    printf("%s\n",type);
	    return ret;
    }
}