1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-27 11:55:06 +00:00
freebsd/contrib/sendmail/libsm/wsetup.c

85 lines
1.9 KiB
C
Raw Normal View History

2002-02-17 21:56:45 +00:00
/*
2002-04-10 03:05:00 +00:00
* Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers.
2002-02-17 21:56:45 +00:00
* All rights reserved.
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the sendmail distribution.
*/
#include <sm/gen.h>
2002-06-11 21:12:04 +00:00
SM_RCSID("@(#)$Id: wsetup.c,v 1.20 2002/02/07 18:02:45 ca Exp $")
2002-02-17 21:56:45 +00:00
#include <stdlib.h>
#include <errno.h>
#include <sm/io.h>
#include "local.h"
/*
2002-04-10 03:05:00 +00:00
** SM_WSETUP -- check writing is safe
2002-02-17 21:56:45 +00:00
**
** Various output routines call wsetup to be sure it is safe to write,
** because either flags does not include SMMWR, or buf is NULL.
** Used in the macro "cantwrite" found in "local.h".
**
** Parameters:
** fp -- the file pointer
**
** Results:
** Failure: SM_IO_EOF and sets errno
** Success: 0 (zero)
*/
int
sm_wsetup(fp)
register SM_FILE_T *fp;
{
/* make sure stdio is set up */
if (!Sm_IO_DidInit)
sm_init();
/* If we are not writing, we had better be reading and writing. */
if ((fp->f_flags & SMWR) == 0)
{
if ((fp->f_flags & SMRW) == 0)
{
errno = EBADF;
return SM_IO_EOF;
}
if (fp->f_flags & SMRD)
{
/* clobber any ungetc data */
if (HASUB(fp))
FREEUB(fp);
2002-04-10 03:05:00 +00:00
/* discard read buffer */
2002-02-17 21:56:45 +00:00
fp->f_flags &= ~(SMRD|SMFEOF);
fp->f_r = 0;
fp->f_p = fp->f_bf.smb_base;
}
fp->f_flags |= SMWR;
}
/* Make a buffer if necessary, then set w. */
if (fp->f_bf.smb_base == NULL)
sm_makebuf(fp);
if (fp->f_flags & SMLBF)
{
/*
** It is line buffered, so make lbfsize be -bufsize
** for the sm_putc() macro. We will change lbfsize back
** to 0 whenever we turn off SMWR.
*/
fp->f_w = 0;
fp->f_lbfsize = -fp->f_bf.smb_size;
}
else
fp->f_w = fp->f_flags & SMNBF ? 0 : fp->f_bf.smb_size;
return 0;
}