+ if (exec 3>&0) 2>/dev/null; then :; else exec 0</dev/null; fi + if (exec 3>&1) 2>/dev/null; then :; else exec 1>/dev/null; fi + if (exec 3>&2) ; then :; else exec 2>/dev/null; fi
This is all _AS_ENSURE_STANDARD_FDS needs to do; none of the other stuff is needed and I suggest omitting it as a maintenance time-sink.
POSIX programs and utilities merely need file descriptors 0, 1, and 2 to be open; it doesn't matter whether they're open for read or for write. The point is that an ordinary 'open' syscall should never return FDs 0 thru 2; not that 'read' from 0 or 'write' to 1 or 2 must succeed (there's never any guarantee of that).