From 9bd0fc6cdc2b7853667fdf18bf2cbd0e2168f233 Mon Sep 17 00:00:00 2001 From: Richard Nyberg Date: Fri, 18 May 2007 13:45:03 +0000 Subject: o Rename net_(write|read)32 to (enc|dec)_be32. Add similar functions for 64 bits as well. Implement them in libmisc instead of in btpd. o Change resume file format and related APIs. The resume files are now memory mapped. --- misc/subr.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'misc/subr.c') diff --git a/misc/subr.c b/misc/subr.c index 22ed6e2..0ca41c7 100644 --- a/misc/subr.c +++ b/misc/subr.c @@ -13,6 +13,48 @@ #include #include +void +enc_be32(void *buf, uint32_t num) +{ + uint8_t *p = buf; + *p = (num >> 24) & 0xff; + *(p + 1) = (num >> 16) & 0xff; + *(p + 2) = (num >> 8) & 0xff; + *(p + 3) = num & 0xff; +} + +uint32_t +dec_be32(const void *buf) +{ + const uint8_t *p = buf; + return (uint32_t)*p << 24 | (uint32_t)*(p + 1) << 16 + | (uint16_t)*(p + 2) << 8 | *(p + 3); +} + +void +enc_be64(void *buf, uint64_t num) +{ + uint8_t *p = buf; + *p = (num >> 56) & 0xff; + *(p + 1) = (num >> 48) & 0xff; + *(p + 2) = (num >> 40) & 0xff; + *(p + 3) = (num >> 32) & 0xff; + *(p + 4) = (num >> 24) & 0xff; + *(p + 5) = (num >> 16) & 0xff; + *(p + 6) = (num >> 8) & 0xff; + *(p + 7) = num & 0xff; +} + +uint64_t +dec_be64(const void *buf) +{ + const uint8_t *p = buf; + return (uint64_t)*p << 56 | (uint64_t)*(p + 1) << 48 + | (uint64_t)*(p + 2) << 40 | (uint64_t)*(p + 3) << 32 + | (uint64_t)*(p + 4) << 24 | (uint64_t)*(p + 5) << 16 + | (uint64_t)*(p + 6) << 8 | (uint64_t)*(p + 7); +} + void set_bit(uint8_t *bits, unsigned long index) { -- cgit 1.4.1