/* consoletype.c simple app to figure out whether the current terminal is serial, console (vt), or remote (pty). Copyright 2005 Robert Millan Distributed under the terms of the GNU General Public License v2 */ #include #include /* exit */ #include main () { char *tty, *msg; tty = ttyname (0); if (tty == NULL) { fprintf (stderr, "Not a tty.\n"); exit (1); } /* Nuke "/dev/" */ tty += 5; if (!strncmp (tty, "ttyS", 4) || !strncmp (tty, "cuaa", 4)) msg = "serial"; else if (!strncmp (tty, "pts/", 4) || !strncmp (tty, "ttyp", 4)) msg = "pty"; else if (!strncmp (tty, "tty", 3)) msg = "console"; else msg = "unknown"; printf ("%s\n", msg); exit (0); }