fpurge.c revision 249810
1228060Sbapt/*- 2228060Sbapt * Copyright (c) 1990, 1993 3228060Sbapt * The Regents of the University of California. All rights reserved. 4228060Sbapt * 5228060Sbapt * This code is derived from software contributed to Berkeley by 6228060Sbapt * Chris Torek. 7228060Sbapt * 8228060Sbapt * Redistribution and use in source and binary forms, with or without 9228060Sbapt * modification, are permitted provided that the following conditions 10228060Sbapt * are met: 11228060Sbapt * 1. Redistributions of source code must retain the above copyright 12228060Sbapt * notice, this list of conditions and the following disclaimer. 13228060Sbapt * 2. Redistributions in binary form must reproduce the above copyright 14228060Sbapt * notice, this list of conditions and the following disclaimer in the 15228060Sbapt * documentation and/or other materials provided with the distribution. 16228060Sbapt * 3. Neither the name of the University nor the names of its contributors 17228060Sbapt * may be used to endorse or promote products derived from this software 18228060Sbapt * without specific prior written permission. 19228060Sbapt * 20228060Sbapt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21228060Sbapt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22228060Sbapt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23228060Sbapt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24228060Sbapt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25228060Sbapt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26228060Sbapt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27228060Sbapt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28228060Sbapt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29228060Sbapt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30228060Sbapt * SUCH DAMAGE. 31228060Sbapt */ 32228060Sbapt 33228060Sbapt#if defined(LIBC_SCCS) && !defined(lint) 34228060Sbaptstatic char sccsid[] = "@(#)fpurge.c 8.1 (Berkeley) 6/4/93"; 35228060Sbapt#endif /* LIBC_SCCS and not lint */ 36228060Sbapt#include <sys/cdefs.h> 37228060Sbapt__FBSDID("$FreeBSD: head/lib/libc/stdio/fpurge.c 249810 2013-04-23 14:36:44Z emaste $"); 38228060Sbapt 39228060Sbapt#include "namespace.h" 40228060Sbapt#include <errno.h> 41228060Sbapt#include <stdio.h> 42228060Sbapt#include <stdlib.h> 43228060Sbapt#include "un-namespace.h" 44228060Sbapt#include "local.h" 45228060Sbapt#include "libc_private.h" 46228060Sbapt 47228060Sbapt/* 48228060Sbapt * fpurge: like fflush, but without writing anything: leave the 49228060Sbapt * given FILE's buffer empty. 50228060Sbapt */ 51228060Sbaptint 52228060Sbaptfpurge(FILE *fp) 53228060Sbapt{ 54228060Sbapt int retval; 55228060Sbapt FLOCKFILE(fp); 56228060Sbapt if (!fp->_flags) { 57228060Sbapt errno = EBADF; 58228060Sbapt retval = EOF; 59228060Sbapt } else { 60228060Sbapt if (HASUB(fp)) 61228060Sbapt FREEUB(fp); 62228060Sbapt fp->_p = fp->_bf._base; 63228060Sbapt fp->_r = 0; 64228060Sbapt fp->_w = fp->_flags & (__SLBF|__SNBF|__SRD) ? 0 : fp->_bf._size; 65228060Sbapt retval = 0; 66228060Sbapt } 67228060Sbapt FUNLOCKFILE(fp); 68228060Sbapt return (retval); 69228060Sbapt} 70228060Sbapt