xref: /csrg-svn/lib/libc/stdio/fpurge.c (revision 61180)
146111Sbostic /*-
2*61180Sbostic  * Copyright (c) 1990, 1993
3*61180Sbostic  *	The Regents of the University of California.  All rights reserved.
446111Sbostic  *
546111Sbostic  * This code is derived from software contributed to Berkeley by
646111Sbostic  * Chris Torek.
746111Sbostic  *
846111Sbostic  * %sccs.include.redist.c%
946111Sbostic  */
1046111Sbostic 
1146111Sbostic #if defined(LIBC_SCCS) && !defined(lint)
12*61180Sbostic static char sccsid[] = "@(#)fpurge.c	8.1 (Berkeley) 06/04/93";
1346111Sbostic #endif /* LIBC_SCCS and not lint */
1446111Sbostic 
1546111Sbostic #include <errno.h>
1646111Sbostic #include <stdio.h>
1746611Sbostic #include <stdlib.h>
1846111Sbostic #include "local.h"
1946111Sbostic 
2046111Sbostic /*
2146111Sbostic  * fpurge: like fflush, but without writing anything: leave the
2246111Sbostic  * given FILE's buffer empty.
2346111Sbostic  */
2446111Sbostic int
fpurge(fp)2546111Sbostic fpurge(fp)
2646111Sbostic 	register FILE *fp;
2746111Sbostic {
2846111Sbostic 	if (!fp->_flags) {
2946111Sbostic 		errno = EBADF;
3046111Sbostic 		return(EOF);
3146111Sbostic 	}
3246111Sbostic 
3346111Sbostic 	if (HASUB(fp))
3446111Sbostic 		FREEUB(fp);
3546111Sbostic 	fp->_p = fp->_bf._base;
3646111Sbostic 	fp->_r = 0;
3746111Sbostic 	fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size;
3846111Sbostic 	return (0);
3946111Sbostic }
40