X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=git-compat-util.h;h=ca0a597a282328bff9e0e29fd3653dbd656489fb;hb=9d25acc49a98ca82988ad871753a45e41f3c90f5;hp=b2ab3f82567d54607a07f4061153adae86854fa9;hpb=b8336519450fdedc8f9cafebc73f7a0226e34e1f;p=git.git diff --git a/git-compat-util.h b/git-compat-util.h index b2ab3f825..ca0a597a2 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -287,6 +287,32 @@ 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 int xmkstemp(char *template) +{ + int fd; + + fd = mkstemp(template); + if (fd < 0) + die("Unable to create temporary file: %s", strerror(errno)); + return fd; +} + static inline size_t xsize_t(off_t len) { return (size_t)len;