diff --git a/flang/runtime/file.cpp b/flang/runtime/file.cpp --- a/flang/runtime/file.cpp +++ b/flang/runtime/file.cpp @@ -45,7 +45,8 @@ if (::GetTempFileNameA(tempDirName, "Fortran", uUnique, tempFileName) == 0) { return -1; } - int fd{::_open(tempFileName, _O_CREAT | _O_TEMPORARY, _S_IREAD | _S_IWRITE)}; + int fd{::_open( + tempFileName, _O_CREAT | _O_TEMPORARY | _O_RDWR, _S_IREAD | _S_IWRITE)}; #else char path[]{"/tmp/Fortran-Scratch-XXXXXX"}; int fd{::mkstemp(path)}; @@ -245,7 +246,7 @@ inline static int openfile_ftruncate(int fd, OpenFile::FileOffset at) { #ifdef _WIN32 - return !::_chsize(fd, at); + return ::_chsize(fd, at); #else return ::ftruncate(fd, at); #endif diff --git a/flang/runtime/unit.cpp b/flang/runtime/unit.cpp --- a/flang/runtime/unit.cpp +++ b/flang/runtime/unit.cpp @@ -687,13 +687,13 @@ if (const char *p{ FindLastNewline(Frame(), prevNL - 1 - frameOffsetInFile_)}) { recordOffsetInFrame_ = p - Frame() + 1; - *recordLength = prevNL - (frameOffsetInFile_ + recordOffsetInFrame_); + recordLength = prevNL - (frameOffsetInFile_ + recordOffsetInFrame_); break; } } if (frameOffsetInFile_ == 0) { recordOffsetInFrame_ = 0; - *recordLength = prevNL; + recordLength = prevNL; break; } frameOffsetInFile_ -= std::min(frameOffsetInFile_, 1024);