prettyness police
[unix-history] / usr / src / bin / stty / util.c
CommitLineData
2b43290b 1/*-
0217b2ba
KB
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
2b43290b
KB
4 *
5 * %sccs.include.redist.c%
6 */
7
8#ifndef lint
706c0358 9static char sccsid[] = "@(#)util.c 8.2 (Berkeley) %G%";
2b43290b
KB
10#endif /* not lint */
11
12#include <sys/types.h>
13#include <sys/stat.h>
60964f11
KB
14
15#include <err.h>
2b43290b
KB
16#include <stdio.h>
17#include <stdlib.h>
60964f11
KB
18#include <unistd.h>
19
2b43290b
KB
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 */
29void
30checkredirect()
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))
37warn("stdout appears redirected, but stdin is the control descriptor");
38}