Comment by asveikau

4 years ago

closefrom() comes in handy for this. It's missing on some platforms (notably glibc and mac iirc) but actually not too hard to implement a work-alike.

I've copied a closefrom() many a time.

A common hack I've had to add is an argument FD that is not to be closed because. e.g., an flock is held on it.