33 assert(filename !=
NULL);
44#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__linux__) || \
45 defined(__NetBSD__) || defined(__OpenBSD__)
55 char mode_with_cloexec[4] = {0};
56 snprintf(mode_with_cloexec,
sizeof(mode_with_cloexec),
"%se",
mode);
57 return fopen_(filename, mode_with_cloexec);
62 char mode_with_cloexec[4] = {0};
63 snprintf(mode_with_cloexec,
sizeof(mode_with_cloexec),
"%sN",
mode);
64 return fopen_(filename, mode_with_cloexec);
70 int flags =
mode[0] ==
'w' ? (O_WRONLY | O_CREAT | O_TRUNC) : O_RDONLY;
81 const int fd = open(filename,
flags | O_CLOEXEC, 0666);
86 FILE *f = fdopen(fd,
mode);
88 const int err = errno;
109 const int fd = fileno(f);
110 const int flags = fcntl(fd, F_GETFD);
111 if (fcntl(fd, F_SETFD,
flags | FD_CLOEXEC) < 0) {
112 const int err = errno;