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| Andrew Morton | -mm merge plans for 2.6.23 |
| Chuck Ebbert | Why do so many machines need "noapic"? |
| Bart Van Assche | Integration of SCST in the mainstream Linux kernel |
| Greg Kroah-Hartman | [PATCH 023/196] MCP_UCB1200: Convert from class_device to device |
git: | |
| David Miller | Re: [BUG] New Kernel Bugs |
| Jarek Poplawski | Re: [PATCH] pkt_sched: Destroy gen estimators under rtnl_lock(). |
| Gerrit Renker | [PATCH 31/37] dccp: Remove manual influence on NDP Count feature |
| Gregory Haskins | [RFC PATCH 00/17] virtual-bus |
