From b4e04fb66e87a027c5f9c96bcbbba50719400169 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Tue, 15 Dec 2015 16:04:08 -0800 Subject: strbuf: add strbuf_read_once to read without blocking The new call will read from a file descriptor into a strbuf once. The underlying call xread is just run once. xread only reattempts reading in case of EINTR, which makes it suitable to use for a nonblocking read. Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- strbuf.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'strbuf.h') diff --git a/strbuf.h b/strbuf.h index 7123fca7af..2bf90e70fc 100644 --- a/strbuf.h +++ b/strbuf.h @@ -366,6 +366,14 @@ extern size_t strbuf_fread(struct strbuf *, size_t, FILE *); */ extern ssize_t strbuf_read(struct strbuf *, int fd, size_t hint); +/** + * Read the contents of a given file descriptor partially by using only one + * attempt of xread. The third argument can be used to give a hint about the + * file size, to avoid reallocs. Returns the number of new bytes appended to + * the sb. + */ +extern ssize_t strbuf_read_once(struct strbuf *, int fd, size_t hint); + /** * Read the contents of a file, specified by its path. The third argument * can be used to give a hint about the file size, to avoid reallocs. -- cgit v1.3