summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5483c71)
raw | patch | inline | side by side (parent: 5483c71)
author | Jim Meyering <jim@meyering.net> | |
Wed, 27 Jun 2007 14:28:53 +0000 (16:28 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 28 Jun 2007 04:02:44 +0000 (21:02 -0700) |
This defines xdup() and xfdopen() in git-compat-util.h to give
us error-catching variants of them without cluttering the code
too much.
Signed-off-by: Jim Meyering <jim@meyering.net>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
us error-catching variants of them without cluttering the code
too much.
Signed-off-by: Jim Meyering <jim@meyering.net>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-log.c | patch | blob | history | |
git-compat-util.h | patch | blob | history |
diff --git a/builtin-log.c b/builtin-log.c
index 073a2a16a3fafd66d13b1ed106a0016617ec63ad..a4186eac8ea395143d25b16b94171b3d4e75d444 100644 (file)
--- a/builtin-log.c
+++ b/builtin-log.c
get_patch_ids(&rev, &ids, prefix);
if (!use_stdout)
- realstdout = fdopen(dup(1), "w");
+ realstdout = xfdopen(xdup(1), "w");
prepare_revision_walk(&rev);
while ((commit = get_revision(&rev)) != NULL) {
diff --git a/git-compat-util.h b/git-compat-util.h
index b2ab3f82567d54607a07f4061153adae86854fa9..362e040f52cf8df17811ae95e46f0b60d2b6f071 100644 (file)
--- a/git-compat-util.h
+++ b/git-compat-util.h
}
}
+static inline int xdup(int fd)
+{
+ int ret = dup(fd);
+ if (ret < 0)
+ die("dup failed: %s", strerror(errno));
+ return ret;
+}
+
+static inline FILE *xfdopen(int fd, const char *mode)
+{
+ FILE *stream = fdopen(fd, mode);
+ if (stream == NULL)
+ die("Out of memory? fdopen failed: %s", strerror(errno));
+ return stream;
+}
+
static inline size_t xsize_t(off_t len)
{
return (size_t)len;