summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b4833a2)
raw | patch | inline | side by side (parent: b4833a2)
author | Kristian Høgsberg <krh@redhat.com> | |
Tue, 18 Sep 2007 00:06:46 +0000 (20:06 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 27 Sep 2007 07:33:29 +0000 (00:33 -0700) |
Signed-off-by: Kristian Høgsberg <krh@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-tag.c | patch | blob | history | |
strbuf.c | patch | blob | history | |
strbuf.h | patch | blob | history |
diff --git a/builtin-tag.c b/builtin-tag.c
index 82ebda11b02b2fd1fad3e3687832bb222e84f500..fcbf9bbf18155b5e9b699bf12cd980561498992f 100644 (file)
--- a/builtin-tag.c
+++ b/builtin-tag.c
const char *editor, *terminal;
struct child_process child;
const char *args[3];
- int fd;
editor = getenv("GIT_EDITOR");
if (!editor && editor_program)
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 d5e92ee17257ea3a3ff53580b0df011d4994240a..d1e338bfb695322cf2c90fa39bc8d482a3ade297 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
sb->buf[sb->len] = '\0';
return 0;
}
+
+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;
+}
diff --git a/strbuf.h b/strbuf.h
index fd683893341723f29301b6ddb51955857b3ffee9..d4d9e5663c58a9c7c019124194d95ef365e874f7 100644 (file)
--- a/strbuf.h
+++ b/strbuf.h
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 int strbuf_getline(struct strbuf *, FILE *, int);