X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=fd.c;h=6f487c410020795a73476fa79ba552c2ad29e4fd;hp=6f9266f47a56cd8dee3e99b8651d12a89bb4069b;hb=748d1368bc96dd7e1af879df1ea41b4d52842f7e;hpb=1be583ecb090f391ae3d906444f11532978fc2c9 diff --git a/fd.c b/fd.c index 6f9266f4..6f487c41 100644 --- a/fd.c +++ b/fd.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2011 Andre Noll + * Copyright (C) 2006-2012 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -25,22 +25,40 @@ * \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. + * \return Standard. */ -int write_all(int fd, const char *buf, size_t *len) +int write_all(int fd, const char *buf, size_t len) { - size_t total = *len; + size_t total = len; assert(total); - *len = 0; - while (*len < total) { - int ret = write(fd, buf + *len, total - *len); + len = 0; + while (len < total) { + int ret = write(fd, buf + len, total - len); if (ret == -1) return -ERRNO_TO_PARA_ERROR(errno); - *len += ret; + len += ret; } - return 1; + return len; +} + +/** + * Send a buffer given by a format string. + * + * \param fd The file descriptor. + * \param fmt A format string. + * + * \return Standard. + */ +__printf_2_3 int write_va_buffer(int fd, const char *fmt, ...) +{ + char *msg; + int ret; + + PARA_VSPRINTF(fmt, msg); + ret = write_buffer(fd, msg); + free(msg); + return ret; } /** @@ -563,6 +581,9 @@ out: int para_munmap(void *start, size_t length) { int err; + + if (!start) + return 0; if (munmap(start, length) >= 0) return 1; err = errno;