1 /*
2    Module to check that the IO is to a tty, and display a usage message
3    otherwise
4    Copright (c) 2000 Randall Maas (randym@acm.org)
5 
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10 
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 
20 */
21 
22 #include "psh.h"
23 
24 static void usage(void) ATTR(INIT);
25 static char msg[]="Usage:\tah-tty\n\tThis will display helpful messages at the"
26 " bottom of your terminal\n";
usage(void)27 static void usage(void)
28 {
29    write(2, msg, sizeof(msg));
30 }
31 
32 /* @txh */
check_stdio(void)33 void check_stdio(void)
34 {
35    /*
36       Description
37        This routine verifies that the stdin and stdout are both TTY channels.
38        If not, a usage message is displayed, and @file{ah-tty} exits.
39 
40        If there is an error, we return.
41    */
42 
43    if (isatty(0) && isatty(1)) return;
44    usage();
45    exit(-1);
46 }
47