Signed-off-by: Kristian Høgsberg <krh@redhat.com>
---
builtin-tag.c | 7 +------
strbuf.c | 15 +++++++++++++++
strbuf.h | 1 +
3 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/builtin-tag.c b/builtin-tag.c
index 1aff952..8724d49 100644
--- a/builtin-tag.c
+++ b/builtin-tag.c
@@ -53,14 +53,9 @@ static void launch_editor(const char *path, struct strbuf *sb)
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_fd(sb, fd) < 0) {
+ if (strbuf_read_path(sb, path) < 0)
die("could not read message file '%s': %s",
path, strerror(errno));
- }
- close(fd);
}
struct tag_filter {
diff --git a/strbuf.c b/strbuf.c
index ed2afea..1951a5b 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -70,6 +70,21 @@ int strbuf_read_fd(struct strbuf *sb, int fd)
return total;
}
+int strbuf_read_path(struct strbuf *sb, const char *path)
+{
+ int fd, len;
+
+ fd = open(path, O_RDONLY);
+ if (fd < 0)
+ return -1;
+ len = strbuf_read_fd(sb, fd);
+ if (len < 0)
+ return -1;
+ close(fd);
+
+ return len;
+}
+
void strbuf_printf(struct strbuf *sb, const char *fmt, ...)
{
char buffer[2048];
diff --git a/strbuf.h b/strbuf.h
index a93b9e1..e852070 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -14,6 +14,7 @@ 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);
+extern int strbuf_read_path(struct strbuf *sb, const char *path);
extern size_t stripspace(struct strbuf *sb, int skip_comments);
#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