torrentd

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

commit 32d01c3f1e38a73df57baf111cdb69a50fca1d8e
parent b92c68bb28d2d9be57498ad0a74747c0b9162b13
Author: sin <sin@2f30.org>
Date:   Sat, 19 Dec 2015 11:05:30 +0000

Add writeall()

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

diff --git a/sbtd.h b/sbtd.h @@ -67,3 +67,4 @@ void sha1sum(uint8_t *, unsigned long, uint8_t *); int readfile(char *, char **, size_t *); char *urlencode(char *, size_t); char *urldecode(char *); +void writeall(int, const void *, size_t); diff --git a/util.c b/util.c @@ -178,3 +178,21 @@ urldecode(char *s) *bp = '\0'; return buf; } + +void +writeall(int fd, const void *buf, size_t count) +{ + const char *p = buf; + ssize_t n; + size_t wrote = 0; + + while (count > 0) { + n = write(fd, p + wrote, count); + if (n < 0) + err(1, "write"); + else if (n == 0) + break; + wrote += n; + count -= n; + } +}