aboutsummaryrefslogtreecommitdiffstats
path: root/wrapper.c
diff options
context:
space:
mode:
Diffstat (limited to 'wrapper.c')
-rw-r--r--wrapper.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/wrapper.c b/wrapper.c
index 3d507d4204..1f12dbb2fa 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -688,6 +688,22 @@ void write_file_buf(const char *path, const char *buf, size_t len)
die_errno(_("could not close '%s'"), path);
}
+int write_file_buf_gently(const char *path, const char *buf, size_t len)
+{
+ int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+
+ if (fd < 0)
+ return error_errno(_("could not open '%s'"), path);
+ if (write_in_full(fd, buf, len) < 0) {
+ int ret = error_errno(_("could not write to '%s'"), path);
+ close(fd);
+ return ret;
+ }
+ if (close(fd))
+ return error_errno(_("could not close '%s'"), path);
+ return 0;
+}
+
void write_file(const char *path, const char *fmt, ...)
{
va_list params;