X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=git-compat-util.h;h=ca0a597a282328bff9e0e29fd3653dbd656489fb;hb=38762c47d6442dc0ce0f45533f9151877c485337;hp=b2ab3f82567d54607a07f4061153adae86854fa9;hpb=e1341abc3759950e891822088cb0163b71b316b3;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;