btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / bin / tty.c
blobc892a997000ec87fb56427641f5620a1aedce6d9
1 /*
2 * Copyright 2001-2013 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Daniel Reinhold, danielre@users.sf.net
7 */
10 #include <stdio.h>
11 #include <unistd.h>
13 #include <OS.h>
16 void
17 usage()
19 printf("Usage: tty [-s]\n"
20 "Prints the file name for the terminal connected to standard input.\n"
21 " -s silent mode: no output -- only return an exit status\n");
23 exit(2);
27 int
28 main(int argc, char *argv[])
31 if (argc > 2)
32 usage();
34 else {
35 bool silent = false;
37 if (argc == 2) {
38 if (!strcmp(argv[1], "-s"))
39 silent = true;
40 else
41 usage();
44 if (!silent)
45 printf("%s\n", ttyname(STDIN_FILENO));
48 return (isatty(STDIN_FILENO) ? 0 : 1);