Like so:
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) { ...
Though I've read man fcntl, I can't figure out what it does.
man fcntl