ucx/memstream.h

Wed, 10 Oct 2012 09:32:06 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 10 Oct 2012 09:32:06 +0200
changeset 58
733f22fca61a
parent 57
e18157c52985
permissions
-rw-r--r--

discarded memprintf / memscanf

Reason: memscanf has no chance to get the amount of bytes read

     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);
    41 /* memwrite, memread, memputc and memreadc shall not generate overflows */
    42 size_t ucx_memio(void *d, size_t s, size_t n, UcxMemstream* m, _Bool read);
    43 #define ucx_memwrite(data, itemsize, nitems, memstream) \
    44     ucx_memio(data, itemsize, nitems, memstream, 0)
    45 #define ucx_memread(data, itemsize, nitems, memstream) \
    46         ucx_memio(data, itemsize, nitems, memstream, 1)
    47 int ucx_memputc(UcxMemstream *stream, int c);
    48 int ucx_memgetc(UcxMemstream *stream);
    50 #ifdef	__cplusplus
    51 }
    52 #endif
    54 #endif	/* MEMSTREAM_H */

mercurial