Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/tty/tty.c
Show All 38 Lines | |||||
#endif | #endif | ||||
#endif /* not lint */ | #endif /* not lint */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <sysexits.h> | |||||
#include <unistd.h> | #include <unistd.h> | ||||
static void usage(void); | static void usage(void); | ||||
int | int | ||||
main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||
{ | { | ||||
int ch, sflag; | int ch, sflag; | ||||
char *t; | char *t; | ||||
sflag = 0; | sflag = 0; | ||||
while ((ch = getopt(argc, argv, "s")) != -1) | while ((ch = getopt(argc, argv, "s")) != -1) | ||||
switch (ch) { | switch (ch) { | ||||
case 's': | case 's': | ||||
sflag = 1; | sflag = 1; | ||||
break; | break; | ||||
case '?': | case '?': | ||||
default: | default: | ||||
usage(); | usage(); | ||||
/* NOTREACHED */ | |||||
} | } | ||||
t = ttyname(0); | t = ttyname(STDIN_FILENO); | ||||
if (!sflag) | if (!sflag) | ||||
puts(t ? t : "not a tty"); | puts(t ? t : "not a tty"); | ||||
exit(t ? 0 : 1); | exit(t ? EXIT_SUCCESS : EXIT_FAILURE); | ||||
} | } | ||||
static void | static void | ||||
usage(void) | usage(void) | ||||
{ | { | ||||
fprintf(stderr, "usage: tty [-s]\n"); | fprintf(stderr, "usage: %s [-s]\n", getprogname()); | ||||
exit(2); | exit(EX_USAGE); | ||||
} | } |