diff options
author | Paul Tan <pyokagan@gmail.com> | 2015-08-04 21:51:23 +0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-08-04 22:02:11 -0700 |
commit | 260eec292736388831958637eccdcf1a8f00e14d (patch) | |
tree | 8492c821dac8943a3b03ef25c5a3cecb1887b8c0 /git-compat-util.h | |
parent | wrapper: implement xopen() (diff) | |
download | tgif-260eec292736388831958637eccdcf1a8f00e14d.tar.xz |
wrapper: implement xfopen()
A common usage pattern of fopen() is to check if it succeeded, and die()
if it failed:
FILE *fp = fopen(path, "w");
if (!fp)
die_errno(_("could not open '%s' for writing"), path);
Implement a wrapper function xfopen() for the above, so that we can save
a few lines of code and make the die() messages consistent.
Helped-by: Jeff King <peff@peff.net>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-compat-util.h')
-rw-r--r-- | git-compat-util.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h index e168dfd68b..392da79029 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -722,6 +722,7 @@ extern ssize_t xread(int fd, void *buf, size_t len); extern ssize_t xwrite(int fd, const void *buf, size_t len); extern ssize_t xpread(int fd, void *buf, size_t len, off_t offset); extern int xdup(int fd); +extern FILE *xfopen(const char *path, const char *mode); extern FILE *xfdopen(int fd, const char *mode); extern int xmkstemp(char *template); extern int xmkstemp_mode(char *template, int mode); |