tempfile: avoid directory cleanup race
[git.git] / compat / open.c
blobeb3754a23b8f62d0d3de5489c4431653d098491b
1 #include "git-compat-util.h"
3 #undef open
4 int git_open_with_retry(const char *path, int flags, ...)
6 mode_t mode = 0;
7 int ret;
9 /*
10 * Also O_TMPFILE would take a mode, but it isn't defined everywhere.
11 * And anyway, we don't use it in our code base.
13 if (flags & O_CREAT) {
14 va_list ap;
15 va_start(ap, flags);
16 mode = va_arg(ap, int);
17 va_end(ap);
20 do {
21 ret = open(path, flags, mode);
22 } while (ret < 0 && errno == EINTR);
24 return ret;