[PATCH 0/1] MR898: scrrun-OpenTextFile-create
Fix bugs in FileSystemObject text-file handling OpenTextFile(...,ForWriting,True) should either create a new file, or open and truncate an existing one OpenTextFile(...,ForAppending,?,True) should write a BOM if appending to an existing-but-empty file -- https://gitlab.winehq.org/wine/wine/-/merge_requests/898
From: Kevin Puetz <PuetzKevinA(a)JohnDeere.com> Fix bugs in FileSystemObject text-file handling OpenTextFile(...,ForWriting,True) should either create a new file, or open and truncate an existing one OpenTextFile(...,ForAppending,?,True) should write a BOM if appending to an existing-but-empty file --- dlls/scrrun/filesystem.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/dlls/scrrun/filesystem.c b/dlls/scrrun/filesystem.c index cfeb5bb1532..e53355267db 100644 --- a/dlls/scrrun/filesystem.c +++ b/dlls/scrrun/filesystem.c @@ -897,7 +897,7 @@ static HRESULT create_textstream(const WCHAR *filename, DWORD disposition, IOMod { stream->unicode = format == TristateTrue; /* Write Unicode BOM */ - if (stream->unicode && (disposition == CREATE_ALWAYS || disposition == CREATE_NEW)) { + if (stream->unicode && (disposition == CREATE_ALWAYS || disposition == CREATE_NEW || disposition == TRUNCATE_EXISTING)) { DWORD written = 0; BOOL ret = WriteFile(stream->file, &utf16bom, sizeof(utf16bom), &written, NULL); if (!ret || written != sizeof(utf16bom)) { @@ -939,7 +939,20 @@ static HRESULT create_textstream(const WCHAR *filename, DWORD disposition, IOMod stream->eof = read != sizeof(buf); } - else SetFilePointer(stream->file, 0, 0, FILE_END); + else + { + LONG filePosHigh = 0; + DWORD filePosLow = SetFilePointer(stream->file, 0, &filePosHigh, FILE_END); + if(stream->unicode && filePosHigh == 0 && filePosLow == 0) { + /* unicode ForAppending to an empty file, write BOM */ + DWORD written = 0; + BOOL ret = WriteFile(stream->file, &utf16bom, sizeof(utf16bom), &written, NULL); + if (!ret || written != sizeof(utf16bom)) { + ITextStream_Release(&stream->ITextStream_iface); + return create_error(GetLastError()); + } + } + } } init_classinfo(&CLSID_TextStream, (IUnknown *)&stream->ITextStream_iface, &stream->classinfo); @@ -4049,7 +4062,11 @@ static HRESULT WINAPI filesys_OpenTextFile(IFileSystem3 *iface, BSTR filename, TRACE("(%p)->(%s %d %d %d %p)\n", iface, debugstr_w(filename), mode, create, format, stream); - disposition = create == VARIANT_TRUE ? OPEN_ALWAYS : OPEN_EXISTING; + if(mode == ForWriting) { + disposition = create == VARIANT_TRUE ? CREATE_ALWAYS : TRUNCATE_EXISTING; + } else { + disposition = create == VARIANT_TRUE ? OPEN_ALWAYS : OPEN_EXISTING; + } return create_textstream(filename, disposition, mode, format, stream); } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/898
participants (2)
-
Kevin Puetz -
Kevin Puetz (@puetzk)