[PATCH 3/5] strbuf: Introduce strbuf_fwrite corresponding to strbuf_fread

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Ramkumar Ramachandra <artagnon@xxxxxxxxx>
---
 strbuf.c |   11 +++++++++++
 strbuf.h |    1 +
 2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/strbuf.c b/strbuf.c
index 77444a9..bdfd0d0 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -290,6 +290,17 @@ size_t strbuf_fread(struct strbuf *sb, size_t size, FILE *f)
 	return res;
 }
 
+size_t strbuf_fwrite(struct strbuf *sb, size_t size, FILE *f)
+{
+	size_t res;
+
+	if (size > sb->len)
+		res = fwrite(sb->buf, 1, sb->len, f);
+	else 
+		res = fwrite(sb->buf, 1, size, f);
+	return res;
+}
+
 ssize_t strbuf_read(struct strbuf *sb, int fd, size_t hint)
 {
 	size_t oldlen = sb->len;
diff --git a/strbuf.h b/strbuf.h
index f722331..c68361c 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -124,6 +124,7 @@ __attribute__((format (printf,2,0)))
 extern void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap);
 
 extern size_t strbuf_fread(struct strbuf *, size_t, FILE *);
+extern size_t strbuf_fwrite(struct strbuf *, size_t, FILE *);
 /* XXX: if read fails, any partial read is undone */
 extern ssize_t strbuf_read(struct strbuf *, int fd, size_t hint);
 extern int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint);
-- 
1.7.4.rc1.7.g2cf08.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]