2 * Copyright (c) 2000-2002 Sendmail, 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.
15 #pragma ident "%Z%%M% %I% %E% SMI"
18 SM_RCSID("@(#)$Id: wsetup.c,v 1.20 2002/02/07 18:02:45 ca Exp $")
25 ** SM_WSETUP -- check writing is safe
27 ** Various output routines call wsetup to be sure it is safe to write,
28 ** because either flags does not include SMMWR, or buf is NULL.
29 ** Used in the macro "cantwrite" found in "local.h".
32 ** fp -- the file pointer
35 ** Failure: SM_IO_EOF and sets errno
41 register SM_FILE_T
*fp
;
43 /* make sure stdio is set up */
47 /* If we are not writing, we had better be reading and writing. */
48 if ((fp
->f_flags
& SMWR
) == 0)
50 if ((fp
->f_flags
& SMRW
) == 0)
55 if (fp
->f_flags
& SMRD
)
57 /* clobber any ungetc data */
61 /* discard read buffer */
62 fp
->f_flags
&= ~(SMRD
|SMFEOF
);
64 fp
->f_p
= fp
->f_bf
.smb_base
;
69 /* Make a buffer if necessary, then set w. */
70 if (fp
->f_bf
.smb_base
== NULL
)
72 if (fp
->f_flags
& SMLBF
)
75 ** It is line buffered, so make lbfsize be -bufsize
76 ** for the sm_putc() macro. We will change lbfsize back
77 ** to 0 whenever we turn off SMWR.
81 fp
->f_lbfsize
= -fp
->f_bf
.smb_size
;
84 fp
->f_w
= fp
->f_flags
& SMNBF
? 0 : fp
->f_bf
.smb_size
;