[PATCH 5/9] Introduce strbuf_read_fd().

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <git@...>
Cc: <krh@...>
Date: Wednesday, September 5, 2007 - 8:23 pm

This function reads from a given fd into a strbuf until end of file.

Signed-off-by: Kristian Høgsberg <krh@redhat.com>
---
 strbuf.c |   19 +++++++++++++++++++
 strbuf.h |    1 +
 2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/strbuf.c b/strbuf.c
index 2805c11..fcfc05e 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -50,6 +50,25 @@ void read_line(struct strbuf *sb, FILE *fp, int term) {
 	strbuf_end(sb);
 }
 
+int strbuf_read_fd(struct strbuf *sb, int fd)
+{
+	int len, total = 0;
+
+	do {
+		strbuf_grow(sb, 1024);
+		len = xread(fd, sb->buf + sb->len, sb->alloc - sb->len);
+		if (len > 0) {
+			total += len;
+			sb->len += len;
+		}
+	} while (len > 0);
+
+	if (len < 0)
+		return len;
+
+	return total;
+}
+
 void strbuf_printf(struct strbuf *sb, const char *fmt, ...)
 {
 	char buffer[2048];
diff --git a/strbuf.h b/strbuf.h
index 1e5d09e..6e630ea 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -12,5 +12,6 @@ extern void read_line(struct strbuf *, FILE *, int);
 extern void strbuf_add(struct strbuf *sb, const char *data, size_t len);
 extern void strbuf_add_char(struct strbuf *sb, int ch);
 extern void strbuf_printf(struct strbuf *sb, const char *fmt, ...);
+extern int strbuf_read_fd(struct strbuf *sb, int fd);
 
 #endif /* STRBUF_H */
-- 
1.5.2.GIT

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [PATCH 1/9] Enable wt-status output to a given FILE poin..., Johannes Schindelin, (Thu Sep 6, 12:27 pm)
Re: [PATCH 4/9] Introduce entry point for launching add--int..., Johannes Schindelin, (Thu Sep 6, 12:31 pm)
Re: [PATCH 4/9] Introduce entry point for launching add--int..., Johannes Schindelin, (Mon Sep 17, 7:27 pm)
[PATCH 5/9] Introduce strbuf_read_fd()., , (Wed Sep 5, 8:23 pm)
Re: [PATCH 6/9] Rewrite launch_editor, create_tag and strips..., Johannes Schindelin, (Thu Sep 6, 12:38 pm)