HTML automatically generated with rman
Table of Contents

Name

stropen, strclose, strdelete, strname, strseek - file-stream enhanced utilities

Synopsis


#include <stdinc.h>stream stropen(string filename, string mode)void strclose(stream
str)void strdelete(stream str, bool scratch)string strname(stream str)bool
strseek(stream str)
Descriptionstropen() opens a file by filename and associates
a stream with it, much like fopen(3) does. It has a few additional features:
(1) existing files cannot be opened for writing unless  mode=w! (mode=a!
is also permitted), 
(2) names of form - map to stdin/stdout, depending on
mode, 
(3) names of the form -num for some small num set up a stream to read/write
file descriptor num. 
(4) With mode=s a file is opened in write-scratch mode.
Whenever strclose is called, the file is also deleted. When the filename
does not start with a "/", a unique temporary filename is automatically
created. 
(5) Output file with the name "." (dot) are equivalent to a bit
sink (/dev/null). 
(6) Input files that look like a URL (http://.., ftp://..
etc) are opened with popen(3) and data directly passed back to the client

Note that fopen(3) itself officially recognizes the following  modes:r,
w, a, r+, w+, a+. 
strclose() closes a stream, which is the recommended practice
 within NEMO (formally, an exit from the program using exit(3) also closes
all open files properly). Each opened stream uses additional space in internal
tables that are free’d when strclose is called.  
strdelete() deletes the
file associated with the stream str  previously opened with stropen.  If
scratch is set TRUE it will always delete the file, if set to  FALSE the
file must have been opened in scratch mode to be deleted. This routine also
clears the internal filetable, that was used  when stropen was called. 
strname()
returns the name of the file that had been opened by stropen. Note it returns
a pointer to an internal static table, and should not be overwritten. See
also scopy(3NEMO). 
strseek returns seekability of a stream. This is primarely
useful for filestruct, which might need to know if stream i/o can be optimized
with deferred input. 
CaveatsFiles that are given as URLs can easily cause
confusion, because a malformed or mistyped URL can give either no output
or whatever the server  decides to return on non-existing names. Since this
is often a webpage with an error message, perfectly legal output,  the
client on the NEMO side will get no error message. 
       % tsf http://bima.astro.umd.edu/nemo/test/p10-a
       ### Fatal error [tsf]: gethdr: bad magic: 20474

See Also

fopen(3) , fclose(3) , filestruct(3NEMO) , strlib(3NEMO) , getparam(3NEMO) , mstropen(3NEMO)

Author

Joshua Barnes, Peter Teuben

Files


~/src/kernel/io      stropen.c, filesecret.c

Update History


23-jul-90    created                Josh
5-oct-90    added strdelete and strname; man page written    PJT
1-mar-91    fixed bug in stropen - improved doc    PJT
19-may-92    added strseek - fixed verbosity in strdelete    PJT
5-nov-93    added special "." filename mode for /dev/null    pjt
22-mar-00    scratch files cannot exist, otherwise error    pjt
9-dec-05    add simple ability to grab URL-based files    PJT


Table of Contents