Merge pull request #8770 from WalterBright/setmode

fix Issue 23312 - Crash when calling writeln in WinMain
This commit is contained in:
Walter Bright 2023-06-21 11:24:52 -07:00 committed by GitHub
commit b3e664e174
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3112,10 +3112,13 @@ is empty, throws an `Exception`. In case of an I/O error throws
// "wide-oriented" for us.
immutable int mode = __setmode(f.fileno, _O_TEXT);
// Set some arbitrary mode to obtain the previous one.
__setmode(f.fileno, mode); // Restore previous mode.
if (mode & (_O_WTEXT | _O_U16TEXT | _O_U8TEXT))
if (mode != -1) // __setmode() succeeded
{
orientation_ = 1; // wide
__setmode(f.fileno, mode); // Restore previous mode.
if (mode & (_O_WTEXT | _O_U16TEXT | _O_U8TEXT))
{
orientation_ = 1; // wide
}
}
}
else