aboutsummaryrefslogtreecommitdiff
path: root/git-compat-util.h
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2007-06-27 16:28:53 +0200
committerJunio C Hamano <gitster@pobox.com>2007-06-27 21:02:44 -0700
commitf57882505efe05990102a0d96b37c09baadae03d (patch)
tree416b045a8020aaf06209f1883d0e4fb10d68c204 /git-compat-util.h
parent5483c71d7ac06b4f16c646886abbb2d0f88a2855 (diff)
downloadgit-f57882505efe05990102a0d96b37c09baadae03d.tar.gz
git-f57882505efe05990102a0d96b37c09baadae03d.tar.xz
git-log: detect dup and fdopen failure
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>
Diffstat (limited to 'git-compat-util.h')
-rw-r--r--git-compat-util.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h
index b2ab3f825..362e040f5 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -287,6 +287,22 @@ static inline ssize_t xwrite(int fd, const void *buf, size_t len)
}
}
+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;