12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #ifndef _LSUP_BUFFER_H
- #define _LSUP_BUFFER_H
- #include "core.h"
- typedef struct LSUP_Buffer {
- void *addr;
- size_t size;
- } LSUP_Buffer;
- LSUP_rc
- LSUP_buffer_new(size_t size, LSUP_Buffer *buf_p);
- LSUP_rc
- LSUP_buffer_reset(LSUP_Buffer *buf, size_t size);
- void LSUP_buffer_print(const LSUP_Buffer *buf);
- LSUP_rc
- LSUP_buffer_copy(const LSUP_Buffer *src, LSUP_Buffer *dest);
- void LSUP_buffer_free(LSUP_Buffer *buf);
- /** @brief Compare two buffers.
- *
- * The return value is the same as memcmp.
- */
- inline int LSUP_buffer_cmp(const LSUP_Buffer *buf1, const LSUP_Buffer *buf2)
- { return memcmp(buf1->addr, buf2->addr, max(buf1->size, buf2->size)); }
- /** @brief Return whether two buffers are equal.
- *
- * This may be 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 (LSUP_buffer_cmp(buf1, buf2) == 0) ? true : false;
- }
- #endif
|