All of lore.kernel.org
 help / color / mirror / Atom feed
From: Faiz Kothari <faiz.off93@gmail.com>
To: git@vger.kernel.org, j6t@kdbg.org, sunshine@sunshineco.com,
	mhagger@alum.mit.edu
Cc: Faiz Kothari <faiz.off93@gmail.com>
Subject: [PATCH v3 1/2] Introduce strbuf_write_or_die()
Date: Sun,  2 Mar 2014 13:04:23 +0530	[thread overview]
Message-ID: <1393745664-21077-1-git-send-email-faiz.off93@gmail.com> (raw)
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

  parent reply	other threads:[~2014-03-02  7:34 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-01 11:21 [PATCH] implemented strbuf_write_or_die() Faiz Kothari
2014-03-01 12:51 ` He Sun
2014-03-01 13:29   ` Faiz Kothari
2014-03-01 22:33     ` Michael Haggerty
2014-03-02  0:18       ` [PATCH v2] " Faiz Kothari
2014-03-02  2:47         ` Eric Sunshine
2014-03-02  2:55           ` Eric Sunshine
2014-03-02  7:34           ` Faiz Kothari [this message]
2014-03-02  7:34             ` [PATCH v3 2/2] use strbuf_write_or_die() Faiz Kothari
2014-03-02 22:04               ` Eric Sunshine
2014-03-02 20:05             ` [PATCH v3 1/2] Introduce strbuf_write_or_die() Eric Sunshine
2014-03-02  3:08   ` [PATCH] implemented strbuf_write_or_die() Eric Sunshine
2014-03-03 18:31     ` Junio C Hamano
     [not found]       ` <CAFbjVckhU7NHzLjqPo5WkoBwVLrOLg=CS6mHSKkQstUxB31_eA@mail.gmail.com>
2014-03-03 18:48         ` Fwd: " Faiz Kothari
2014-03-03 19:46       ` Eric Sunshine
2014-03-03 19:51         ` David Kastrup
2014-03-03 20:35         ` Junio C Hamano
2014-03-03 21:29           ` Eric Sunshine
2014-03-04  9:18       ` Michael Haggerty
2014-03-04 17:01         ` Faiz Kothari
2014-03-04 18:45         ` Junio C Hamano
2014-03-01 21:34 ` Johannes Sixt
2014-03-03 18:27 ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1393745664-21077-1-git-send-email-faiz.off93@gmail.com \
    --to=faiz.off93@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    --cc=mhagger@alum.mit.edu \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.