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().
Merge pull request #1666 from waywardmonkeys/add-mktemp

Add mktemp