Fix the external-io unittest under Windows.
In particular, fixes the following issues:
- When creating a temporary file, open it with read+write permissions.
- _chsize returns 0 on success (just like ftruncate).
- To set a std::optional, use its assign-operator overload instead of getting a reference of its value an overwrite that. The latter is invalid if the std::optional has no value, and is caught by msvc's debug STL.
The non-GTest unittest is currently not executed under Windows because of the added .exe extension to the output file: external-io.text.exe. llvm-lit skips the file because .exe is not in the lists of test suffixes (.test is). D105315 is going to change that by converting it to a gtest-test.