new copyright; att/bsd/shared
[unix-history] / usr / src / lib / libc / stdio / fpurge.c
CommitLineData
c9be6cfe
KB
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * %sccs.include.redist.c%
9 */
10
11#if defined(LIBC_SCCS) && !defined(lint)
cb631443 12static char sccsid[] = "@(#)fpurge.c 5.2 (Berkeley) %G%";
c9be6cfe
KB
13#endif /* LIBC_SCCS and not lint */
14
15#include <errno.h>
16#include <stdio.h>
cb631443 17#include <stdlib.h>
c9be6cfe
KB
18#include "local.h"
19
20/*
21 * fpurge: like fflush, but without writing anything: leave the
22 * given FILE's buffer empty.
23 */
24int
25fpurge(fp)
26 register FILE *fp;
27{
28 if (!fp->_flags) {
29 errno = EBADF;
30 return(EOF);
31 }
32
33 if (HASUB(fp))
34 FREEUB(fp);
35 fp->_p = fp->_bf._base;
36 fp->_r = 0;
37 fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size;
38 return (0);
39}