summaryrefslogtreecommitdiffstats
path: root/list.h
diff options
context:
space:
mode:
authortanyaionova <isaqtm@gmail.com>2019-11-20 23:29:05 +0300
committertanyaionova <isaqtm@gmail.com>2019-11-20 23:29:05 +0300
commitac7fd63348553c2a0ad1b776c7039b1a8b60dbe8 (patch)
tree772b481416230eedfdfb55a03ef1c3e61ec23825 /list.h
parent48debdf040d0e0b1af8d11a339ce8332e2454d3f (diff)
downloadash-sbox-ac7fd63348553c2a0ad1b776c7039b1a8b60dbe8.tar.gz
Bump
Diffstat (limited to 'list.h')
-rw-r--r--list.h107
1 files changed, 0 insertions, 107 deletions
diff --git a/list.h b/list.h
index 9f6ea60..6644c22 100644
--- a/list.h
+++ b/list.h
@@ -31,110 +31,3 @@ void aco_list_remove (struct aco_list *iter) {
iter->prev->next = iter->next;
iter->next->prev = iter->prev;
}
-
-#define SBO_BUF_SMALL 0x80
-#define SBO_BUF_BIG 0x00
-#define SBO_BUF_MASK 0x80
-#define SBO_BUF_SIZEMASK 0x7f
-#define SBO_BUF_SMALL_MAX_SIZE 0x7f /* 0x80 - 0x1 */
-
-
-typedef struct sbo_buf {
- unsigned char hdr;
- union {
- char small[SBO_BUF_SMALL_MAX_SIZE];
- struct {
- char *base;
- size_t size;
- size_t alloc;
- } big;
- } buf;
-} sbo_buf_t;
-
-
-int sbo_buf_init (sbo_buf_t *buf, char *init, size_t count);
-void sbo_buf_free (sbo_buf_t *buf);
-char *sbo_buf_mem (sbo_buf_t *buf);
-size_t sbo_buf_size (sbo_buf_t *buf);
-int sbo_buf_type (sbo_buf_t *buf);
-int sbo_buf_grow (sbo_buf_t *buf, char *grow, size_t count);
-
-
-int sbo_buf_init0 (sbo_buf_t *buf) {
- memset (buf, 0, sizeof (*buf));
- buf->hdr = 0 | SBO_BUF_SMALL;
- return 0;
-}
-
-
-int sbo_buf_init (sbo_buf_t *buf, char *init, size_t count) {
- if (count <= (size_t)SBO_BUF_SMALL_MAX_SIZE) {
- buf->hdr = 0 | SBO_BUF_SMALL;
- buf->hdr |= (unsigned char) count;
- memcpy (buf->buf.small, init, count);
- }
- else {
- buf->buf.big.base = malloc (count);
- if (!buf->buf.big.base)
- return errno;
- buf->hdr = 0 | SBO_BUF_BIG;
- buf->buf.big.size = count;
- buf->buf.big.alloc = count;
- }
- return 0;
-}
-
-void sbo_buf_free (sbo_buf_t *buf) {
- if (sbo_buf_type (buf) == SBO_BUF_BIG)
- free (buf->buf.big.base);
-}
-
-inline char *sbo_buf_mem (sbo_buf_t *buf) {
- if (sbo_buf_type (buf) == SBO_BUF_BIG)
- return buf->buf.big.base;
- return buf->buf.small;
-}
-
-inline size_t sbo_buf_size (sbo_buf_t *buf) {
- if (sbo_buf_type (buf) == SBO_BUF_BIG)
- return buf->buf.big.size;
-
- return buf->hdr & SBO_BUF_SIZEMASK;
-}
-
-inline int sbo_buf_type (sbo_buf_t *buf) {
- return buf->hdr & SBO_BUF_MASK;
-}
-
-int sbo_buf_grow (sbo_buf_t *buf, char *grow, size_t count) {
- if (count == 0)
- return 0;
- //size_t bufsize = sbo_buf_size (buf);
- if (sbo_buf_type (buf) == SBO_BUF_SMALL) {
- size_t current_size = sbo_buf_size (buf);
- if (current_size + count <= (size_t)SBO_BUF_SMALL_MAX_SIZE) {
- /* no need to become big. just concat two existing buffers */
- char *dst = sbo_buf_mem (buf) + current_size;
- memcpy (dst, grow, count);
- buf->hdr += count;
- return 0;
- }
- /* fallthrough to realloc */
- }
-
- char *base = sbo_buf_mem (buf);
- size_t len = sbo_buf_size (buf);
- char *newbuf = malloc (len + count);
- if (!newbuf)
- return errno;
-
- memcpy (newbuf, base, len);
- memcpy (newbuf + len, grow, count);
- sbo_buf_free (buf);
- buf->hdr = 0 | SBO_BUF_BIG; /* We definitely exceeded small buffer */
- buf->buf.big.base = newbuf;
- buf->buf.big.alloc = len + count;
- buf->buf.big.size = len + count;
-
- return 0;
-} \ No newline at end of file