/*
* Copyright (c) 2000-2002, 2004 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 <errno.h>
#include <setjmp.h>
#include "local.h"
static void reopenalrm __P((int));
/*
** OPENALRM -- handler when timeout activated for sm_io_open()
**
** Returns flow of control to where setjmp(OpenTimeOut) was set.
**
** Parameters:
** sig -- unused
**
** Returns:
** does not return
**
** Side Effects:
** returns flow of control to setjmp(OpenTimeOut).
**
** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
** DOING.
*/
/* ARGSUSED0 */
static void
int sig;
{
}
/*
** REOPENALRM -- handler when timeout activated for sm_io_reopen()
**
** Returns flow of control to where setjmp(ReopenTimeOut) was set.
**
** Parameters:
** sig -- unused
**
** Returns:
** does not return
**
** Side Effects:
** returns flow of control to setjmp(ReopenTimeOut).
**
** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
** DOING.
*/
/* ARGSUSED0 */
static void
int sig;
{
}
/*
** SM_IO_OPEN -- open a file of a specific type
**
** Parameters:
** type -- type of file to open
** timeout -- time to complete the open
** info -- info describing what is to be opened (type dependant)
** flags -- user selected flags
** rpool -- pointer to rpool to be used for this open
**
** Returns:
** Raises exception on heap exhaustion.
** Aborts if type is invalid.
** Returns NULL and sets errno
** - when the type specific open fails
** - when open vector errors
** - when flags not set or invalid
** Success returns a file pointer to the opened file type.
*/
const void *info;
int flags;
const void *rpool;
{
int ioflags;
if (ioflags == 0)
{
/* must give some indication/intent */
return NULL;
}
if (timeout == SM_TIME_DEFAULT)
if (timeout == SM_TIME_IMMEDIATE)
{
return NULL;
}
/* Okay, this is where we set the timeout. */
if (timeout != SM_TIME_FOREVER)
{
if (setjmp(OpenTimeOut) != 0)
{
return NULL;
}
}
{
return NULL;
}
/* We're back. So undo our timeout and handler */
#if SM_RPOOL
#endif /* SM_RPOOL */
return fp;
}
/*
** SM_IO_DUP -- duplicate a file pointer
**
** Parameters:
** fp -- file pointer to duplicate
**
** Returns:
** Success - the duplicated file pointer
** Failure - NULL (was an invalid file pointer or too many open)
**
** Increments the duplicate counter (dup_cnt) for the open file pointer.
** The counter counts the number of duplicates. When the duplicate
** counter is 0 (zero) then the file pointer is the only one left
** (no duplicates, it is the only one).
*/
{
{
return NULL;
}
{
/* Can't let f_dup_cnt wrap! */
return NULL;
}
return fp;
}
/*
** SM_IO_REOPEN -- open a new file using the old file pointer
**
** Parameters:
** type -- file type to be opened
** timeout -- time to complete the reopen
** info -- infomation about what is to be "re-opened" (type dep.)
** flags -- user flags to map to internal flags
** rpool -- rpool file to be associated with
** fp -- the file pointer to reuse
**
** Returns:
** Raises an exception on heap exhaustion.
** Aborts if type is invalid.
** Failure: returns NULL
** Success: returns "reopened" file pointer
*/
int SM_NONVOLATILE timeout;
const void *info;
int flags;
const void *rpool;
{
{
return NULL;
}
if (!Sm_IO_DidInit)
sm_init();
if (timeout == SM_TIME_DEFAULT)
if (timeout == SM_TIME_IMMEDIATE)
{
/*
** Filling the buffer will take time and we are wanted to
** return immediately. So...
*/
return NULL;
}
/* Okay, this is where we set the timeout. */
if (timeout != SM_TIME_FOREVER)
{
if (setjmp(ReopenTimeOut) != 0)
{
return NULL;
}
}
/*
** There are actually programs that depend on being able to "reopen"
** descriptors that weren't originally open. Keep this from breaking.
** Remember whether the stream was open to begin with, and which file
** descriptor (if any) was associated with it. If it was attached to
** should work. This is unnecessary if it was not a Unix file.
*/
{
else
{
/* flush the stream; ANSI doesn't require this. */
}
}
/* We're back. So undo our timeout and handler */
if (ret < 0)
{
return NULL;
}
/*
** We're not preserving this logic (below) for sm_io because it is now
** abstracted at least one "layer" away. By closing and reopening
** the 1st fd used should be the just released one (when Unix
** behavior followed). Old comment::
** If reopening something that was open before on a real file, try
** to maintain the descriptor. Various C library routines (perror)
** assume stderr is always fd STDERR_FILENO, even if being reopen'd.
*/
#if SM_RPOOL
#endif /* SM_RPOOL */
return fp2;
}
/*
** SM_IO_AUTOFLUSH -- link another file to this for auto-flushing
**
** When a read occurs on fp, fp2 will be flushed iff there is no
** data waiting on fp.
**
** Parameters:
** fp -- the file opened for reading.
** fp2 -- the file opened for writing.
**
** Returns:
** The old flush file pointer.
*/
{
return savefp;
}
/*
** SM_IO_AUTOMODE -- link another file to this for auto-moding
**
** When the mode (blocking or non-blocking) changes for fp1 then
** update fp2's mode at the same time. This is to be used when
** a system dup() has generated a second file descriptor for
** another sm_io_open() by file descriptor. The modes have been
** linked in the system and this formalizes it for sm_io internally.
**
** Parameters:
** fp1 -- the first file
** fp2 -- the second file
**
** Returns:
** nothing
*/
void
{
}