SPRAAK
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Data Structures | Namespaces | Macros | Typedefs | Enumerations | Functions | Variables
stream.c File Reference

Unified data IO. More...

Data Structures

struct  SprStreamOpenInfo
 
struct  SprStreamOpenCPHInfo
 
class  SprStream
 The generic stream pointer. For more info, see stream.c. More...
 
class  SprStreamFile
 Stream object that refers to classical file descriptors. More...
 
class  SprStreamNull
 Stream object that refers to the null device. More...
 
class  SprStreamBuf
 Stream object that refers to the null device. More...
 
class  SprStreamDynBuf
 Stream object that refers to a dynamically allocated buffer. More...
 
class  SprStreamDynStr
 Stream object that refers to a dynamic string. More...
 

Namespaces

 xref_spr_stream_principles
 Data IO in SPRAAK
 

Macros

#define spr_stderr
 Stream handler for the 'stderr' stream. More...
 

Typedefs

typedef struct SprStreamOpenParam SprStreamOpenParam
 
typedef int(* SprStreamOpenProtocol )(SprStreamOpenInfo *info, SprStreamOpenParam *param)
 
typedef int(* SprStreamOpenCoder )(SprStreamOpenInfo *info, SprStreamOpenParam *param)
 
typedef char *(* SprStreamOpenDecodeParam )(SprStreamOpenParam **param_info, char *param_desc, SprStreamOpenInfo *info)
 
typedef SprStreamOpenParam *(* SprStreamOpenFreeParam )(SprStreamOpenInfo *info, SprStreamOpenParam *param_data)
 
typedef int(* SprStreamOpenHdrRead )(SprStreamOpenInfo *info, SprStreamOpenParam *param)
 
typedef int(* SprStreamOpenHdrWrite )(SprStreamOpenInfo *info, SprStreamOpenParam *param)
 
typedef int(* SprStreamOpenCheck )(SprStreamOpenInfo *info, SprStreamOpenParam *param)
 
typedef const uint8_t *(* SprStream_buf_fill )(struct SprStream *restrict fd, int min_fill)
 
typedef uint8_t *(* SprStream_buf_flush )(struct SprStream *restrict fd)
 
typedef size_t(* SprStream_ebuf_read )(struct SprStream *restrict fd, void *restrict buf, size_t size)
 
typedef int(* SprStream_ebuf_write )(struct SprStream *restrict fd, const void *restrict buf, size_t size)
 

Enumerations

enum  SprStreamFlags {
  SPR_STREAM_CREATE, SPR_STREAM_TRUNC, SPR_STREAM_APPEND, SPR_STREAM_READ,
  SPR_STREAM_WRITE, SPR_STREAM_RW, SPR_STREAM_LINEBUF, SPR_STREAM_UNBUF,
  SPR_STREAM_SILENT, SPR_STREAM_SILENTEOF, SPR_STREAM_NONBLOCK, SPR_STREAM_KEEPKSET,
  SPR_STREAM_NOHDR, SPR_STREAM_SEEK, SPR_STREAM_REWIND, SPR_STREAM_AUTOCLOSE,
  SPR_STREAM_AUTORM, SPR_STREAM_ASCII
}
 Flags for opening a file. More...
 
enum  { SPR_STREAM_MODE_BIN, SPR_STREAM_MODE_BINSWAP, SPR_STREAM_MODE_ASCII }
 

Functions

size_t spr_stream_read (SprStream *restrict fd, void *restrict buf, size_t size)
 Read from a stream. More...
 
int spr_stream_write (SprStream *restrict fd, const void *restrict buf, size_t size)
 Write to a stream. More...
 
size_t spr_stream_skip (SprStream *restrict fd, size_t size)
 Skip data from a stream. More...
 
int spr_stream_fill (SprStream *restrict fd, int chr, size_t size)
 
SprStreamspr_stream_close_check_auto (SprStream *restrict fd, SprMsgId *restrict routine)
 
int spr_stream_mkdir_parents (SprMsgId *routine, char *path)
 
SprStreamspr_stream_nullqw_make (SprStreamNull *restrict fd)
 
off_t spr_stream_buf_tell (SprStreamBuf *restrict fd)
 
SprStreamspr_stream_buf_make (const char *name, uint8_t *buf, size_t size, size_t fill, unsigned int flags, SprKeySet *keys)
 
SprStreamspr_stream_bufqr_make (SprStreamBuf *restrict fd, const char *restrict buf, size_t size)
 
const void * spr_stream_buf_get (SprStreamBuf *fd)
 
void spr_stream_buf_rewind (SprStreamBuf *fd)
 
void * spr_stream_dynbuf_close_getdata (SprStreamDynBuf *restrict fd)
 
SprDynStr spr_stream_dynstr_close_getdata (SprStreamDynStr *restrict fd)
 
SprStreamspr_stream_dynbuf_make (const char *name, void *buf, size_t alen, size_t fill, unsigned int flags, SprKeySet *keys)
 
SprStreamspr_stream_dynstr_make (const char *name, SprDynStr str, size_t fill, unsigned int flags, SprKeySet *keys)
 
void * spr_stream_dynbufq_close (SprStreamDynBuf *restrict fd)
 
SprDynStr spr_stream_dynstrq_close (SprStreamDynStr *restrict fd)
 
SprStreamspr_stream_dynbufq_make (SprStreamDynBuf *restrict fd, void *restrict buf, size_t alen, size_t fill)
 
