/*
* Copyright (c) 2000-2005 Proofpoint, Inc. and its suppliers.
* 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 <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include "local.h"
/*
** Overall:
** These maintain the `known seek offset' for seek optimization.
*/
/*
** SM_STDOPEN -- open a file with stdio behavior
**
** Not associated with the system's stdio in libc.
**
** Parameters:
** fp -- file pointer to be associated with the open
** info -- pathname of the file to be opened
** flags -- indicates type of access methods
** rpool -- ignored
**
** Returns:
** Failure: -1 and set errno
** Success: 0 or greater (fd of file from open(2)).
**
*/
/* ARGSUSED3 */
int
const void *info;
int flags;
const void *rpool;
{
int oflags;
switch (SM_IO_MODE(flags))
{
case SM_IO_RDWR:
break;
case SM_IO_RDWRTR:
break;
case SM_IO_RDONLY:
break;
case SM_IO_WRONLY:
break;
case SM_IO_APPEND:
break;
case SM_IO_APPENDRW:
break;
default:
return -1;
}
#ifdef O_BINARY
if (SM_IS_BINARY(flags))
#endif /* O_BINARY */
return -1; /* errno set by open() */
}
/*
** SM_STDREAD -- read from the file
**
** Parameters:
** fp -- file pointer to read from
** buf -- location to place read data
** n -- number of bytes to read
**
** Returns:
** Failure: -1 and sets errno
** Success: number of bytes read
**
** Side Effects:
** Updates internal offset into file.
*/
char *buf;
size_t n;
{
register int ret;
/* if the read succeeded, update the current offset */
if (ret > 0)
return ret;
}
/*
** SM_STDWRITE -- write to the file
**
** Parameters:
** fp -- file pointer ro write to
** buf -- location of data to be written
** n - number of bytes to write
**
** Returns:
** Failure: -1 and sets errno
** Success: number of bytes written
*/
char const *buf;
size_t n;
{
}
/*
** SM_STDSEEK -- set the file offset position
**
** Parmeters:
** fp -- file pointer to position
** offset -- how far to position from "base" (set by 'whence')
** whence -- indicates where the "base" of the 'offset' to start
**
** Results:
** Failure: -1 and sets errno
** Success: the current offset
**
** Side Effects:
** Updates the internal value of the offset.
*/
int whence;
{
return ret;
}
/*
** SM_STDCLOSE -- close the file
**
** Parameters:
** fp -- the file pointer to close
**
** Returns:
** Success: 0 (zero)
** Failure: -1 and sets errno
*/
int
{
}
/*
** SM_STDSETMODE -- set the access mode for the file
**
** Called by sm_stdsetinfo().
**
** Parameters:
** fp -- file pointer
** mode -- new mode to set the file access to
**
** Results:
** Success: 0 (zero);
** Failure: -1 and sets errno
*/
static int
const int *mode;
{
int flags = 0;
switch (SM_IO_MODE(*mode))
{
case SM_IO_RDWR:
break;
case SM_IO_RDONLY:
break;
case SM_IO_WRONLY:
break;
case SM_IO_APPEND:
default:
return -1;
}
return 0;
}
/*
** SM_STDGETMODE -- for getinfo determine open mode
**
** Called by sm_stdgetinfo().
**
** Parameters:
** fp -- the file mode being determined
** mode -- internal mode to map to external value
**
** Results:
** Failure: -1 and sets errno
** Success: external mode value
*/
static int
int *mode;
{
{
case SMRW:
*mode = SM_IO_RDWR;
break;
case SMRD:
*mode = SM_IO_RDONLY;
break;
case SMWR:
*mode = SM_IO_WRONLY;
break;
default:
return -1;
}
return 0;
}
/*
**
** Parameters:
** fp -- file to set info for
** what -- type of info to set
** valp -- location of data used for setting
**
** Returns:
** Failure: -1 and sets errno
** Success: >=0
*/
int
int what;
void *valp;
{
switch (what)
{
case SM_IO_WHAT_MODE:
default:
return -1;
}
}
/*
** SM_GETINFO -- get information about the open file
**
** Parameters:
** fp -- file to get info for
** what -- type of info to get
** valp -- location to place found info
**
** Returns:
** Success: may or may not place info in 'valp' depending
** on 'what' value, and returns values >=0. Return
** value may be the obtained info
** Failure: -1 and sets errno
*/
int
int what;
void *valp;
{
switch (what)
{
case SM_IO_WHAT_MODE:
case SM_IO_WHAT_FD:
case SM_IO_WHAT_SIZE:
{
else
return -1;
}
case SM_IO_IS_READABLE:
{
{
return -1;
}
return 1;
return 0;
}
default:
return -1;
}
}
/*
** SM_STDFDOPEN -- open file by primitive 'fd' rather than pathname
**
** I/O function to handle fdopen() stdio equivalence. The rest of
** the functions are the same as the sm_stdopen() above.
**
** Parameters:
** fp -- the file pointer to be associated with the open
** name -- the primitive file descriptor for association
** flags -- indicates type of access methods
** rpool -- ignored
**
** Results:
** Success: primitive file descriptor value
** Failure: -1 and sets errno
*/
/* ARGSUSED3 */
int
const void *info;
int flags;
const void *rpool;
{
switch (SM_IO_MODE(flags))
{
case SM_IO_RDWR:
break;
case SM_IO_RDONLY:
break;
case SM_IO_WRONLY:
break;
case SM_IO_APPEND:
break;
case SM_IO_APPENDRW:
break;
default:
return -1;
}
#ifdef O_BINARY
if (SM_IS_BINARY(flags))
#endif /* O_BINARY */
/* Make sure the mode the user wants is a subset of the actual mode. */
return -1;
{
return -1;
}
}
/*
** SM_IO_FOPEN -- open a file
**
** Same interface and semantics as the open() system call,
** except that it returns SM_FILE_T* instead of a file descriptor.
**
** Parameters:
** pathname -- path of file to open
** flags -- flags controlling the open
** ... -- option "mode" for opening the file
**
** Returns:
** Raises an exception on heap exhaustion.
** Returns NULL and sets errno if open() fails.
** Returns an SM_FILE_T pointer on success.
*/
#if SM_VA_STD
#else /* SM_VA_STD */
char *pathname;
int flags;
#endif /* SM_VA_STD */
{
int ioflags;
{
}
else
mode = 0;
{
case O_RDONLY:
break;
case O_WRONLY:
break;
case O_RDWR:
break;
default:
}
{
return NULL;
}
return fp;
}