universe@56: #ifndef MEMSTREAM_H universe@56: #define MEMSTREAM_H universe@56: universe@56: #include universe@56: universe@56: /* as fmemopen is a C extension we provide our cross plattform stuff here */ universe@56: universe@56: #ifdef __cplusplus universe@56: extern "C" { universe@56: #endif universe@56: universe@56: universe@56: /* as FILE is opaque, we don't do evil hacks but provide an alternative */ olaf@57: typedef struct UcxMemstream UcxMemstream; universe@56: universe@56: UcxMemstream *ucx_memopen(void *space, size_t length); universe@56: void ucx_memclose(UcxMemstream* stream); universe@56: universe@56: /* universe@56: * Moves the position of the stream to a new position relative to whence. universe@56: * universe@56: * SEEK_SET marks the start of the buffer universe@56: * SEEK_CUR marks the current position universe@56: * SEEK_END marks the first 0-byte in the buffer universe@56: * universe@56: * ucx_memseek returns 0 on success and -1 if the new position is beyond the universe@56: * bounds of the allocated buffer. In that case the position of the stream universe@56: * remains unchanged. universe@56: * universe@56: */ olaf@57: int ucx_memseek(UcxMemstream *stream, off_t offset, int whence); universe@56: size_t ucx_memtell(UcxMemstream *stream); universe@56: universe@56: /* universe@56: * returns non-zero, iff the current stream position has exceeded the last universe@56: * available byte of the underlying buffer universe@56: * universe@56: */ universe@56: int ucx_memeof(UcxMemstream *stream); universe@56: universe@56: /* memwrite, memread, memputc and memreadc shall not generate overflows */ universe@56: size_t ucx_memio(void *d, size_t s, size_t n, UcxMemstream* m, _Bool read); universe@56: #define ucx_memwrite(data, itemsize, nitems, memstream) \ universe@56: ucx_memio(data, itemsize, nitems, memstream, 0) universe@56: #define ucx_memread(data, itemsize, nitems, memstream) \ universe@56: ucx_memio(data, itemsize, nitems, memstream, 1) universe@56: int ucx_memputc(UcxMemstream *stream, int c); universe@56: int ucx_memgetc(UcxMemstream *stream); universe@56: universe@56: #ifdef __cplusplus universe@56: } universe@56: #endif universe@56: universe@56: #endif /* MEMSTREAM_H */ universe@56: