1N/A * Copyright (c) 2000-2002, 2004 Sendmail, Inc. and its suppliers. 1N/A * All rights reserved. 1N/A * Copyright (c) 1990, 1993 1N/A * The Regents of the University of California. All rights reserved. 1N/A * This code is derived from software contributed to Berkeley by 1N/A * By using this file, you agree to the terms and conditions set 1N/A * forth in the LICENSE file which can be found at the top level of 1N/A * the sendmail distribution. 1N/A#
pragma ident "%Z%%M% %I% %E% SMI" 1N/A** OPENALRM -- handler when timeout activated for sm_io_open() 1N/A** Returns flow of control to where setjmp(OpenTimeOut) was set. 1N/A** returns flow of control to setjmp(OpenTimeOut). 1N/A** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD 1N/A** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE 1N/A** REOPENALRM -- handler when timeout activated for sm_io_reopen() 1N/A** Returns flow of control to where setjmp(ReopenTimeOut) was set. 1N/A** returns flow of control to setjmp(ReopenTimeOut). 1N/A** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD 1N/A** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE 1N/A** SM_IO_OPEN -- open a file of a specific type 1N/A** type -- type of file to open 1N/A** timeout -- time to complete the open 1N/A** info -- info describing what is to be opened (type dependant) 1N/A** flags -- user selected flags 1N/A** rpool -- pointer to rpool to be used for this open 1N/A** Raises exception on heap exhaustion. 1N/A** Aborts if type is invalid. 1N/A** Returns NULL and sets errno 1N/A** - when the type specific open fails 1N/A** - when open vector errors 1N/A** - when flags not set or invalid 1N/A** Success returns a file pointer to the opened file type. 1N/A /* Okay, this is where we set the timeout. */ 1N/A /* We're back. So undo our timeout and handler */ 1N/A#
endif /* SM_RPOOL */ 1N/A** SM_IO_DUP -- duplicate a file pointer 1N/A** fp -- file pointer to duplicate 1N/A** Success - the duplicated file pointer 1N/A** Failure - NULL (was an invalid file pointer or too many open) 1N/A** Increments the duplicate counter (dup_cnt) for the open file pointer. 1N/A** The counter counts the number of duplicates. When the duplicate 1N/A** counter is 0 (zero) then the file pointer is the only one left 1N/A** (no duplicates, it is the only one). 1N/A /* Can't let f_dup_cnt wrap! */ 1N/A** SM_IO_REOPEN -- open a new file using the old file pointer 1N/A** type -- file type to be opened 1N/A** timeout -- time to complete the reopen 1N/A** info -- infomation about what is to be "re-opened" (type dep.) 1N/A** flags -- user flags to map to internal flags 1N/A** rpool -- rpool file to be associated with 1N/A** fp -- the file pointer to reuse 1N/A** Raises an exception on heap exhaustion. 1N/A** Aborts if type is invalid. 1N/A** Failure: returns NULL 1N/A** Success: returns "reopened" file pointer 1N/A ** Filling the buffer will take time and we are wanted to 1N/A ** return immediately. So... 1N/A /* Okay, this is where we set the timeout. */ 1N/A ** There are actually programs that depend on being able to "reopen" 1N/A ** descriptors that weren't originally open. Keep this from breaking. 1N/A ** Remember whether the stream was open to begin with, and which file 1N/A ** descriptor (if any) was associated with it. If it was attached to 1N/A ** a descriptor, defer closing it; reopen("/dev/stdin", "r", stdin) 1N/A ** should work. This is unnecessary if it was not a Unix file. 1N/A /* flush the stream; ANSI doesn't require this. */ 1N/A /* We're back. So undo our timeout and handler */ 1N/A ** We're not preserving this logic (below) for sm_io because it is now 1N/A ** abstracted at least one "layer" away. By closing and reopening 1N/A ** the 1st fd used should be the just released one (when Unix 1N/A ** behavior followed). Old comment:: 1N/A ** If reopening something that was open before on a real file, try 1N/A ** to maintain the descriptor. Various C library routines (perror) 1N/A ** assume stderr is always fd STDERR_FILENO, even if being reopen'd. 1N/A#
endif /* SM_RPOOL */ 1N/A** SM_IO_AUTOFLUSH -- link another file to this for auto-flushing 1N/A** When a read occurs on fp, fp2 will be flushed iff there is no 1N/A** data waiting on fp. 1N/A** fp -- the file opened for reading. 1N/A** fp2 -- the file opened for writing. 1N/A** The old flush file pointer. 1N/A** SM_IO_AUTOMODE -- link another file to this for auto-moding 1N/A** When the mode (blocking or non-blocking) changes for fp1 then 1N/A** update fp2's mode at the same time. This is to be used when 1N/A** a system dup() has generated a second file descriptor for 1N/A** another sm_io_open() by file descriptor. The modes have been 1N/A** linked in the system and this formalizes it for sm_io internally. 1N/A** fp1 -- the first file 1N/A** fp2 -- the second file