Skip to content

Commit

Permalink
Add eofOk parameter to the Windows readLine impl
Browse files Browse the repository at this point in the history
Now the two implementations are back in sync.
  • Loading branch information
Ericson2314 committed Nov 7, 2024
1 parent 3723537 commit a6149eb
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/libutil/windows/file-descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void writeFull(HANDLE handle, std::string_view s, bool allowInterrupts)
}


std::string readLine(HANDLE handle)
std::string readLine(HANDLE handle, bool eofOk)
{
std::string s;
while (1) {
Expand All @@ -71,8 +71,12 @@ std::string readLine(HANDLE handle)
DWORD rd;
if (!ReadFile(handle, &ch, 1, &rd, NULL)) {
throw WinError("reading a line");
} else if (rd == 0)
throw EndOfFile("unexpected EOF reading a line");
} else if (rd == 0) {
if (eofOk)
return s;
else
throw EndOfFile("unexpected EOF reading a line");
}
else {
if (ch == '\n') return s;
s += ch;
Expand Down

0 comments on commit a6149eb

Please sign in to comment.