#ifndef _LSUP_BUFFER_H #define _LSUP_BUFFER_H #include "core.h" typedef struct LSUP_Buffer { void *addr; size_t size; } LSUP_Buffer; LSUP_Buffer *LSUP_buffer_new(size_t size); int LSUP_buffer_init(LSUP_Buffer *buf, size_t size); void LSUP_buffer_print(const LSUP_Buffer *buf); int LSUP_buffer_copy(LSUP_Buffer *dest, const LSUP_Buffer *src); void LSUP_buffer_done(LSUP_Buffer *buf); /** * Return whether two buffers are equal. * * This is faster than LSUP_buffer_cmp because it returns immediately if the * sizes of the buffers differ. */ inline bool LSUP_buffer_eq(const LSUP_Buffer *buf1, const LSUP_Buffer *buf2) { if (buf1->size != buf2->size) return false; return (memcmp(buf1->addr, buf2->addr, buf1->size) == 0) ? true : false; } inline int LSUP_buffer_cmp(const LSUP_Buffer *buf1, const LSUP_Buffer *buf2) { return memcmp(buf1->addr, buf2->addr, max(buf1->size, buf2->size)); } #endif