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>
This commit is contained in:
committed by
Junio C Hamano
parent
5483c71d7a
commit
f57882505e
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user