Have you verified that all the platforms will actually return EINVAL in this case? Also this is the other spot of inconsistent meaning of the O_CLOEXEC macro. This causes problems with the locking surrounding fork down below.