Open the stream (file) the (rich) file name fname refers to. The flags argument can be a combination of the following flags:
- SPR_STREAM_CREATE
- Create the file if it does not exist.
- SPR_STREAM_TRUNC
- When opening a file for writing, truncate the file to length 0.
- SPR_STREAM_APPEND
- Open the file and position the write pointer to the end of the file.
- SPR_STREAM_READ
- Open the file for reading (the default).
- SPR_STREAM_WRITE
- Open the file for writing.
- SPR_STREAM_RW
- Open the file for reading and writing. The stream will be put in WRITE mode initialy if the CREATE, TRUNC or APPEND flag is set as well, otherwise the initial mode for the stream will be the READ mode.
- SPR_STREAM_LINEBUF
- Buffer the IO operations on a line by line base instead of the normal 4K blocks.
- SPR_STREAM_UNBUF
- Do minimal (i.e. almost no) buffering on the IO operations.
- SPR_STREAM_SILENT
- Do not report read/write/close errors on this stream via the message system.
- SPR_STREAM_SILENTEOF
- Do not report EOF errors on this stream via the message system.
- SPR_STREAM_NONBLOCK
- Open the file in a non-blocking mode, i.e. reads will return the available amount of data only, writes may not write all requested data, so retries may be needed.
- SPR_STREAM_KEEPKSET
- Do not free the keyset given as argument to the spr_stream_open() routine when opening the stream fails.
- SPR_STREAM_NOHDR
- Open the file without writing/reading a header.
- SPR_STREAM_SEEK
- Make sure random seeks on the file are possible.
- SPR_STREAM_REWIND
- Make sure a rewind (full restart) on the file is possible.
- SPR_STREAM_AUTOCLOSE
- Automatically close the file when the program terminates.
- SPR_STREAM_AUTORM
- Automatically close and remove the file when the program terminates.
- SPR_STREAM_ASCII
- Force the stream in ASCII mode after opening it.
When opening a file for writing, the keys argument is the set of keys that will make up the file header (keys may equal NULL when opening a header-less file for writing).
When opening a file for reading, the keys argument may either be NULL or may point to a existing set of keys. In the latter case, the keys found in the file will be added to keys, overwriting existing keys with the same name. In other words, when opening for reading, the keys argument can be used to provide default values of certain keys.
If a non NULL keys argument is given, the ownership of keys will be transfered to the freshly opened stream (the return value). keys will be freed if the stream fails to open (a NULL return value), except when the SPR_STREAM_KEEPKSET flag is set.
- Returns
- A valid stream handler or NULL on error.