Lely core libraries
2.2.5
|
Go to the documentation of this file.
22 #ifndef LELY_UTIL_MEMBUF_H_
23 #define LELY_UTIL_MEMBUF_H_
30 #ifndef LELY_UTIL_MEMBUF_INLINE
31 #define LELY_UTIL_MEMBUF_INLINE static inline
100 struct membuf *buf, ptrdiff_t offset);
132 struct membuf *buf,
const void *ptr,
size_t size);
164 return buf->
end - buf->
cur;
170 char *cur = buf->
cur + offset;
171 if (cur - buf->
begin < 0) {
173 offset = cur - buf->
cur;
174 }
else if (buf->
end - cur < 0) {
176 offset = cur - buf->
cur;
186 void *cur = buf->
cur;
196 memcpy(cur, ptr, size);
204 #endif // !LELY_UTIL_MEMBUF_H_
void * membuf_alloc(struct membuf *buf, size_t *size)
Creates region of *size bytes in a memory buffer, starting at the current position indicator given by...
void membuf_init(struct membuf *buf)
Initializes a memory buffer.
void * membuf_begin(const struct membuf *buf)
Returns a pointer to the first byte in a memory buffer.
size_t membuf_size(const struct membuf *buf)
Returns the total number of bytes written to a memory buffer.
size_t membuf_write(struct membuf *buf, const void *ptr, size_t size)
Writes data to a memory buffer.
char * end
A pointer to one past the last byte in the buffer.
ptrdiff_t membuf_seek(struct membuf *buf, ptrdiff_t offset)
Adjusts the position indicator of a memory buffer by offset bytes.
void membuf_clear(struct membuf *buf)
Clears a memory buffer.
void membuf_flush(struct membuf *buf, size_t size)
Flushes size bytes from the beginning of a memory buffer.
size_t membuf_capacity(const struct membuf *buf)
Returns the number of unused bytes remaining in a memory buffer.
char * cur
A pointer to one past the last byte written to the buffer.
char * begin
A pointer to the first byte in the buffer.
size_t membuf_reserve(struct membuf *buf, size_t size)
Resizes a memory buffer, if necessary, to make room for at least an additional size bytes.
void membuf_fini(struct membuf *buf)
Finalizes a memory buffer.