SprStreamspr_stream_dynstrq_make (SprStreamDynStr *restrict fd, SprDynStr str, size_t fill)
 
SprStreamspr_stream_close (SprStream *restrict fd)
 Close a stream. More...
 
SprStreamspr_stream_open (const char *restrict fname, unsigned int flags, SprKeySet *restrict keys)
 
SprStreamspr_stream_open_write (const char *restrict fname, unsigned int flags, const char *def_keys,...)
 
unsigned int spr_stream_check (const char *restrict fname, unsigned int flags)
 
int spr_fgetc (SprStream *restrict fd)
 
int spr_fgetc_utf8 (SprStream *restrict fd)
 
int spr_ungetc (SprStream *restrict fd, int chr)
 
int spr_ungetc_utf8 (SprStream *restrict fd, int chr)
 
int spr_fputc (SprStream *restrict fd, int chr)
 
int spr_fputc_utf8 (SprStream *restrict fd, int chr)
 
SprDynStr spr_fgets (SprDynStr restrict str, SprStream *restrict fd, unsigned int flags, int *restrict pos)
 
char * spr_fgets_alt (char *restrict str, int *restrict alen, SprStream *restrict fd, unsigned int flags, int *restrict pos)
 
ssize_t spr_fputs (SprStream *restrict fd, const char *restrict str)
 
ssize_t spr_fputsq (SprStream *restrict fd, const char *restrict str)
 
ssize_t spr_fputsoq (SprStream *restrict fd, const char *restrict str)
 
size_t spr_strlenq (const char *restrict str)
 
size_t spr_strlenoq (const char *restrict str)
 
int spr_stream_hex_write (SprStream *restrict fd, const void *restrict data, size_t Nel, size_t el_size)
 
int spr_stream_hex_read (SprStream *restrict fd, void *restrict data, size_t Nel, size_t el_size)
 
off_t spr_stream_copy_data (SprStream *restrict dst, SprStream *restrict src)
 
int spr_fprintf (SprStream *restrict fd, const char *restrict fmt,...)
 
int spr_vfprintf (SprStream *restrict fd, const char *restrict fmt, va_list args)
 
size_t spr_snprintf (char *restrict buf, size_t size, const char *restrict fmt,...)
 
size_t spr_snprintf0 (char *restrict buf, size_t size, const char *restrict fmt,...)
 
size_t spr_vsnprintf (char *restrict buf, size_t size, const char *restrict fmt, va_list args)
 
SprDynStr spr_sprintf (SprDynStr restrict str, const char *restrict fmt,...)
 
SprDynStr spr_vsprintf (SprDynStr restrict str, const char *restrict fmt, va_list args)
 
SprDynStr spr_soprintf (SprDynStr restrict str, size_t *restrict offset, const char *restrict fmt,...)
 
SprDynStr spr_vsoprintf (SprDynStr restrict str, size_t *restrict offset, const char *restrict fmt, va_list args)
 
char * spr_sprintf_alt (SprDynStr restrict str, int *restrict alen, const char *restrict fmt,...)
 
char * spr_vsprintf_alt (char *restrict str, int *restrict alen, const char *restrict fmt, va_list args)
 
char * spr_soprintf_alt (char *restrict str, int *restrict alen, int *restrict pos, const char *restrict fmt,...)
 
SprDynStr spr_vsoprintf_alt (char *restrict str, int *restrict alen, int *restrict pos, const char *restrict fmt, va_list args)
 
SprStreamspr_stream_open_tmp (const char *template_str, unsigned int flags,...)
 

Variables

const char * spr_stream_tmpdir
 

Detailed Description

Unified data IO.

This module provides routines for formatted and unformated input and output to streams (files, buffers, sockets, ...).

The routines in this module provide a unified (stream alike) interface to files on disk, unix pipes, devices, tcp-sockets, ftp-servers, stdin/out of other programs and other media where data can be sent to or read from.

The interface also transparently maps the different stream header formats –headers which describe the data content of the files– to a unified format, and provides for all conversions between the data formats used by the host computer and that on the input/output medium (ascii/binary format, with or without compression and big/little endian byte ordering).

See Also
Data IO in SPRAAK
Author
Kris Demuynck
Date
25/02/2008
Revision History:
08/08/2001 - KD
First version created (the concept of key-headers is based on a previous version written by Frank Schoeters).
Environment variables:
SPR_STREAM_CHECK
trace all open files and report any non-closed stream at the end of the program.
Bug:

The routines are not async-safe: signals should be handled in a separate thread (e.g. the main thread).

The routines are not MT-safe: multi-thread applications normally contain enough locking provisions to avoid race conditions on files, so the extra overhead is useless for most files.

Reading and writing floating point numbers in decimal format is subject to small rounding errors (least significant bit), i.e. the value is not always the decimal number with a given precision the closest to the real binary/decimal number.

Reading and writing long doubles in decimal format is no more precise than reading and writing doubles (no long); however the extra range of the exponent is still available.

No support for wide-characters (UTF-16, UTF-32); UTF-8 is supported.

Both stdin and stdout must be opened explicitely using the desired mode (buffering, etc.) with a call to spr_stream_open(). They must be closed before the program is ended as well. Both of them can be opened and closed several times (the unamed pipes are only closed at the very end of the program). stderr behaves the same, except that a default pointer (spr_stderr) is provided at the beginning of the program.