35 assert(filename !=
NULL);
46#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__linux__) || \
47 defined(__NetBSD__) || defined(__OpenBSD__)
57 char mode_with_cloexec[4] = {0};
58 snprintf(mode_with_cloexec,
sizeof(mode_with_cloexec),
"%se",
mode);
59 return fopen_(filename, mode_with_cloexec);
64 char mode_with_cloexec[4] = {0};
65 snprintf(mode_with_cloexec,
sizeof(mode_with_cloexec),
"%sN",
mode);
66 return fopen_(filename, mode_with_cloexec);
72 int flags =
mode[0] ==
'w' ? (O_WRONLY | O_CREAT | O_TRUNC) : O_RDONLY;
83 const int fd = open(filename,
flags | O_CLOEXEC, 0666);
88 FILE *f = fdopen(fd,
mode);
90 const int err = errno;
111 const int fd = fileno(f);
112 const int flags = fcntl(fd, F_GETFD);
113 if (fcntl(fd, F_SETFD,
flags | FD_CLOEXEC) < 0) {
114 const int err = errno;