8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / sendmail / libsm / wsetup.c
blobe7a5e7924ba6c91abe6d3443aa00ac4a6b78e5ed
1 /*
2 * Copyright (c) 2000-2002 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.
7 * This code is derived from software contributed to Berkeley by
8 * Chris Torek.
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"
17 #include <sm/gen.h>
18 SM_RCSID("@(#)$Id: wsetup.c,v 1.20 2002/02/07 18:02:45 ca Exp $")
19 #include <stdlib.h>
20 #include <errno.h>
21 #include <sm/io.h>
22 #include "local.h"
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".
31 ** Parameters:
32 ** fp -- the file pointer
34 ** Results:
35 ** Failure: SM_IO_EOF and sets errno
36 ** Success: 0 (zero)
39 int
40 sm_wsetup(fp)
41 register SM_FILE_T *fp;
43 /* make sure stdio is set up */
44 if (!Sm_IO_DidInit)
45 sm_init();
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)
52 errno = EBADF;
53 return SM_IO_EOF;
55 if (fp->f_flags & SMRD)
57 /* clobber any ungetc data */
58 if (HASUB(fp))
59 FREEUB(fp);
61 /* discard read buffer */
62 fp->f_flags &= ~(SMRD|SMFEOF);
63 fp->f_r = 0;
64 fp->f_p = fp->f_bf.smb_base;
66 fp->f_flags |= SMWR;
69 /* Make a buffer if necessary, then set w. */
70 if (fp->f_bf.smb_base == NULL)
71 sm_makebuf(fp);
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.
80 fp->f_w = 0;
81 fp->f_lbfsize = -fp->f_bf.smb_size;
83 else
84 fp->f_w = fp->f_flags & SMNBF ? 0 : fp->f_bf.smb_size;
85 return 0;