Commit f5788250 authored by Jim Meyering's avatar Jim Meyering Committed by Junio C Hamano

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: default avatarJim Meyering <[email protected]>
Acked-by: default avatarLinus Torvalds <[email protected]>
Signed-off-by: default avatarJunio C Hamano <[email protected]>
parent 5483c71d
......@@ -589,7 +589,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
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) {
......
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment