190792Sgshapiro/*
2261194Sgshapiro * Copyright (c) 2000-2001 Proofpoint, Inc. and its suppliers.
390792Sgshapiro *      All rights reserved.
490792Sgshapiro * Copyright (c) 1990, 1993
590792Sgshapiro *	The Regents of the University of California.  All rights reserved.
690792Sgshapiro *
790792Sgshapiro * This code is derived from software contributed to Berkeley by
890792Sgshapiro * Chris Torek.
990792Sgshapiro *
1090792Sgshapiro * By using this file, you agree to the terms and conditions set
1190792Sgshapiro * forth in the LICENSE file which can be found at the top level of
1290792Sgshapiro * the sendmail distribution.
1390792Sgshapiro */
1490792Sgshapiro
1590792Sgshapiro#include <sm/gen.h>
16266527SgshapiroSM_RCSID("@(#)$Id: fpurge.c,v 1.21 2013-11-22 20:51:42 ca Exp $")
1790792Sgshapiro#include <stdlib.h>
1890792Sgshapiro#include <errno.h>
1990792Sgshapiro#include <sm/io.h>
2090792Sgshapiro#include <sm/assert.h>
2190792Sgshapiro#include "local.h"
2290792Sgshapiro
2390792Sgshapiro/*
2490792Sgshapiro**  SM_IO_PURGE -- purge/empty the buffer without committing buffer content
2590792Sgshapiro**
2690792Sgshapiro**	Parameters:
2790792Sgshapiro**		fp -- file pointer to purge
2890792Sgshapiro**
2990792Sgshapiro**	Returns:
3090792Sgshapiro**		Failure: returns SM_IO_EOF and sets errno
3190792Sgshapiro**		Success: returns 0 (zero)
3290792Sgshapiro*/
3390792Sgshapiro
3490792Sgshapiroint
3590792Sgshapirosm_io_purge(fp)
3690792Sgshapiro	register SM_FILE_T *fp;
3790792Sgshapiro{
3890792Sgshapiro	SM_REQUIRE_ISA(fp, SmFileMagic);
3990792Sgshapiro	if (!fp->f_flags)
4090792Sgshapiro	{
4190792Sgshapiro		errno = EBADF;
4290792Sgshapiro		return SM_IO_EOF;
4390792Sgshapiro	}
4490792Sgshapiro
4590792Sgshapiro	if (HASUB(fp))
4690792Sgshapiro		FREEUB(fp);
4790792Sgshapiro	fp->f_p = fp->f_bf.smb_base;
4890792Sgshapiro	fp->f_r = 0;
4990792Sgshapiro
5090792Sgshapiro	/* implies SMFBF */
5190792Sgshapiro	fp->f_w = fp->f_flags & (SMLBF|SMNBF) ? 0 : fp->f_bf.smb_size;
5290792Sgshapiro	return 0;
5390792Sgshapiro}
54