]> diplodocus.org Git - nmh/blob - sbr/discard.c
Fix stupid accidental dependence on a bash quirk in previous
[nmh] / sbr / discard.c
1
2 /*
3 * discard.c -- discard output on a file pointer
4 *
5 * $Id$
6 *
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
10 */
11
12 #include <h/mh.h>
13
14 #ifdef HAVE_TERMIOS_H
15 # include <termios.h>
16 #else
17 # ifdef HAVE_TERMIO_H
18 # include <termio.h>
19 # else
20 # include <sgtty.h>
21 # endif
22 #endif
23
24 #ifdef SCO_5_STDIO
25 # define _ptr __ptr
26 # define _cnt __cnt
27 # define _base __base
28 # define _filbuf(fp) ((fp)->__cnt = 0, __filbuf(fp))
29 #endif
30
31
32 void
33 discard (FILE *io)
34 {
35 #ifndef HAVE_TERMIOS_H
36 # ifdef HAVE_TERMIO_H
37 struct termio tio;
38 # else
39 struct sgttyb tio;
40 # endif
41 #endif
42
43 if (io == NULL)
44 return;
45
46 #ifdef HAVE_TERMIOS_H
47 tcflush (fileno(io), TCOFLUSH);
48 #else
49 # ifdef HAVE_TERMIO_H
50 if (ioctl (fileno(io), TCGETA, &tio) != -1)
51 ioctl (fileno(io), TCSETA, &tio);
52 # else
53 if (ioctl (fileno(io), TIOCGETP, (char *) &tio) != -1)
54 ioctl (fileno(io), TIOCSETP, (char *) &tio);
55 # endif
56 #endif
57
58 #ifdef _FSTDIO
59 fpurge (io);
60 #else
61 # ifdef LINUX_STDIO
62 io->_IO_write_ptr = io->_IO_write_base;
63 # else
64 if ((io->_ptr = io->_base))
65 io->_cnt = 0;
66 # endif
67 #endif
68 }
69