summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2021-03-04 15:34:45 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2021-03-04 15:34:45 -0800
commit921846fa22adb0abc3fb35e18c6be5feb5091cdd (patch)
tree4b53b3b120ff88bf1e1e93d7e36902d1aa5d8a8f /compat
parentMerge https://github.com/prati0100/git-gui (diff)
parentconfig.mak.uname: enable OPEN_RETURNS_EINTR for macOS Big Sur (diff)
downloadtgif-921846fa22adb0abc3fb35e18c6be5feb5091cdd.tar.xz
Merge branch 'jk/open-returns-eintr'
Work around platforms whose open() is reported to return EINTR (it shouldn't, as we do our signals with SA_RESTART). * jk/open-returns-eintr: config.mak.uname: enable OPEN_RETURNS_EINTR for macOS Big Sur Makefile: add OPEN_RETURNS_EINTR knob
Diffstat (limited to 'compat')
-rw-r--r--compat/mingw.h1
-rw-r--r--compat/open.c25
2 files changed, 26 insertions, 0 deletions
diff --git a/compat/mingw.h b/compat/mingw.h
index af8eddd73e..c9a52ad64a 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -227,6 +227,7 @@ int mingw_rmdir(const char *path);
int mingw_open (const char *filename, int oflags, ...);
#define open mingw_open
+#undef OPEN_RETURNS_EINTR
int mingw_fgetc(FILE *stream);
#define fgetc mingw_fgetc
diff --git a/compat/open.c b/compat/open.c
new file mode 100644
index 0000000000..eb3754a23b
--- /dev/null
+++ b/compat/open.c
@@ -0,0 +1,25 @@
+#include "git-compat-util.h"
+
+#undef open
+int git_open_with_retry(const char *path, int flags, ...)
+{
+ mode_t mode = 0;
+ int ret;
+
+ /*
+ * Also O_TMPFILE would take a mode, but it isn't defined everywhere.
+ * And anyway, we don't use it in our code base.
+ */
+ if (flags & O_CREAT) {
+ va_list ap;
+ va_start(ap, flags);
+ mode = va_arg(ap, int);
+ va_end(ap);
+ }
+
+ do {
+ ret = open(path, flags, mode);
+ } while (ret < 0 && errno == EINTR);
+
+ return ret;
+}