refill.c revision 49218d4f8e4d84d1c08aeb267bcf6e451f2056dc
/*
* Copyright (c) 2000-2001 Sendmail, 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.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <setjmp.h>
#include <signal.h>
#include <fcntl.h>
#include <string.h>
#include "local.h"
/*
** SM_IO_RD_TIMEOUT -- measured timeout for reads
**
** This #define uses a select() to wait for the 'fd' to become readable.
** The select() can be active for up to 'To' time. The select() may not
** use all of the the 'To' time. Hence, the amount of "wall-clock" time is
** measured to decide how much to subtract from 'To' to update it. On some
** the updating of 'To' must be done ourselves; a copy of 'To' is passed
** since a BSD-like system will have updated it and we don't want to
** double the time used!
** Note: if a valid 'fd' doesn't exist yet, don't use this (e.g. the
**
** Parameters
** fp -- the file pointer for the active file
** fd -- raw file descriptor (from 'fp') to use for select()
** to -- struct timeval of the timeout
** timeout -- the original timeout value
** sel_ret -- the return value from the select()
**
** Returns:
** nothing, flow through code
*/
{ \
errno = 0; \
if (timeout == SM_TIME_IMMEDIATE) \
{ \
return SM_IO_EOF; \
} \
{ \
return SM_IO_EOF; \
} \
FD_ZERO(&sm_io_to_mask); \
FD_ZERO(&sm_io_x_mask); \
return SM_IO_EOF; \
&sm_io_x_mask, (to)); \
if ((sel_ret) < 0) \
{ \
/* something went wrong, errno set */ \
return SM_IO_EOF; \
} \
else if ((sel_ret) == 0) \
{ \
/* timeout */ \
return SM_IO_EOF; \
} \
/* calulate wall-clock time used */ \
return SM_IO_EOF; \
}
/*
** SM_LFLUSH -- flush a file if it is line buffered and writable
**
** Parameters:
** fp -- file pointer to flush
** timeout -- original timeout value (in milliseconds)
**
** Returns:
** Failure: returns SM_IO_EOF and sets errno
** Success: returns 0
*/
static int
int *timeout;
{
return 0;
}
/*
** SM_REFILL -- refill a buffer
**
** Parameters:
** fp -- file pointer for buffer refill
** timeout -- time to complete filling the buffer in milliseconds
**
** Returns:
** Success: returns 0
** Failure: returns SM_IO_EOF
*/
int
int timeout;
{
int ret, r;
int fd;
if (timeout == SM_TIME_DEFAULT)
if (timeout == SM_TIME_IMMEDIATE)
{
/*
** Filling the buffer will take time and we are wanted to
** return immediately. And we're not EOF or ERR really.
** So... the failure is we couldn't do it in time.
*/
return 0;
}
/* make sure stdio is set up */
if (!Sm_IO_DidInit)
sm_init();
return SM_IO_EOF;
/* if not already reading, have to be reading and writing */
{
{
return SM_IO_EOF;
}
/* switch to reading */
{
return SM_IO_EOF;
}
}
else
{
/*
** We were reading. If there is an ungetc buffer,
** we must have been reading from that. Drop it,
** restoring the previous buffer (if any). If there
** is anything in that buffer, return.
*/
{
{
/* revert blocking state */
return 0;
}
}
}
sm_makebuf(fp);
/*
** Before reading from a line buffered or unbuffered file,
** flush all line buffered output files, per the ANSI C standard.
*/
/*
** If this file is linked to another, and we are going to hang
** on the read, flush the linked file before continuing.
*/
/*
** The do-while loop stops trying to read when something is read
** or it appears that the timeout has expired before finding
** something available to be read (via select()).
*/
ret = 0;
do
{
errno = 0; /* needed to ensure EOF correctly found */
if (r <= 0)
{
if (r == 0 && errno == 0)
break; /* EOF found */
goto err; /* errno set */
/* read would block */
}
} while (r <= 0 && ret > 0);
err:
if (r <= 0)
{
if (r == 0)
else
return SM_IO_EOF;
}
return 0;
}
/*
** SM_RGET -- refills buffer and returns first character
**
** Handle sm_getc() when the buffer ran out:
** Refill, then return the first character in the newly-filled buffer.
**
** Parameters:
** fp -- file pointer to work on
** timeout -- time to complete refill
**
** Returns:
** Success: first character in refilled buffer as an int
** Failure: SM_IO_EOF
*/
int
int timeout;
{
{
}
return SM_IO_EOF;
}