#ifndef UCX_BUFFER_H
#define UCX_BUFFER_H
#include "ucx.h"
#include <sys/types.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
#define UCX_BUFFER_DEFAULT 0x00
#define UCX_BUFFER_AUTOFREE 0x01
#define UCX_BUFFER_AUTOEXTEND 0x02
typedef struct {
char *space;
size_t pos;
size_t capacity;
size_t size;
int flags;
} UcxBuffer;
UcxBuffer *ucx_buffer_new(
void *space,
size_t capacity,
int flags);
void ucx_buffer_free(UcxBuffer* buffer);
UcxBuffer* ucx_buffer_extract(UcxBuffer *src,
size_t start,
size_t length,
int flags);
#define ucx_buffer_clone(src,flags) \
ucx_buffer_extract(src,
0, (src)->capacity, flags)
int ucx_buffer_seek(UcxBuffer *buffer,
off_t offset,
int whence);
#define ucx_buffer_clear(buffer) memset(buffer->space,
0, buffer->size); \
buffer->size =
0; buffer->pos =
0;
int ucx_buffer_eof(UcxBuffer *buffer);
int ucx_buffer_extend(UcxBuffer *buffer,
size_t additional_bytes);
size_t ucx_buffer_write(
const void *ptr,
size_t size,
size_t nitems,
UcxBuffer *buffer);
size_t ucx_buffer_read(
void *ptr,
size_t size,
size_t nitems,
UcxBuffer *buffer);
int ucx_buffer_putc(UcxBuffer *buffer,
int c);
int ucx_buffer_getc(UcxBuffer *buffer);
size_t ucx_buffer_puts(UcxBuffer *buffer,
char *str);
#ifdef __cplusplus
}
#endif
#endif