From: Pierre Habouzit Date: Sun, 2 Dec 2007 11:36:28 +0000 (+0100) Subject: Implement buffer_write. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=9a6e88e7139970a218bbcd027a1ef461f06c8893;p=apps%2Fpfixtools.git Implement buffer_write. Signed-off-by: Pierre Habouzit --- diff --git a/buffer.c b/buffer.c index bdd5715..4e41b3c 100644 --- a/buffer.c +++ b/buffer.c @@ -33,6 +33,7 @@ * Copyright © 2006-2007 Pierre Habouzit */ +#include #include #include @@ -80,3 +81,13 @@ ssize_t buffer_read(buffer_t *buf, int fd, ssize_t count) buffer_extend(buf, res); return res; } + +ssize_t buffer_write(buffer_t *buf, int fd) +{ + ssize_t res = write(fd, buf->data, buf->len); + if (res < 0) { + return errno == EINTR || errno == EAGAIN ? 0 : -1; + } + buffer_consume(buf, res); + return res; +} diff --git a/buffer.h b/buffer.h index c399259..816788a 100644 --- a/buffer.h +++ b/buffer.h @@ -105,5 +105,6 @@ static inline void buffer_addch(buffer_t *buf, int c) { void buffer_consume(buffer_t *buf, ssize_t len); ssize_t buffer_read(buffer_t *buf, int fd, ssize_t count); +ssize_t buffer_write(buffer_t *buf, int fd); #endif /* PFIXTOOLS_BUFFER_H */