X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=fd.c;h=48e2faf97c6d3e2bcb1616ebef04db48e2003d9e;hp=abad80a86ce368660c1ed3b88a1c0e088488a422;hb=d2a600590a2607d2bd729f3079aaec320efe7990;hpb=2fe2b6e212e8e0d09cd1a8fc95f7f2f3a1110485 diff --git a/fd.c b/fd.c index abad80a8..48e2faf9 100644 --- a/fd.c +++ b/fd.c @@ -15,6 +15,31 @@ #include "para.h" #include "error.h" +/* + * Write a buffer to a file descriptor, re-write on short writes. + * + * \param fd The file descriptor. + * \param buf The buffer to be sent. + * \param len The length of \a buf. + * + * \return Standard. In any case, the number of bytes that have been written is + * stored in \a len. + */ +int write_all(int fd, const char *buf, size_t *len) +{ + size_t total = *len; + + assert(total); + *len = 0; + while (*len < total) { + int ret = write(fd, buf + *len, total - *len); + if (ret == -1) + return -ERRNO_TO_PARA_ERROR(errno); + *len += ret; + } + return 1; +} + /** * Check whether a file exists. *