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 #pragma ident "%Z%%M% %I% %E% SMI" 16 17 #include <sm/gen.h> 18 SM_RCSID("@(#)$Id: fpurge.c,v 1.18 2001/01/28 00:29:35 ca Exp $") 19 #include <stdlib.h> 20 #include <errno.h> 21 #include <sm/io.h> 22 #include <sm/assert.h> 23 #include "local.h" 24 25 /* 26 ** SM_IO_PURGE -- purge/empty the buffer without committing buffer content 27 ** 28 ** Parameters: 29 ** fp -- file pointer to purge 30 ** 31 ** Returns: 32 ** Failure: returns SM_IO_EOF and sets errno 33 ** Success: returns 0 (zero) 34 */ 35 36 int 37 sm_io_purge(fp) 38 register SM_FILE_T *fp; 39 { 40 SM_REQUIRE_ISA(fp, SmFileMagic); 41 if (!fp->f_flags) 42 { 43 errno = EBADF; 44 return SM_IO_EOF; 45 } 46 47 if (HASUB(fp)) 48 FREEUB(fp); 49 fp->f_p = fp->f_bf.smb_base; 50 fp->f_r = 0; 51 52 /* implies SMFBF */ 53 fp->f_w = fp->f_flags & (SMLBF|SMNBF) ? 0 : fp->f_bf.smb_size; 54 return 0; 55 } 56