fpurge.c revision 182352
1249259Sdim/*
2249259Sdim * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
3249259Sdim *      All rights reserved.
4249259Sdim * Copyright (c) 1990, 1993
5249259Sdim *	The Regents of the University of California.  All rights reserved.
6249259Sdim *
7249259Sdim * This code is derived from software contributed to Berkeley by
8249259Sdim * Chris Torek.
9249259Sdim *
10249259Sdim * By using this file, you agree to the terms and conditions set
11249259Sdim * forth in the LICENSE file which can be found at the top level of
12249259Sdim * the sendmail distribution.
13249259Sdim */
14249259Sdim
15249259Sdim#include <sm/gen.h>
16249259SdimSM_RCSID("@(#)$Id: fpurge.c,v 1.20 2001/09/11 04:04:48 gshapiro Exp $")
17276479Sdim#include <stdlib.h>
18276479Sdim#include <errno.h>
19249259Sdim#include <sm/io.h>
20249259Sdim#include <sm/assert.h>
21249259Sdim#include "local.h"
22249259Sdim
23249259Sdim/*
24249259Sdim**  SM_IO_PURGE -- purge/empty the buffer without committing buffer content
25249259Sdim**
26249259Sdim**	Parameters:
27249259Sdim**		fp -- file pointer to purge
28249259Sdim**
29249259Sdim**	Returns:
30249259Sdim**		Failure: returns SM_IO_EOF and sets errno
31249259Sdim**		Success: returns 0 (zero)
32249259Sdim*/
33249259Sdim
34249259Sdimint
35249259Sdimsm_io_purge(fp)
36249259Sdim	register SM_FILE_T *fp;
37249259Sdim{
38249259Sdim	SM_REQUIRE_ISA(fp, SmFileMagic);
39249259Sdim	if (!fp->f_flags)
40249259Sdim	{
41249259Sdim		errno = EBADF;
42249259Sdim		return SM_IO_EOF;
43249259Sdim	}
44249259Sdim
45249259Sdim	if (HASUB(fp))
46249259Sdim		FREEUB(fp);
47249259Sdim	fp->f_p = fp->f_bf.smb_base;
48249259Sdim	fp->f_r = 0;
49249259Sdim
50249259Sdim	/* implies SMFBF */
51249259Sdim	fp->f_w = fp->f_flags & (SMLBF|SMNBF) ? 0 : fp->f_bf.smb_size;
52249259Sdim	return 0;
53249259Sdim}
54249259Sdim