32 assert(filename !=
NULL);
34 assert(strcmp(
mode,
"r") == 0 || strcmp(
mode,
"rb") == 0 ||
35 strcmp(
mode,
"w") == 0 || strcmp(
mode,
"wb") == 0);
43#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__linux__) || \
44 defined(__NetBSD__) || defined(__OpenBSD__)
54 char mode_with_cloexec[4] = {0};
55 snprintf(mode_with_cloexec,
sizeof(mode_with_cloexec),
"%se",
mode);
56 return fopen_(filename, mode_with_cloexec);
61 char mode_with_cloexec[4] = {0};
62 snprintf(mode_with_cloexec,
sizeof(mode_with_cloexec),
"%sN",
mode);
63 return fopen_(filename, mode_with_cloexec);
69 int flags =
mode[0] ==
'w' ? (O_WRONLY | O_CREAT | O_TRUNC) : O_RDONLY;
80 const int fd = open(filename,
flags | O_CLOEXEC, 0666);
85 FILE *f = fdopen(fd,
mode);
87 const int err = errno;
108 const int fd = fileno(f);
109 const int flags = fcntl(fd, F_GETFD);
110 if (fcntl(fd, F_SETFD,
flags | FD_CLOEXEC) < 0) {
111 const int err = errno;