diff options
Diffstat (limited to 'git-compat-util.h')
-rw-r--r-- | git-compat-util.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h index b2ab3f8256..ca0a597a28 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; |