torrentd

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

commit 52dae2da3ecb182a26eafc1e5178ae974e00859d
parent 99008b92ed997638d977f7cc024ecb3e4d186ecc
Author: sin <sin@2f30.org>
Date:   Thu, 17 Dec 2015 13:19:28 +0000

Add newbit()

Diffstat:
Msbtd.h | 2++
Mutil.c | 19+++++++++++++++++++
2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/sbtd.h b/sbtd.h @@ -36,6 +36,8 @@ void bfree(struct ben *); /* util.c */ void *emalloc(size_t); +void *ecalloc(size_t, size_t); +uint32_t *newbit(int); void setbit(uint32_t *, int); void clrbit(uint32_t *, int); int tstbit(uint32_t *, int); diff --git a/util.c b/util.c @@ -39,6 +39,25 @@ emalloc(size_t size) return p; } +void * +ecalloc(size_t n, size_t size) +{ + void *p; + + p = calloc(n, size); + if (!p) + err(1, "calloc"); + return p; +} + +uint32_t * +newbit(int n) +{ + n += 31; + n /= 32; + return ecalloc(n, 4); +} + void setbit(uint32_t *b, int n) {