mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-24 06:14:47 +02:00
Fix empty file with non-Unicode encoding cannot be saved issue
The PR fixes the regression due to the saving file API being changecd from POSIX functions to Win32 native API: The old used function "fopen" using "wbc" as argument, according Microsoft document: "w" Opens an empty file for writing. If the given file exists, its contents are destroyed. (https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fopen-wfopen?view=msvc-160) so to save a 0 length document, it was unecessary to "write nothing" explicitely on disk, since fopen did it for you. Whereas our new implementation which uses Win32 native API passes "OPEN_ALWAYS" - that needs to "write nothing" explicitely. Fix #10699, close #10702
This commit is contained in:
parent
38de8b2306
commit
1a02319a8a
@ -1010,6 +1010,12 @@ SavingStatus FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool i
|
||||
else
|
||||
{
|
||||
WcharMbcsConvertor& wmc = WcharMbcsConvertor::getInstance();
|
||||
if (lengthDoc == 0)
|
||||
{
|
||||
isWrittenSuccessful = UnicodeConvertor.writeFile(buf, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
int grabSize;
|
||||
for (int i = 0; i < lengthDoc; i += grabSize)
|
||||
{
|
||||
@ -1023,8 +1029,7 @@ SavingStatus FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool i
|
||||
grabSize -= incompleteMultibyteChar;
|
||||
isWrittenSuccessful = UnicodeConvertor.writeFile(newData, static_cast<unsigned long>(newDataLen));
|
||||
}
|
||||
if (lengthDoc == 0)
|
||||
isWrittenSuccessful = true;
|
||||
}
|
||||
}
|
||||
|
||||
// check the language du fichier
|
||||
|
Loading…
x
Reference in New Issue
Block a user