libeech

BitTorrent library
git clone git://z3bra.org/libeech.git
Log | Files | Refs | README | LICENSE

commit a3feb8c50165995ebc29431f7ec15ada67ddb92f
parent 7f5175a8d8f118bbc9f5b0f8d68c240020495d28
Author: z3bra <contactatz3bradotorg>
Date:   Sun Feb 25 06:26:45 -0500

Add functions to alterate/query bits

Diffstat:
libeech.c | 25+++++++++++++++++++++++++
1 file changed, 25 insertions(+), 0 deletions(-)
diff --git a/libeech.c b/libeech.c @@ -23,6 +23,11 @@ struct peerfds { struct pollfd *fds; }; +/* helpers to deal with bitfields */ +static int bit(char *, long); +static char *setbit(char *, long); +static char *clrbit(char *, long); + /* helpers to retrieve attributes from metadata */ static char * peerid(); static long torrentsize(struct torrent *); @@ -51,6 +56,26 @@ static int pwprx(struct torrent *, struct peer *); static int netconn(char *, int); static int netloop(struct torrent *, int); +static int +bit(char *bits, long off) +{ + return !!(bits[off / 8] & (1 << (7 - off%8))); +} + +static char * +setbit(char *bits, long off) +{ + bits[off / 8] |= (1 << (7 - off%8)); + return bits; +} + +static char * +clrbit(char *bits, long off) +{ + bits[off / sizeof(*bits)] &= ~(1 << (7 - off%8)); + return bits; +} + static char * peerid() {