It would be good to cache the result in a no_cloexec static variable so you don't keep repeating the open(O_CLOEXEC) call when it's unsupported.