It is not portable, that is why I went this route. I'll reformulate the code to avoid the problems you mentioned.
(The O_CLOEXEC flag is not specified in POSIX.1-2001, but is specified in POSIX.1-2008, which leaves some of our supported systems out)