diff --git a/Makefile b/Makefile index 9ec9990..1c39fef 100644 --- a/Makefile +++ b/Makefile @@ -79,7 +79,8 @@ LIBUTILSRC =\ libutil/strlcpy.c\ libutil/strsep.c\ libutil/strtonum.c\ - libutil/unescape.c + libutil/unescape.c\ + libutil/writeall.c LIB = $(LIBUTF) $(LIBUTIL) diff --git a/libutil/writeall.c b/libutil/writeall.c new file mode 100644 index 0000000..4725ced --- /dev/null +++ b/libutil/writeall.c @@ -0,0 +1,21 @@ +/* See LICENSE file for copyright and license details. */ +#include + +#include "../util.h" + +ssize_t +writeall(int fd, const void *buf, size_t len) +{ + const char *p = buf; + ssize_t n; + + while (len) { + n = write(fd, p, len); + if (n <= 0) + return n; + p += n; + len -= n; + } + + return p - (const char *)buf; +} diff --git a/util.h b/util.h index 29325d2..b39d918 100644 --- a/util.h +++ b/util.h @@ -62,6 +62,9 @@ char *strsep(char **, const char *); int enregcomp(int, regex_t *, const char *, int); int eregcomp(regex_t *, const char *, int); +/* io */ +ssize_t writeall(int, const void *, size_t); + /* misc */ void enmasse(int, char **, int (*)(const char *, const char *, int)); void fnck(const char *, const char *, int (*)(const char *, const char *, int), int);