2 * Copyright (c) 2000-2002 Proofpoint, Inc. and its suppliers.
4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
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.
16 SM_RCSID("@(#)$Id: wsetup.c,v 1.21 2013-11-22 20:51:44 ca Exp $")
23 ** SM_WSETUP -- check writing is safe
25 ** Various output routines call wsetup to be sure it is safe to write,
26 ** because either flags does not include SMMWR, or buf is NULL.
27 ** Used in the macro "cantwrite" found in "local.h".
30 ** fp -- the file pointer
33 ** Failure: SM_IO_EOF and sets errno
39 register SM_FILE_T *fp;
41 /* make sure stdio is set up */
45 /* If we are not writing, we had better be reading and writing. */
46 if ((fp->f_flags & SMWR) == 0)
48 if ((fp->f_flags & SMRW) == 0)
53 if (fp->f_flags & SMRD)
55 /* clobber any ungetc data */
59 /* discard read buffer */
60 fp->f_flags &= ~(SMRD|SMFEOF);
62 fp->f_p = fp->f_bf.smb_base;
67 /* Make a buffer if necessary, then set w. */
68 if (fp->f_bf.smb_base == NULL)
70 if (fp->f_flags & SMLBF)
73 ** It is line buffered, so make lbfsize be -bufsize
74 ** for the sm_putc() macro. We will change lbfsize back
75 ** to 0 whenever we turn off SMWR.
79 fp->f_lbfsize = -fp->f_bf.smb_size;
82 fp->f_w = fp->f_flags & SMNBF ? 0 : fp->f_bf.smb_size;