git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Kristian Høgsberg" <krh@redhat.com>
To: git@vger.kernel.org
Cc: "Kristian Høgsberg" <krh@redhat.com>
Subject: [PATCH 5/7] Add strbuf_read_file().
Date: Mon, 17 Sep 2007 20:06:46 -0400	[thread overview]
Message-ID: <11900740154136-git-send-email-krh@redhat.com> (raw)
In-Reply-To: <11900740153845-git-send-email-krh@redhat.com>

Signed-off-by: Kristian Høgsberg <krh@redhat.com>
---
 builtin-tag.c |   10 +++-------
 strbuf.c      |   15 +++++++++++++++
 strbuf.h      |    1 +
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/builtin-tag.c b/builtin-tag.c
index 68c9a20..c97673f 100644
--- a/builtin-tag.c
+++ b/builtin-tag.c
@@ -53,13 +53,9 @@ static void launch_editor(const char *path, struct strbuf *buffer)
 	if (run_command(&child))
 		die("There was a problem with the editor %s.", editor);
 
-	fd = open(path, O_RDONLY);
-	if (fd < 0)
-		die("could not open '%s': %s", path, strerror(errno));
-	if (strbuf_read(buffer, fd, 0) < 0) {
-		die("could not read message file '%s': %s", path, strerror(errno));
-	}
-	close(fd);
+	if (strbuf_read_file(buffer, path) < 0)
+		die("could not read message file '%s': %s",
+		    path, strerror(errno));
 }
 
 struct tag_filter {
diff --git a/strbuf.c b/strbuf.c
index d919047..438606d 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -110,6 +110,21 @@ ssize_t strbuf_read(struct strbuf *sb, int fd, size_t hint)
 	return sb->len - oldlen;
 }
 
+int strbuf_read_file(struct strbuf *sb, const char *path)
+{
+	int fd, len;
+
+	fd = open(path, O_RDONLY);
+	if (fd < 0)
+		return -1;
+	len = strbuf_read(sb, fd, 0);
+	close(fd);
+	if (len < 0)
+		return -1;
+
+	return len;
+}
+
 void read_line(struct strbuf *sb, FILE *fp, int term) {
 	int ch;
 	if (feof(fp)) {
diff --git a/strbuf.h b/strbuf.h
index 5960637..3a523ab 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -95,6 +95,7 @@ extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...);
 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);
 
 extern void read_line(struct strbuf *, FILE *, int);
 
-- 
1.5.3.1.993.gbf388-dirty

  reply	other threads:[~2007-09-18  0:07 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-18  0:06 [PATCH 1/7] Enable wt-status output to a given FILE pointer Kristian Høgsberg
2007-09-18  0:06 ` [PATCH 2/7] Enable wt-status to run against non-standard index file Kristian Høgsberg
2007-09-18  0:06   ` [PATCH 3/7] Introduce entry point for launching add--interactive Kristian Høgsberg
2007-09-18  0:06     ` [PATCH 4/7] Clean up stripspace a bit, use strbuf even more Kristian Høgsberg
2007-09-18  0:06       ` Kristian Høgsberg [this message]
2007-09-18  0:06         ` [PATCH 6/7] Export rerere() and launch_editor() Kristian Høgsberg
2007-09-18  0:06           ` [PATCH 7/7] Implement git commit as a builtin command Kristian Høgsberg
2007-09-18 13:58             ` Johannes Schindelin
2007-09-18 15:07               ` Kristian Høgsberg
2007-09-20  1:27             ` Junio C Hamano
2007-09-21 17:18               ` Kristian Høgsberg
2007-09-21 19:32                 ` Junio C Hamano
2007-09-24 20:27                   ` Kristian Høgsberg
2007-09-18 13:14           ` [PATCH 6/7] Export rerere() and launch_editor() Johannes Schindelin
2007-09-19 23:52           ` Junio C Hamano
2007-09-21 18:01             ` Kristian Høgsberg
2007-09-18 13:12       ` [PATCH 4/7] Clean up stripspace a bit, use strbuf even more Johannes Schindelin
2007-09-18 13:52         ` Kristian Høgsberg

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=11900740154136-git-send-email-krh@redhat.com \
    --to=krh@redhat.com \
    --cc=git@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).