git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 1/2] Introduce strbuf_write_or_die()

From
FKFaiz Kothari <faiz.off93@gmail.com>
Date
Mar 2, 2014, 07:34 UTC
Message-ID
<1393745664-21077-1-git-send-email-faiz.off93@gmail.com>
In-Reply-To
<CAPig+cR0gTeB1oUUPQ=W_wWGPMDaY4gkG7+531HT-ktnwn5L-Q@mail.gmail.com>
Signed-off-by: Faiz Kothari <faiz.off93@gmail.com>

Introduced a new function strbuf.c:strbuf_write_or_die() to the strbuf family of functions. Now use this API instead of write_or_die.c:write_or_die() --- Hi, Thanks for the suggestions and feedbacks. As Johannes Sixt pointed out, the function is now defined in strbuf.c and prototype added to strbuf.h Also, replaced if(!sbuf) with assert(sbuf) and split the patch into two as pointed out by Eric Sunshine.

As far as justification is concerned, I am not able to come up with a satisfactory justification. Apart from, that it makes life of the programmer a little easier and if we add a few more functions to thestrbuf API, we can make strbuf completely opaque. I am open to views and since I haven't used this API extensively, I cannot comment for what is missing and what is required. But I am going through it. Also, once this patch is OK, I'll add documentation for the API.

Thanks again for the feedback.
 strbuf.c |    6 ++++++
 strbuf.h |    1 +
 2 files changed, 7 insertions(+)
diff --git a/strbuf.c b/strbuf.c
index 83caf4a..337a70c 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -477,6 +477,12 @@ int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint)
 	return len;
 }
 
+void strbuf_write_or_die(const struct strbuf *sb, int fd)
+{
+	assert(sb);
+	write_or_die(fd, sb->buf, sb->len);
+}
+
 void strbuf_add_lines(struct strbuf *out, const char *prefix,
 		      const char *buf, size_t size)
 {
diff --git a/strbuf.h b/strbuf.h
index 73e80ce..6aadb6d 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -156,6 +156,7 @@ extern size_t strbuf_fread(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);
+extern void strbuf_write_or_die(const struct strbuf *sb, int fd);
 extern int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint);
 
 extern int strbuf_getwholeline(struct strbuf *, FILE *, int);
-- 
1.7.9.5
Previous: Eric SunshineNext: Faiz Kothari
Message 8 of 23 in “implemented strbuf_write_or_die()”
  1. implemented strbuf_write_or_die()Faiz Kothari, Mar 1, 2014
  2. He SunMar 1, 2014
  3. implemented strbuf_write_or_die()Faiz Kothari, Mar 1, 2014
  4. Michael HaggertyMar 1, 2014
  5. implemented strbuf_write_or_die()Faiz Kothari, Mar 2, 2014
  6. Eric SunshineMar 2, 2014
  7. Eric SunshineMar 2, 2014
  8. 1/2 Introduce strbuf_write_or_die()Faiz Kothari, Mar 2, 2014
  9. 2/2 use strbuf_write_or_die()Faiz Kothari, Mar 2, 2014
  10. Eric SunshineMar 2, 2014
  11. Eric SunshineMar 2, 2014
  12. Eric SunshineMar 2, 2014
  13. Junio C HamanoMar 3, 2014
  14. Eric SunshineMar 3, 2014
  15. David KastrupMar 3, 2014
  16. Junio C HamanoMar 3, 2014
  17. Eric SunshineMar 3, 2014
  18. Michael HaggertyMar 4, 2014
  19. Faiz KothariMar 4, 2014
  20. Junio C HamanoMar 4, 2014
  21. Johannes SixtMar 1, 2014
  22. Junio C HamanoMar 3, 2014
  23. Fwd: [PATCH] implemented strbuf_write_or_die()Faiz Kothari, Mar 3, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.