ucx/memstream.h

Tue, 09 Oct 2012 16:46:29 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 09 Oct 2012 16:46:29 +0200
changeset 57
e18157c52985
parent 56
76caac0da4a0
child 58
733f22fca61a
permissions
-rw-r--r--

some fixes

     1 #ifndef MEMSTREAM_H
     2 #define	MEMSTREAM_H
     4 #include <stdio.h>
     6 /* as fmemopen is a C extension we provide our cross plattform stuff here */
     8 #ifdef	__cplusplus
     9 extern "C" {
    10 #endif
    13 /* as FILE is opaque, we don't do evil hacks but provide an alternative */
    14 typedef struct UcxMemstream UcxMemstream;
    16 UcxMemstream *ucx_memopen(void *space, size_t length);
    17 void ucx_memclose(UcxMemstream* stream);
    19 /*
    20  * Moves the position of the stream to a new position relative to whence.
    21  *
    22  * SEEK_SET marks the start of the buffer
    23  * SEEK_CUR marks the current position
    24  * SEEK_END marks the first 0-byte in the buffer
    25  *
    26  * ucx_memseek returns 0 on success and -1 if the new position is beyond the
    27  * bounds of the allocated buffer. In that case the position of the stream
    28  * remains unchanged.
    29  *
    30  */
    31 int ucx_memseek(UcxMemstream *stream, off_t offset, int whence);
    32 size_t ucx_memtell(UcxMemstream *stream);
    34 /*
    35  * returns non-zero, iff the current stream position has exceeded the last
    36  * available byte of the underlying buffer
    37  *
    38  */
    39 int ucx_memeof(UcxMemstream *stream);
    40 /*
    41  * returns non-zero, iff the current stream position has exceeded the length
    42  * of the underlying buffer
    43  *
    44  * in contrast to ucx_memeof this function will return zero, if the current
    45  * position exactly matches the buffer length
    46  *
    47  * this function should be called after any ucx_memprintf/ucx_memscanf call
    48  */
    49 int ucx_memoverflow(UcxMemstream *stream);
    51 /* memwrite, memread, memputc and memreadc shall not generate overflows */
    52 size_t ucx_memio(void *d, size_t s, size_t n, UcxMemstream* m, _Bool read);
    53 #define ucx_memwrite(data, itemsize, nitems, memstream) \
    54     ucx_memio(data, itemsize, nitems, memstream, 0)
    55 #define ucx_memread(data, itemsize, nitems, memstream) \
    56         ucx_memio(data, itemsize, nitems, memstream, 1)
    57 int ucx_memputc(UcxMemstream *stream, int c);
    58 int ucx_memgetc(UcxMemstream *stream);
    60 /* printf / scanf may generate overflows */
    61 int ucx_memprintf(UcxMemstream *stream, const char* format, ...);
    62 int ucx_memscanf(UcxMemstream *stream, const char* format, ...);
    64 #ifdef	__cplusplus
    65 }
    66 #endif
    68 #endif	/* MEMSTREAM_H */

mercurial