xref: /illumos-gate/usr/src/cmd/sendmail/libsm/fpurge.c (revision 012e6ce759c490003aed29439cc47d3d73a99ad3)
1 /*
2  * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
3  *      All rights reserved.
4  * Copyright (c) 1990, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Chris Torek.
9  *
10  * By using this file, you agree to the terms and conditions set
11  * forth in the LICENSE file which can be found at the top level of
12  * the sendmail distribution.
13  */
14 
15 #include <sm/gen.h>
16 SM_RCSID("@(#)$Id: fpurge.c,v 1.18 2001/01/28 00:29:35 ca Exp $")
17 #include <stdlib.h>
18 #include <errno.h>
19 #include <sm/io.h>
20 #include <sm/assert.h>
21 #include "local.h"
22 
23 /*
24 **  SM_IO_PURGE -- purge/empty the buffer without committing buffer content
25 **
26 **	Parameters:
27 **		fp -- file pointer to purge
28 **
29 **	Returns:
30 **		Failure: returns SM_IO_EOF and sets errno
31 **		Success: returns 0 (zero)
32 */
33 
34 int
35 sm_io_purge(fp)
36 	register SM_FILE_T *fp;
37 {
38 	SM_REQUIRE_ISA(fp, SmFileMagic);
39 	if (!fp->f_flags)
40 	{
41 		errno = EBADF;
42 		return SM_IO_EOF;
43 	}
44 
45 	if (HASUB(fp))
46 		FREEUB(fp);
47 	fp->f_p = fp->f_bf.smb_base;
48 	fp->f_r = 0;
49 
50 	/* implies SMFBF */
51 	fp->f_w = fp->f_flags & (SMLBF|SMNBF) ? 0 : fp->f_bf.smb_size;
52 	return 0;
53 }
54