Skip to content

Commit

Permalink
Merge pull request #4647 from SmileTheory/lfn_wrong_filesize
Browse files Browse the repository at this point in the history
DOS_Int21_71a6(): Report correct file size on win32 when file is open.
  • Loading branch information
joncampbell123 authored Dec 2, 2023
2 parents 505231b + ac084fe commit 406ac94
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/dos/dos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5352,6 +5352,19 @@ void DOS_Int21_71a6(const char *name1, const char *name2) {
if(status.st_mode & S_IFDIR) st = DOS_ATTR_DIRECTORY;
else st = DOS_ATTR_ARCHIVE;

/* Win32 stat() will not return the correct file size of a file open for writing */
#if defined (WIN32)
if (Files[handle]->IsOpen())
{
Files[handle]->Flush();
uint32_t oldPos = Files[handle]->GetSeekPos();
uint32_t newPos = 0;
Files[handle]->Seek(&newPos, DOS_SEEK_END);
status.st_size = Files[handle]->GetSeekPos();
Files[handle]->Seek(&oldPos, DOS_SEEK_SET);
}
#endif

memset(buf, 0, 52);
set_dword(buf, st);
// 116444736000000000LL = FILETIME 1970/01/01 00:00:00
Expand Down

0 comments on commit 406ac94

Please sign in to comment.