tAdd functions to alterate/query bits - libeech - bittorrent library
(HTM) git clone git://z3bra.org/libeech.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit a3feb8c50165995ebc29431f7ec15ada67ddb92f
(DIR) parent 7f5175a8d8f118bbc9f5b0f8d68c240020495d28
(HTM) Author: z3bra <contactatz3bradotorg>
Date: Sun, 25 Feb 2018 06:26:45 -0500
Add functions to alterate/query bits
Diffstat:
M libeech.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/libeech.c b/libeech.c
t@@ -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 *);
t@@ -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()
{