fopen.c revision 1
** OPENALRM -- handler when timeout activated for sm_io_open() ** Returns flow of control to where setjmp(OpenTimeOut) was set. ** 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 ** REOPENALRM -- handler when timeout activated for sm_io_reopen() ** Returns flow of control to where setjmp(ReopenTimeOut) was set. ** 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 ** SM_IO_OPEN -- open a file of a specific type ** 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 ** 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. /* Okay, this is where we set the timeout. */ /* We're back. So undo our timeout and handler */ ** SM_IO_DUP -- duplicate a file pointer ** fp -- file pointer to duplicate ** 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). /* Can't let f_dup_cnt wrap! */ ** SM_IO_REOPEN -- open a new file using the old file pointer ** 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 ** Raises an exception on heap exhaustion. ** Aborts if type is invalid. ** Success: returns "reopened" file pointer ** Filling the buffer will take time and we are wanted to ** return immediately. So... /* Okay, this is where we set the timeout. */ ** 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 ** a descriptor, defer closing it; reopen("/dev/stdin", "r", stdin) ** should work. This is unnecessary if it was not a Unix file. /* flush the stream; ANSI doesn't require this. */ /* We're back. So undo our timeout and handler */ ** 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. ** 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 ** fp -- the file opened for reading. ** fp2 -- the file opened for writing. ** The old flush file pointer. ** 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. ** fp2 -- the second file