Break up mkstemp impl to provide mktemp impl.

The libcxx test suite wants mktemp(), so provide it by pulling
out some of the internals of mkstemp().