Wed, 10 Oct 2012 09:32:06 +0200
discarded memprintf / memscanf
Reason: memscanf has no chance to get the amount of bytes read
universe@56 | 1 | #ifndef MEMSTREAM_H |
universe@56 | 2 | #define MEMSTREAM_H |
universe@56 | 3 | |
universe@56 | 4 | #include <stdio.h> |
universe@56 | 5 | |
universe@56 | 6 | /* as fmemopen is a C extension we provide our cross plattform stuff here */ |
universe@56 | 7 | |
universe@56 | 8 | #ifdef __cplusplus |
universe@56 | 9 | extern "C" { |
universe@56 | 10 | #endif |
universe@56 | 11 | |
universe@56 | 12 | |
universe@56 | 13 | /* as FILE is opaque, we don't do evil hacks but provide an alternative */ |
olaf@57 | 14 | typedef struct UcxMemstream UcxMemstream; |
universe@56 | 15 | |
universe@56 | 16 | UcxMemstream *ucx_memopen(void *space, size_t length); |
universe@56 | 17 | void ucx_memclose(UcxMemstream* stream); |
universe@56 | 18 | |
universe@56 | 19 | /* |
universe@56 | 20 | * Moves the position of the stream to a new position relative to whence. |
universe@56 | 21 | * |
universe@56 | 22 | * SEEK_SET marks the start of the buffer |
universe@56 | 23 | * SEEK_CUR marks the current position |
universe@56 | 24 | * SEEK_END marks the first 0-byte in the buffer |
universe@56 | 25 | * |
universe@56 | 26 | * ucx_memseek returns 0 on success and -1 if the new position is beyond the |
universe@56 | 27 | * bounds of the allocated buffer. In that case the position of the stream |
universe@56 | 28 | * remains unchanged. |
universe@56 | 29 | * |
universe@56 | 30 | */ |
olaf@57 | 31 | int ucx_memseek(UcxMemstream *stream, off_t offset, int whence); |
universe@56 | 32 | size_t ucx_memtell(UcxMemstream *stream); |
universe@56 | 33 | |
universe@56 | 34 | /* |
universe@56 | 35 | * returns non-zero, iff the current stream position has exceeded the last |
universe@56 | 36 | * available byte of the underlying buffer |
universe@56 | 37 | * |
universe@56 | 38 | */ |
universe@56 | 39 | int ucx_memeof(UcxMemstream *stream); |
universe@56 | 40 | |
universe@56 | 41 | /* memwrite, memread, memputc and memreadc shall not generate overflows */ |
universe@56 | 42 | size_t ucx_memio(void *d, size_t s, size_t n, UcxMemstream* m, _Bool read); |
universe@56 | 43 | #define ucx_memwrite(data, itemsize, nitems, memstream) \ |
universe@56 | 44 | ucx_memio(data, itemsize, nitems, memstream, 0) |
universe@56 | 45 | #define ucx_memread(data, itemsize, nitems, memstream) \ |
universe@56 | 46 | ucx_memio(data, itemsize, nitems, memstream, 1) |
universe@56 | 47 | int ucx_memputc(UcxMemstream *stream, int c); |
universe@56 | 48 | int ucx_memgetc(UcxMemstream *stream); |
universe@56 | 49 | |
universe@56 | 50 | #ifdef __cplusplus |
universe@56 | 51 | } |
universe@56 | 52 | #endif |
universe@56 | 53 | |
universe@56 | 54 | #endif /* MEMSTREAM_H */ |
universe@56 | 55 |