/*
* Copyright (c) 2000-2002, 2004, 2013 Proofpoint, Inc. and its suppliers.
* All rights reserved.
* Copyright (c) 1990
* 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.
*
* $Id: io.h,v 1.26 2013-11-22 20:51:31 ca Exp $
*/
/*-
* @(#)stdio.h 5.17 (Berkeley) 6/3/91
*/
#ifndef SM_IO_H
#define SM_IO_H
#include <stdio.h>
/* mode for sm io (exposed) */
/* for sm_io_fseek, et al api's (exposed) */
#define SM_IO_SEEK_SET 0
/* flags for info what's with different types (exposed) */
/* info flags (exposed) */
/* for internal buffers */
struct smbuf
{
unsigned char *smb_base;
int smb_size;
};
/*
** sm I/O state variables (internal only).
**
** The following always hold:
**
** if (flags&(SMLBF|SMWR)) == (SMLBF|SMWR),
** lbfsize is -bf.size, else lbfsize is 0
** if flags&SMRD, w is 0
** if flags&SMWR, r is 0
**
** This ensures that the getc and putc macros (or inline functions) never
** try to write or read from a file that is in `read' or `write' mode.
** (Moreover, they can, and do, automatically switch from read mode to
** write mode, and back, on "r+" and "w+" files.)
**
** lbfsize is used only to make the inline line-buffered output stream
** code as compact as possible.
**
** ub, up, and ur are used when ungetc() pushes back more characters
** than fit in the current bf, or when ungetc() pushes back a character
** that does not match the previous one in bf. When this happens,
** ub.base becomes non-nil (i.e., a stream has ungetc() data iff
** ub.base!=NULL) and up and ur save the current values of p and r.
*/
struct sm_file
{
/* These can be used for any purpose by a file type implementation: */
void *f_cookie;
int f_ival;
/* operations */
const void *));
int f_timeout;
/* separate buffer for long sequences of ungetc() */
/* tricks to meet minimum requirements even when malloc() fails */
/* Unix stdio files get aligned to block boundaries on fseek() */
};
extern const char SmFileMagic[];
extern SM_FILE_T SmFtStdio_def;
extern SM_FILE_T SmFtStdiofd_def;
extern SM_FILE_T SmFtString_def;
extern SM_FILE_T SmFtSyslog_def;
extern SM_FILE_T SmFtRealStdio_def;
#define SMIOIN_FILENO 0
/* Common predefined and already (usually) open files (exposed) */
#ifdef __STDC__
(f) = {SmFileMagic, (unsigned char *) 0, 0, 0, 0L, -1, {0}, 0, (void *) 0,\
0, (name)}
#else /* __STDC__ */
(f).sm_magic = SmFileMagic; \
(f).f_p = (unsigned char *) 0; \
(f).f_r = 0; \
(f).f_w = 0; \
(f).f_flags = 0L; \
(f).f_file = 0; \
(f).f_lbfsize = 0; \
(f).f_cookie = (void *) 0; \
(f).f_ival = 0; \
(f).f_timeoutstate = 0; \
#endif /* __STDC__ */
/* Internal flags */
/* RD and WR are never simultaneously asserted */
/* defines for timeout constants */
#define SM_TIME_IMMEDIATE (0)
/* timeout state for blocking */
/* Exposed buffering type flags */
/* setvbuf buffered, but through at lower file type layers */
/*
** size of buffer used by setbuf.
** If underlying filesystem blocksize is discoverable that is used instead
*/
/* Functions defined in ANSI C standard. */
int, const void *));
const void *, int, const void *, SM_FILE_T *));
int SM_NONVOLATILE));
sm_io_sscanf __P((const char *, char const *, ...));
extern SM_FILE_T *
char *_pathname,
int _flags,
...));
extern SM_FILE_T *
char *_mode));
extern int
char **_str,
const char *_fmt,
extern int
char *,
const char *,
va_list));
extern void
const char *));
/*
** Functions internal to the implementation.
*/
/*
** The macros are here so that we can
** define function versions in the library.
*/
#define sm_getc(f, t) \
(--(f)->f_r < 0 ? \
sm_rget(f, t) : \
(int)(*(f)->f_p++))
/*
** This has been tuned to generate reasonable code on the vax using pcc.
** (It also generates reasonable x86 code using gcc.)
*/
#define sm_putc(f, t, c) \
(--(f)->f_w < 0 ? \
(int)*(f)->f_p++ : \
sm_wbuf(f, t, '\n') : \
sm_wbuf(f, t, (int)(c)) : \
#ifndef lint
# ifndef _POSIX_SOURCE
# endif /* _POSIX_SOURCE */
#endif /* lint */
#endif /* SM_IO_H */