148944Sbostic /*-
2*66642Spendry * Copyright (c) 1991, 1993, 1994
360721Sbostic * The Regents of the University of California. All rights reserved.
448944Sbostic *
548944Sbostic * %sccs.include.redist.c%
648944Sbostic */
748944Sbostic
848944Sbostic #ifndef lint
9*66642Spendry static char sccsid[] = "@(#)util.c 8.3 (Berkeley) 04/02/94";
1048944Sbostic #endif /* not lint */
1148944Sbostic
1248944Sbostic #include <sys/types.h>
1348944Sbostic #include <sys/stat.h>
1459525Sbostic
1559525Sbostic #include <err.h>
1648944Sbostic #include <stdio.h>
1748944Sbostic #include <stdlib.h>
1859525Sbostic #include <unistd.h>
1959525Sbostic
2048944Sbostic #include "stty.h"
2148944Sbostic #include "extern.h"
2248944Sbostic
2348944Sbostic /*
2448944Sbostic * Gross, but since we're changing the control descriptor from 1 to 0, most
2548944Sbostic * users will be probably be doing "stty > /dev/sometty" by accident. If 1
2648944Sbostic * and 2 are both ttys, but not the same, assume that 1 was incorrectly
2748944Sbostic * redirected.
2848944Sbostic */
2948944Sbostic void
checkredirect()3048944Sbostic checkredirect()
3148944Sbostic {
3248944Sbostic struct stat sb1, sb2;
3348944Sbostic
3448944Sbostic if (isatty(STDOUT_FILENO) && isatty(STDERR_FILENO) &&
3548944Sbostic !fstat(STDOUT_FILENO, &sb1) && !fstat(STDERR_FILENO, &sb2) &&
3648944Sbostic (sb1.st_rdev != sb2.st_rdev))
3748944Sbostic warn("stdout appears redirected, but stdin is the control descriptor");
3848944Sbostic }
39