xref: /original-bsd/bin/stty/util.c (revision e58c8952)
1 /*-
2  * Copyright (c) 1991, 1993, 1994
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)util.c	8.3 (Berkeley) 04/02/94";
10 #endif /* not lint */
11 
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 
15 #include <err.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <unistd.h>
19 
20 #include "stty.h"
21 #include "extern.h"
22 
23 /*
24  * Gross, but since we're changing the control descriptor from 1 to 0, most
25  * users will be probably be doing "stty > /dev/sometty" by accident.  If 1
26  * and 2 are both ttys, but not the same, assume that 1 was incorrectly
27  * redirected.
28  */
29 void
30 checkredirect()
31 {
32 	struct stat sb1, sb2;
33 
34 	if (isatty(STDOUT_FILENO) && isatty(STDERR_FILENO) &&
35 	    !fstat(STDOUT_FILENO, &sb1) && !fstat(STDERR_FILENO, &sb2) &&
36 	    (sb1.st_rdev != sb2.st_rdev))
37 warn("stdout appears redirected, but stdin is the control descriptor");
38 }
39