strbuf_getwholeline: NUL-terminate getdelim buffer on error
[gitweb.git] / wrapper.c
index c95e2906b850749cbeb109050359b671979969f2..52001789ded0372becd3f55dda4cd1226c4b6dae 100644 (file)
--- a/wrapper.c
+++ b/wrapper.c
@@ -375,6 +375,19 @@ FILE *xfdopen(int fd, const char *mode)
        return stream;
 }
 
+FILE *fopen_for_writing(const char *path)
+{
+       FILE *ret = fopen(path, "w");
+
+       if (!ret && errno == EPERM) {
+               if (!unlink(path))
+                       ret = fopen(path, "w");
+               else
+                       errno = EPERM;
+       }
+       return ret;
+}
+
 int xmkstemp(char *template)
 {
        int fd;