- f2 = fopen("/dev/null", mode);
- if (!f2) goto fail;
- fl = syscall(SYS_fcntl, f2->fd, F_GETFL, 0);
- if (fl < 0 || syscall(SYS_fcntl, f->fd, F_SETFL, fl) < 0)
- goto fail2;
+ if (fl&O_CLOEXEC)
+ __syscall(SYS_fcntl, f->fd, F_SETFD, FD_CLOEXEC);
+ fl &= ~(O_CREAT|O_EXCL|O_CLOEXEC);
+ if (syscall(SYS_fcntl, f->fd, F_SETFL, fl) < 0)
+ goto fail;