write_file: use xopen
authorJeff King <peff@peff.net>
Fri, 8 Jul 2016 09:10:08 +0000 (05:10 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 8 Jul 2016 16:47:29 +0000 (09:47 -0700)
This simplifies the code a tiny bit, and provides consistent
error messages with other users of xopen().

While we're here, let's also switch to using O_WRONLY. We
know we're only going to open/write/close the file, so
there's no point in asking for O_RDWR.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
wrapper.c
index 0349441bde57eada06d1c7b99fa45d760a00b2a8..7c126b87c50d4d46a986b0de42b4038e92face69 100644 (file)
--- a/wrapper.c
+++ b/wrapper.c
@@ -644,9 +644,7 @@ void write_file(const char *path, const char *fmt, ...)
 {
        va_list params;
        struct strbuf sb = STRBUF_INIT;
-       int fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0666);
-       if (fd < 0)
-               die_errno(_("could not open %s for writing"), path);
+       int fd = xopen(path, O_WRONLY | O_CREAT | O_TRUNC, 0666);
 
        va_start(params, fmt);
        strbuf_vaddf(&sb, fmt, params);