ucx/memstream.h

changeset 60
abae4669fba7
parent 58
733f22fca61a
equal deleted inserted replaced
59:c80c910fe191 60:abae4669fba7
1 #ifndef MEMSTREAM_H
2 #define MEMSTREAM_H
3
4 #include <stdio.h>
5
6 /* as fmemopen is a C extension we provide our cross plattform stuff here */
7
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11
12
13 /* as FILE is opaque, we don't do evil hacks but provide an alternative */
14 typedef struct UcxMemstream UcxMemstream;
15
16 UcxMemstream *ucx_memopen(void *space, size_t length);
17 void ucx_memclose(UcxMemstream* stream);
18
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);
33
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 /* 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);
49
50 #ifdef __cplusplus
51 }
52 #endif
53
54 #endif /* MEMSTREAM_H */
55

mercurial