/*
* Copyright (c) 2000-2002, 2004 Sendmail, Inc. and its suppliers.
* All rights reserved.
*
* 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.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include "local.h"
/*
** Overall:
** This is a file type which implements a layer on top of the system
** stdio. fp->f_cookie is the FILE* of stdio. The cookie may be
** "bound late" because of the manner which Linux implements stdio.
** When binding late (when fp->f_cookie==NULL) then the value of
** fp->f_ival is used (0, 1 or 2) to map to stdio's stdin, stdout or
** stderr.
*/
/*
** SM_STDIOOPEN -- open a file to system stdio implementation
**
** Parameters:
** fp -- file pointer assign for this open
** info -- info about file to open
** flags -- indicating method of opening
** rpool -- ignored
**
** Returns:
** Failure: -1
** Success: 0 (zero)
*/
/* ARGSUSED3 */
int
const void *info;
int flags;
const void *rpool;
{
register FILE *s;
char *stdiomode;
switch (flags)
{
case SM_IO_RDONLY:
stdiomode = "r";
break;
case SM_IO_WRONLY:
stdiomode = "w";
break;
case SM_IO_APPEND:
stdiomode = "a";
break;
case SM_IO_APPENDRW:
stdiomode = "a+";
break;
#if SM_IO_BINARY != 0
case SM_IO_RDONLY_B:
stdiomode = "rb";
break;
case SM_IO_WRONLY_B:
stdiomode = "wb";
break;
case SM_IO_APPEND_B:
stdiomode = "ab";
break;
case SM_IO_APPENDRW_B:
stdiomode = "a+b";
break;
case SM_IO_RDWR_B:
stdiomode = "r+b";
break;
#endif /* SM_IO_BINARY != 0 */
case SM_IO_RDWR:
default:
stdiomode = "r+";
break;
}
return -1;
return 0;
}
/*
** SETUP -- assign file type cookie when not already assigned
**
** Parameters:
** fp - the file pointer to get the cookie assigned
**
** Return:
** none.
*/
static void
{
{
{
case 0:
break;
case 1:
break;
case 2:
break;
default:
break;
}
}
}
/*
** SM_STDIOREAD -- read from the file
**
** Parameters:
** fp -- the file pointer
** buf -- location to place the read data
** n - number of bytes to read
**
** Returns:
** result from fread().
*/
char *buf;
size_t n;
{
register FILE *s;
}
/*
** SM_STDIOWRITE -- write to the file
**
** Parameters:
** fp -- the file pointer
** buf -- location of data to write
** n - number of bytes to write
**
** Returns:
** result from fwrite().
*/
char const *buf;
size_t n;
{
register FILE *s;
}
/*
** SM_STDIOSEEK -- set position within file
**
** Parameters:
** fp -- the file pointer
** offset -- new location based on 'whence'
** whence -- indicates "base" for 'offset'
**
** Returns:
** result from fseek().
*/
int whence;
{
register FILE *s;
}
/*
** SM_STDIOCLOSE -- close the file
**
** Parameters:
** fp -- close file pointer
**
** Return:
** status from fclose()
*/
int
{
register FILE *s;
return fclose(s);
}
/*
** SM_STDIOSETINFO -- set info for this open file
**
** Parameters:
** fp -- the file pointer
** what -- type of information setting
** valp -- memory location of info to set
**
** Return:
** Failure: -1 and sets errno
** Success: none (currently).
*/
/* ARGSUSED2 */
int
int what;
void *valp;
{
switch (what)
{
case SM_IO_WHAT_MODE:
default:
return -1;
}
}
/*
** SM_STDIOGETINFO -- get info for this open file
**
** Parameters:
** fp -- the file pointer
** what -- type of information request
** valp -- memory location to place info
**
** Return:
** Failure: -1 and sets errno
** Success: none (currently).
*/
/* ARGSUSED2 */
int
int what;
void *valp;
{
switch (what)
{
case SM_IO_WHAT_SIZE:
{
int fd;
if (fd < 0)
return -1;
else
return -1;
}
case SM_IO_WHAT_MODE:
default:
return -1;
}
}
/*
** SM_IO_STDIOOPEN -- create an SM_FILE which interfaces to a stdio FILE
**
** Parameters:
** stream -- an open stdio stream, as returned by fopen()
** mode -- the mode argument to fopen() which describes stream
**
** Return:
** On success, return a pointer to an SM_FILE object which
** can be used for reading and writing 'stream'.
** Abort if mode is gibberish or stream is bad.
** Raise an exception if we can't allocate memory.
*/
char *mode;
{
int fd;
bool r, w;
int ioflags;
SM_REQUIRE(fd >= 0);
r = w = false;
switch (mode[0])
{
case 'r':
r = true;
break;
case 'w':
case 'a':
w = true;
break;
default:
}
r = w = true;
if (r && w)
else if (r)
else
return fp;
}