X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=fd.c;h=6f487c410020795a73476fa79ba552c2ad29e4fd;hp=ea16bdda993aff814fa41684af53506e46242a4f;hb=748d1368bc96dd7e1af879df1ea41b4d52842f7e;hpb=8acdfc3d6d124581d0b624e61e0047f576eb4748 diff --git a/fd.c b/fd.c index ea16bdda..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; } /**