Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / sbr / discard.c
1 /* discard.c - discard output on a file pointer */
2 #ifndef lint
3 static char ident[] = "@(#)$Id: discard.c,v 1.7 1993/02/26 21:56:04 jromine Exp $";
4 #endif  /* lint */
5
6 #include "../h/mh.h"
7 #include <stdio.h>
8 #ifdef POSIX
9 #include <termios.h>
10 #else
11 #ifndef SYS5
12 #include <sgtty.h>
13 #else   /* SYS5 */
14 #include <sys/types.h>
15 #include <termio.h>
16 #ifndef NOIOCTLH
17 #include <sys/ioctl.h>
18 #endif  /* NOIOCTLH */
19 #endif  /* SYS5 */
20 #endif  /* POSIX */
21
22
23 void    discard (io)
24 FILE   *io;
25 {
26 #ifndef POSIX
27 #ifndef SYS5
28     struct sgttyb   sg;
29 #else   /* SYS5 */
30     struct termio   sg;
31 #endif  /* SYS5 */
32 #endif  /* POSIX */
33
34     if (io == NULL)
35         return;
36
37 #ifdef POSIX
38     tcflush (fileno (io), TCOFLUSH);
39 #else
40 #ifndef SYS5
41     if (ioctl (fileno (io), TIOCGETP, (char *) &sg) != NOTOK)
42         (void) ioctl (fileno (io), TIOCSETP, (char *) &sg);
43 #else   /* SYS5 */
44     if (ioctl (fileno (io), TCGETA, &sg) != NOTOK)
45         (void) ioctl (fileno (io), TCSETA, &sg);
46 #endif  /* SYS5 */
47 #endif  /* POSIX */
48
49 #ifdef _FSTDIO
50     fpurge (io);
51 #else
52     if (io -> _ptr = io -> _base)
53         io -> _cnt = 0;
54 #endif
55 }