torrentd

simple torrent daemon
git clone git://git.2f30.org/torrentd
Log | Files | Refs | LICENSE

commit ee8fa81f48db069fa0b48f148dd5a3f63e760440
parent 89709afc547df11b28a1ce14a268c1afe78207b6
Author: sin <sin@2f30.org>
Date:   Sat, 26 Dec 2015 16:50:28 +0000

move buffer handle to util

Diffstat:
Mstorrent.h | 8++++++++
Mtracker.c | 28----------------------------
Mutil.c | 23+++++++++++++++++++++++
3 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/storrent.h b/storrent.h @@ -5,6 +5,11 @@ enum { EVSTOPPED }; +struct buf { + char *p; + size_t n; +}; + struct ben { int type; struct ben *k; @@ -92,3 +97,6 @@ ssize_t readn(int, void *, size_t); size_t strlcpy(char *, const char *, size_t); #undef strlcat size_t strlcat(char *, const char *, size_t); +void initbuf(struct buf *); +void freebuf(struct buf *); +size_t fillbuf(struct buf *, void *, size_t); diff --git a/tracker.c b/tracker.c @@ -12,34 +12,6 @@ #include "storrent.h" -struct buf { - char *p; - size_t n; -}; - -static void -initbuf(struct buf *b) -{ - memset(b, 0, sizeof(*b)); -} - -static void -freebuf(struct buf *b) -{ - free(b->p); - b->p = NULL; -} - -static size_t -fillbuf(struct buf *b, void *ptr, size_t n) -{ - if (!(b->p = realloc(b->p, b->n + n))) - err(1, "realloc"); - memcpy(b->p + b->n, ptr, n); - b->n += n; - return b->n; -} - static size_t writefn(void *ptr, size_t size, size_t nmemb, struct buf *b) { diff --git a/util.c b/util.c @@ -222,3 +222,26 @@ strlcat(char *dst, const char *src, size_t dsize) return(dlen + (src - osrc)); /* count does not include NUL */ } + +void +initbuf(struct buf *b) +{ + memset(b, 0, sizeof(*b)); +} + +void +freebuf(struct buf *b) +{ + free(b->p); + b->p = NULL; +} + +size_t +fillbuf(struct buf *b, void *ptr, size_t n) +{ + if (!(b->p = realloc(b->p, b->n + n))) + err(1, "realloc"); + memcpy(b->p + b->n, ptr, n); + b->n += n; + return b->n; +}