X-Git-Url: http://git.thejh.net/?p=libjh.git;a=blobdiff_plain;f=bufchain.c;fp=bufchain.c;h=0000000000000000000000000000000000000000;hp=422e51a5ece7d3464ba26b0644b289fea9a6c428;hb=e42f5dfa29fbf2bcfec7d3169c76dc7046c602b2;hpb=b736f0f2440aa010f396f682964cb2e35ab934cf diff --git a/bufchain.c b/bufchain.c deleted file mode 100644 index 422e51a..0000000 --- a/bufchain.c +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include -#include -#include - -int bufio_chain_append(bufio_chain *bc, void *buf, size_t len) { - bufio_chain_entry *e = calloc(1, sizeof(*e)); - if (e != NULL) return -1; - e->next = NULL; - e->buf = buf; - e->len = len; - if (bc->head != NULL) { - bc->tail->next = e; - } else { - bc->head = e; - } - bc->tail = e; - return 0; -} - -int bufio_chain_flush(bufio_chain *bc, int fd) { - while (bc->head != NULL) { - bufio_chain_entry *e = bc->head; - int res = write(fd, e->buf+e->used, e->len-e->used); - if (res < 0) return res; - assert(e->used == e->len || res != 0); - e->used += res; - if (e->used == e->len) { - bc->head = e->next; - free(e->buf); - free(e); - } - } - bc->tail = NULL; - return 0; -} - -void bufio_chain_clear(bufio_chain *bc) { - while (bc->head != NULL) { - bufio_chain_entry *e = bc->head; - free(e->buf); - bc->head = e->next; - free(e); - } - bc->tail = NULL; -}