MCPcopy Create free account
hub / github.com/git/git / git_open_cloexec

Function git_open_cloexec

compat/open.c:29–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27#endif
28
29int git_open_cloexec(const char *name, int flags)
30{
31 int fd;
32 static int o_cloexec = O_CLOEXEC;
33
34 fd = open(name, flags | o_cloexec);
35 if ((o_cloexec & O_CLOEXEC) && fd < 0 && errno == EINVAL) {
36 /* Try again w/o O_CLOEXEC: the kernel might not support it */
37 o_cloexec &= ~O_CLOEXEC;
38 fd = open(name, flags | o_cloexec);
39 }
40
41#if defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
42 {
43 static int fd_cloexec = FD_CLOEXEC;
44
45 if (!o_cloexec && 0 <= fd && fd_cloexec) {
46 /* Opened w/o O_CLOEXEC? try with fcntl(2) to add it */
47 int flags = fcntl(fd, F_GETFD);
48 if (fcntl(fd, F_SETFD, flags | fd_cloexec))
49 fd_cloexec = 0;
50 }
51 }
52#endif
53 return fd;
54}

Callers 1

ce_compare_dataFunction · 0.85

Calls 1

fcntlFunction · 0.85

Tested by

no test coverage detected