In addition to kre@'s comments about reviewing fcntl(F_GETFD), I would add a fd_set_fdflags_from_oflags() that does: fd_set_fdflags(curlwp, newfd, ((flags & O_CLOEXEC) ? FD_CLOEXEC : 0) | ((flags & O_CLOFORK) ? FD_CLOFORK : 0)); since this is repeated a bunch of times. christos