From 239586a633cdee52b7783a9aea1d7e212298b44d Mon Sep 17 00:00:00 2001 From: xezon <4720891+xezon@users.noreply.github.com> Date: Thu, 17 Jul 2025 22:43:09 +0200 Subject: [PATCH 1/3] [CORE] Implement custom buffer options for LocalFile::open() --- Core/GameEngine/Include/Common/FileSystem.h | 4 +-- Core/GameEngine/Include/Common/LocalFile.h | 2 +- .../Include/Common/LocalFileSystem.h | 4 +-- Core/GameEngine/Include/Common/RAMFile.h | 2 +- .../Include/Common/StreamingArchiveFile.h | 2 +- Core/GameEngine/Include/Common/file.h | 26 ++++++++++++----- Core/GameEngine/Source/Common/System/File.cpp | 4 +-- .../Source/Common/System/FileSystem.cpp | 4 +-- .../Source/Common/System/LocalFile.cpp | 29 ++++++++++++++++--- .../Source/Common/System/RAMFile.cpp | 15 ++++++---- .../Common/System/StreamingArchiveFile.cpp | 10 +++---- .../StdDevice/Common/StdLocalFileSystem.h | 2 +- .../Win32Device/Common/Win32LocalFileSystem.h | 2 +- .../Source/StdDevice/Common/StdBIGFile.cpp | 3 +- .../StdDevice/Common/StdLocalFileSystem.cpp | 4 +-- .../Win32Device/Common/Win32BIGFile.cpp | 3 +- .../Common/Win32LocalFileSystem.cpp | 4 +-- 17 files changed, 77 insertions(+), 43 deletions(-) diff --git a/Core/GameEngine/Include/Common/FileSystem.h b/Core/GameEngine/Include/Common/FileSystem.h index 755e1c76b9..3ae6e83cbc 100644 --- a/Core/GameEngine/Include/Common/FileSystem.h +++ b/Core/GameEngine/Include/Common/FileSystem.h @@ -50,13 +50,13 @@ // Includes //---------------------------------------------------------------------------- +#include "Common/file.h" #include "Common/STLTypedefs.h" #include "Common/SubsystemInterface.h" //---------------------------------------------------------------------------- // Forward References //---------------------------------------------------------------------------- -class File; //---------------------------------------------------------------------------- // Type Defines @@ -130,7 +130,7 @@ class FileSystem : public SubsystemInterface void reset(); void update(); - File* openFile( const Char *filename, Int access = 0 ); ///< opens a File interface to the specified file + File* openFile( const Char *filename, Int access = File::NONE, size_t bufferSize = File::BUFFERSIZE ); ///< opens a File interface to the specified file Bool doesFileExist(const Char *filename) const; ///< returns TRUE if the file exists. filename should have no directory. void getFileListInDirectory(const AsciiString& directory, const AsciiString& searchName, FilenameList &filenameList, Bool searchSubdirectories) const; ///< search the given directory for files matching the searchName (egs. *.ini, *.rep). Possibly search subdirectories. Bool getFileInfo(const AsciiString& filename, FileInfo *fileInfo) const; ///< fills in the FileInfo struct for the file given. returns TRUE if successful. diff --git a/Core/GameEngine/Include/Common/LocalFile.h b/Core/GameEngine/Include/Common/LocalFile.h index 091ed57128..b7d1fdc5d8 100644 --- a/Core/GameEngine/Include/Common/LocalFile.h +++ b/Core/GameEngine/Include/Common/LocalFile.h @@ -96,7 +96,7 @@ class LocalFile : public File //virtual ~LocalFile(); - virtual Bool open( const Char *filename, Int access = 0 ); ///< Open a file for access + virtual Bool open( const Char *filename, Int access = NONE, size_t bufferSize = BUFFERSIZE ); ///< Open a file for access virtual void close( void ); ///< Close the file virtual Int read( void *buffer, Int bytes ); ///< Read the specified number of bytes in to buffer: See File::read virtual Int write( const void *buffer, Int bytes ); ///< Write the specified number of bytes from the buffer: See File::write diff --git a/Core/GameEngine/Include/Common/LocalFileSystem.h b/Core/GameEngine/Include/Common/LocalFileSystem.h index fcec949947..1a912b7f1b 100644 --- a/Core/GameEngine/Include/Common/LocalFileSystem.h +++ b/Core/GameEngine/Include/Common/LocalFileSystem.h @@ -34,8 +34,6 @@ #include "Common/SubsystemInterface.h" #include "FileSystem.h" // for typedefs, etc. -class File; - class LocalFileSystem : public SubsystemInterface { public: @@ -45,7 +43,7 @@ class LocalFileSystem : public SubsystemInterface virtual void reset() = 0; virtual void update() = 0; - virtual File * openFile(const Char *filename, Int access = 0) = 0; + virtual File * openFile(const Char *filename, Int access = File::NONE, size_t bufferSize = File::BUFFERSIZE) = 0; virtual Bool doesFileExist(const Char *filename) const = 0; virtual void getFileListInDirectory(const AsciiString& currentDirectory, const AsciiString& originalDirectory, const AsciiString& searchName, FilenameList &filenameList, Bool searchSubdirectories) const = 0; ///< search the given directory for files matching the searchName (egs. *.ini, *.rep). Possibly search subdirectories. virtual Bool getFileInfo(const AsciiString& filename, FileInfo *fileInfo) const = 0; ///< see FileSystem.h diff --git a/Core/GameEngine/Include/Common/RAMFile.h b/Core/GameEngine/Include/Common/RAMFile.h index 659b9a571c..6681344d38 100644 --- a/Core/GameEngine/Include/Common/RAMFile.h +++ b/Core/GameEngine/Include/Common/RAMFile.h @@ -87,7 +87,7 @@ class RAMFile : public File //virtual ~RAMFile(); - virtual Bool open( const Char *filename, Int access = 0 ); ///< Open a file for access + virtual Bool open( const Char *filename, Int access = NONE, size_t bufferSize = 0 ); ///< Open a file for access virtual void close( void ); ///< Close the file virtual Int read( void *buffer, Int bytes ); ///< Read the specified number of bytes in to buffer: See File::read virtual Int write( const void *buffer, Int bytes ); ///< Write the specified number of bytes from the buffer: See File::write diff --git a/Core/GameEngine/Include/Common/StreamingArchiveFile.h b/Core/GameEngine/Include/Common/StreamingArchiveFile.h index 1ba681e14e..38e683a229 100644 --- a/Core/GameEngine/Include/Common/StreamingArchiveFile.h +++ b/Core/GameEngine/Include/Common/StreamingArchiveFile.h @@ -88,7 +88,7 @@ class StreamingArchiveFile : public RAMFile //virtual ~StreamingArchiveFile(); - virtual Bool open( const Char *filename, Int access = 0 ); ///< Open a file for access + virtual Bool open( const Char *filename, Int access = NONE, size_t bufferSize = BUFFERSIZE ); ///< Open a file for access virtual void close( void ); ///< Close the file virtual Int read( void *buffer, Int bytes ); ///< Read the specified number of bytes in to buffer: See File::read virtual Int write( const void *buffer, Int bytes ); ///< Write the specified number of bytes from the buffer: See File::write diff --git a/Core/GameEngine/Include/Common/file.h b/Core/GameEngine/Include/Common/file.h index 56780ec15b..273e30b08b 100644 --- a/Core/GameEngine/Include/Common/file.h +++ b/Core/GameEngine/Include/Common/file.h @@ -89,15 +89,20 @@ class File : public MemoryPoolObject enum access { - NONE = 0x00000000, + NONE = 0x00000000, ///< Access file. Reading by default + READ = 0x00000001, ///< Access file for reading WRITE = 0x00000002, ///< Access file for writing + READWRITE = (READ | WRITE), + APPEND = 0x00000004, ///< Seek to end of file on open CREATE = 0x00000008, ///< Create file if it does not exist TRUNCATE = 0x00000010, ///< Delete all data in file when opened - TEXT = 0x00000020, ///< Access file as text data - BINARY = 0x00000040, ///< Access file as binary data - READWRITE = (READ | WRITE), + + // NOTE: accesses file as text data (with full buffering) if neither TEXT and BINARY are set + TEXT = 0x00000020, ///< Access file as text data (with line buffering) + BINARY = 0x00000040, ///< Access file as binary data (with full buffering) + ONLYNEW = 0x00000080, ///< Only create file if it does not exist // NOTE: STREAMING is Mutually exclusive with WRITE @@ -111,6 +116,11 @@ class File : public MemoryPoolObject END ///< Seek position is relative from the end of the file }; + enum + { + BUFFERSIZE = BUFSIZ, + }; + protected: AsciiString m_nameStr; ///< Stores file name @@ -128,20 +138,20 @@ class File : public MemoryPoolObject Bool eof(); - virtual Bool open( const Char *filename, Int access = 0 ); ///< Open a file for access + virtual Bool open( const Char *filename, Int access = NONE, size_t bufferSize = BUFFERSIZE ); ///< Open a file for access virtual void close( void ); ///< Close the file !!! File object no longer valid after this call !!! virtual Int read( void *buffer, Int bytes ) = NULL ; /**< Read the specified number of bytes from the file in to the * memory pointed at by buffer. Returns the number of bytes read. - * Returns -1 if an error occured. + * Returns -1 if an error occurred. */ virtual Int write( const void *buffer, Int bytes ) = NULL ; /**< Write the specified number of bytes from the * memory pointed at by buffer to the file. Returns the number of bytes written. - * Returns -1 if an error occured. + * Returns -1 if an error occurred. */ virtual Int seek( Int bytes, seekMode mode = CURRENT ) = NULL; /**< Sets the file position of the next read/write operation. Returns the new file * position as the number of bytes from the start of the file. - * Returns -1 if an error occured. + * Returns -1 if an error occurred. * * seekMode determines how the seek is done: * diff --git a/Core/GameEngine/Source/Common/System/File.cpp b/Core/GameEngine/Source/Common/System/File.cpp index c1b3964b3b..05688ccdc0 100644 --- a/Core/GameEngine/Source/Common/System/File.cpp +++ b/Core/GameEngine/Source/Common/System/File.cpp @@ -134,7 +134,7 @@ File::~File() */ //================================================================= -Bool File::open( const Char *filename, Int access ) +Bool File::open( const Char *filename, Int access, size_t bufferSize ) { if( m_open ) { @@ -160,7 +160,7 @@ Bool File::open( const Char *filename, Int access ) access |= READ; } - if ( !(access & (READ|APPEND)) ) + if ( (access & (READ|APPEND)) == 0 ) { access |= TRUNCATE; } diff --git a/Core/GameEngine/Source/Common/System/FileSystem.cpp b/Core/GameEngine/Source/Common/System/FileSystem.cpp index 164f72ee09..051d6d751e 100644 --- a/Core/GameEngine/Source/Common/System/FileSystem.cpp +++ b/Core/GameEngine/Source/Common/System/FileSystem.cpp @@ -171,14 +171,14 @@ void FileSystem::reset( void ) // FileSystem::open //============================================================================ -File* FileSystem::openFile( const Char *filename, Int access ) +File* FileSystem::openFile( const Char *filename, Int access, size_t bufferSize ) { USE_PERF_TIMER(FileSystem) File *file = NULL; if ( TheLocalFileSystem != NULL ) { - file = TheLocalFileSystem->openFile( filename, access ); + file = TheLocalFileSystem->openFile( filename, access, bufferSize ); if (file != NULL && (file->getAccess() & File::CREATE)) { unsigned key = TheNameKeyGenerator->nameToLowercaseKey(filename); diff --git a/Core/GameEngine/Source/Common/System/LocalFile.cpp b/Core/GameEngine/Source/Common/System/LocalFile.cpp index 512b37747e..08b0690a71 100644 --- a/Core/GameEngine/Source/Common/System/LocalFile.cpp +++ b/Core/GameEngine/Source/Common/System/LocalFile.cpp @@ -134,14 +134,14 @@ LocalFile::~LocalFile() // LocalFile::open //================================================================= /** - * This function opens a file using the standard C open() call. Access flags - * are mapped to the appropriate open flags. Returns true if file was opened - * successfully. + * This function opens a file using the standard C open() or + * fopen() call. Access flags are mapped to the appropriate flags. + * Returns true if file was opened successfully. */ //================================================================= //DECLARE_PERF_TIMER(LocalFile) -Bool LocalFile::open( const Char *filename, Int access ) +Bool LocalFile::open( const Char *filename, Int access, size_t bufferSize ) { //USE_PERF_TIMER(LocalFile) if( !File::open( filename, access) ) @@ -165,6 +165,7 @@ Bool LocalFile::open( const Char *filename, Int access ) const Bool append = (m_access & APPEND) != 0; const Bool create = (m_access & CREATE) != 0; const Bool truncate = (m_access & TRUNCATE) != 0; + const Bool text = (m_access & TEXT) != 0; const Bool binary = (m_access & BINARY) != 0; const Char *mode = NULL; @@ -199,6 +200,26 @@ Bool LocalFile::open( const Char *filename, Int access ) goto error; } + { + Int result = 0; + + if (bufferSize == 0) + { + result = setvbuf(m_file, NULL, _IONBF, 0); // Uses no buffering. + } + else + { + const Int bufferMode = text + ? _IOLBF // Uses line buffering + : _IOFBF; // Uses full buffering + + // Buffer is expected to lazy allocate on first read or write later. + result = setvbuf(m_file, NULL, bufferMode, bufferSize); + } + + DEBUG_ASSERTCRASH(result == 0, ("LocalFile::open - setvbuf failed")); + } + #else int flags = 0; diff --git a/Core/GameEngine/Source/Common/System/RAMFile.cpp b/Core/GameEngine/Source/Common/System/RAMFile.cpp index a34fbf0ac6..3e0dcee442 100644 --- a/Core/GameEngine/Source/Common/System/RAMFile.cpp +++ b/Core/GameEngine/Source/Common/System/RAMFile.cpp @@ -133,17 +133,20 @@ RAMFile::~RAMFile() // RAMFile::open //================================================================= /** - * This function opens a file using the standard C open() call. Access flags - * are mapped to the appropriate open flags. Returns true if file was opened - * successfully. + * This function opens a file using the standard C open() or + * fopen() call. Access flags are mapped to the appropriate flags. + * Returns true if file was opened successfully. */ //================================================================= //DECLARE_PERF_TIMER(RAMFile) -Bool RAMFile::open( const Char *filename, Int access ) +Bool RAMFile::open( const Char *filename, Int access, size_t bufferSize ) { //USE_PERF_TIMER(RAMFile) - File *file = TheFileSystem->openFile( filename, access ); + + bufferSize = 0; // RAM File needs no file buffer because it is read in one go. + + File *file = TheFileSystem->openFile( filename, access, bufferSize ); if ( file == NULL ) { @@ -169,7 +172,7 @@ Bool RAMFile::open( File *file ) return NULL; } - Int access = file->getAccess(); + const Int access = file->getAccess(); if ( !File::open( file->getName(), access )) { diff --git a/Core/GameEngine/Source/Common/System/StreamingArchiveFile.cpp b/Core/GameEngine/Source/Common/System/StreamingArchiveFile.cpp index 000e22195b..6149e3c55e 100644 --- a/Core/GameEngine/Source/Common/System/StreamingArchiveFile.cpp +++ b/Core/GameEngine/Source/Common/System/StreamingArchiveFile.cpp @@ -130,17 +130,17 @@ StreamingArchiveFile::~StreamingArchiveFile() // StreamingArchiveFile::open //================================================================= /** - * This function opens a file using the standard C open() call. Access flags - * are mapped to the appropriate open flags. Returns true if file was opened - * successfully. + * This function opens a file using the file system. Access flags + * are mapped to the appropriate open flags. Returns true if file + * was opened successfully. */ //================================================================= //DECLARE_PERF_TIMER(StreamingArchiveFile) -Bool StreamingArchiveFile::open( const Char *filename, Int access ) +Bool StreamingArchiveFile::open( const Char *filename, Int access, size_t bufferSize ) { //USE_PERF_TIMER(StreamingArchiveFile) - File *file = TheFileSystem->openFile( filename, access ); + File *file = TheFileSystem->openFile( filename, access, bufferSize ); if ( file == NULL ) { diff --git a/Core/GameEngineDevice/Include/StdDevice/Common/StdLocalFileSystem.h b/Core/GameEngineDevice/Include/StdDevice/Common/StdLocalFileSystem.h index b0409e5945..29a1b9285e 100644 --- a/Core/GameEngineDevice/Include/StdDevice/Common/StdLocalFileSystem.h +++ b/Core/GameEngineDevice/Include/StdDevice/Common/StdLocalFileSystem.h @@ -42,7 +42,7 @@ class StdLocalFileSystem : public LocalFileSystem virtual void reset(); virtual void update(); - virtual File * openFile(const Char *filename, Int access = 0); ///< open the given file. + virtual File * openFile(const Char *filename, Int access = File::NONE, size_t bufferSize = File::BUFFERSIZE); ///< open the given file. virtual Bool doesFileExist(const Char *filename) const; ///< does the given file exist? virtual void getFileListInDirectory(const AsciiString& currentDirectory, const AsciiString& originalDirectory, const AsciiString& searchName, FilenameList &filenameList, Bool searchSubdirectories) const; ///< search the given directory for files matching the searchName (egs. *.ini, *.rep). Possibly search subdirectories. diff --git a/Core/GameEngineDevice/Include/Win32Device/Common/Win32LocalFileSystem.h b/Core/GameEngineDevice/Include/Win32Device/Common/Win32LocalFileSystem.h index c2c1c1cd7b..49477ee6d3 100644 --- a/Core/GameEngineDevice/Include/Win32Device/Common/Win32LocalFileSystem.h +++ b/Core/GameEngineDevice/Include/Win32Device/Common/Win32LocalFileSystem.h @@ -42,7 +42,7 @@ class Win32LocalFileSystem : public LocalFileSystem virtual void reset(); virtual void update(); - virtual File * openFile(const Char *filename, Int access = 0); ///< open the given file. + virtual File * openFile(const Char *filename, Int access = File::NONE, size_t bufferSize = File::BUFFERSIZE); ///< open the given file. virtual Bool doesFileExist(const Char *filename) const; ///< does the given file exist? virtual void getFileListInDirectory(const AsciiString& currentDirectory, const AsciiString& originalDirectory, const AsciiString& searchName, FilenameList &filenameList, Bool searchSubdirectories) const; ///< search the given directory for files matching the searchName (egs. *.ini, *.rep). Possibly search subdirectories. diff --git a/Core/GameEngineDevice/Source/StdDevice/Common/StdBIGFile.cpp b/Core/GameEngineDevice/Source/StdDevice/Common/StdBIGFile.cpp index 9515af78c1..7a9c9d15fe 100644 --- a/Core/GameEngineDevice/Source/StdDevice/Common/StdBIGFile.cpp +++ b/Core/GameEngineDevice/Source/StdDevice/Common/StdBIGFile.cpp @@ -86,7 +86,8 @@ File* StdBIGFile::openFile( const Char *filename, Int access ) // whoever is opening this file wants write access, so copy the file to the local disk // and return that file pointer. - File *localFile = TheLocalFileSystem->openFile(filename, access); + CONSTEXPR size_t bufferSize = 0; + File *localFile = TheLocalFileSystem->openFile(filename, access, bufferSize); if (localFile != NULL) { ramFile->copyDataToFile(localFile); } diff --git a/Core/GameEngineDevice/Source/StdDevice/Common/StdLocalFileSystem.cpp b/Core/GameEngineDevice/Source/StdDevice/Common/StdLocalFileSystem.cpp index 02398f465b..e7cd7a12df 100644 --- a/Core/GameEngineDevice/Source/StdDevice/Common/StdLocalFileSystem.cpp +++ b/Core/GameEngineDevice/Source/StdDevice/Common/StdLocalFileSystem.cpp @@ -125,7 +125,7 @@ static std::filesystem::path fixFilenameFromWindowsPath(const Char *filename, In return path; } -File * StdLocalFileSystem::openFile(const Char *filename, Int access /* = 0 */) +File * StdLocalFileSystem::openFile(const Char *filename, Int access, size_t bufferSize) { //USE_PERF_TIMER(StdLocalFileSystem_openFile) @@ -155,7 +155,7 @@ File * StdLocalFileSystem::openFile(const Char *filename, Int access /* = 0 */) StdLocalFile *file = newInstance( StdLocalFile ); - if (file->open(path.string().c_str(), access) == FALSE) { + if (file->open(path.string().c_str(), access, bufferSize) == FALSE) { deleteInstance(file); file = NULL; } else { diff --git a/Core/GameEngineDevice/Source/Win32Device/Common/Win32BIGFile.cpp b/Core/GameEngineDevice/Source/Win32Device/Common/Win32BIGFile.cpp index 9eb8ca5fe7..a4519304d5 100644 --- a/Core/GameEngineDevice/Source/Win32Device/Common/Win32BIGFile.cpp +++ b/Core/GameEngineDevice/Source/Win32Device/Common/Win32BIGFile.cpp @@ -86,7 +86,8 @@ File* Win32BIGFile::openFile( const Char *filename, Int access ) // whoever is opening this file wants write access, so copy the file to the local disk // and return that file pointer. - File *localFile = TheLocalFileSystem->openFile(filename, access); + CONSTEXPR size_t bufferSize = 0; + File *localFile = TheLocalFileSystem->openFile(filename, access, bufferSize); if (localFile != NULL) { ramFile->copyDataToFile(localFile); } diff --git a/Core/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp b/Core/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp index 8d2b90daeb..d68f768df7 100644 --- a/Core/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp +++ b/Core/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp @@ -42,7 +42,7 @@ Win32LocalFileSystem::~Win32LocalFileSystem() { } //DECLARE_PERF_TIMER(Win32LocalFileSystem_openFile) -File * Win32LocalFileSystem::openFile(const Char *filename, Int access /* = 0 */) +File * Win32LocalFileSystem::openFile(const Char *filename, Int access, size_t bufferSize) { //USE_PERF_TIMER(Win32LocalFileSystem_openFile) @@ -71,7 +71,7 @@ File * Win32LocalFileSystem::openFile(const Char *filename, Int access /* = 0 */ // TheSuperHackers @fix Mauller 21/04/2025 Create new file handle when necessary to prevent memory leak Win32LocalFile *file = newInstance( Win32LocalFile ); - if (file->open(filename, access) == FALSE) { + if (file->open(filename, access, bufferSize) == FALSE) { deleteInstance(file); file = NULL; } else { From 2ce3c3ac148db0a0e32b3c2bca7f8c9668454023 Mon Sep 17 00:00:00 2001 From: xezon <4720891+xezon@users.noreply.github.com> Date: Fri, 18 Jul 2025 18:53:10 +0200 Subject: [PATCH 2/3] Add LINEBUF and FULLBUF modes --- Core/GameEngine/Include/Common/file.h | 14 ++++++++++---- Core/GameEngine/Source/Common/System/LocalFile.cpp | 4 +--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Core/GameEngine/Include/Common/file.h b/Core/GameEngine/Include/Common/file.h index 273e30b08b..c8dac63869 100644 --- a/Core/GameEngine/Include/Common/file.h +++ b/Core/GameEngine/Include/Common/file.h @@ -76,6 +76,8 @@ * * All code should use the File class and not its derivatives, unless * absolutely necessary. Also FS::Open should be used to create File objects and open files. + * + * TheSuperHackers @feature Adds LINEBUF and FULLBUF modes and buffer size argument for file open. */ //=============================== @@ -99,14 +101,18 @@ class File : public MemoryPoolObject CREATE = 0x00000008, ///< Create file if it does not exist TRUNCATE = 0x00000010, ///< Delete all data in file when opened - // NOTE: accesses file as text data (with full buffering) if neither TEXT and BINARY are set - TEXT = 0x00000020, ///< Access file as text data (with line buffering) - BINARY = 0x00000040, ///< Access file as binary data (with full buffering) + // NOTE: accesses file as text data if neither TEXT and BINARY are set + TEXT = 0x00000020, ///< Access file as text data + BINARY = 0x00000040, ///< Access file as binary data ONLYNEW = 0x00000080, ///< Only create file if it does not exist // NOTE: STREAMING is Mutually exclusive with WRITE - STREAMING = 0x00000100 ///< Do not read this file into a ram file, read it as requested. + STREAMING = 0x00000100, ///< Do not read this file into a ram file, read it as requested. + + // NOTE: accesses file with full buffering if neither LINEBUF and FULLBUF are set + LINEBUF = 0x00000200, ///< Access file with line buffering + FULLBUF = 0x00000400, ///< Access file with full buffering }; enum seekMode diff --git a/Core/GameEngine/Source/Common/System/LocalFile.cpp b/Core/GameEngine/Source/Common/System/LocalFile.cpp index 08b0690a71..1c450e3d7c 100644 --- a/Core/GameEngine/Source/Common/System/LocalFile.cpp +++ b/Core/GameEngine/Source/Common/System/LocalFile.cpp @@ -165,14 +165,12 @@ Bool LocalFile::open( const Char *filename, Int access, size_t bufferSize ) const Bool append = (m_access & APPEND) != 0; const Bool create = (m_access & CREATE) != 0; const Bool truncate = (m_access & TRUNCATE) != 0; - const Bool text = (m_access & TEXT) != 0; const Bool binary = (m_access & BINARY) != 0; const Char *mode = NULL; // Mode string selection (mimics _open flag combinations) // TEXT is implicit for fopen if 'b' is not present - // READ is implicit here if not READWRITE or WRITE if (readwrite) { if (append) @@ -209,7 +207,7 @@ Bool LocalFile::open( const Char *filename, Int access, size_t bufferSize ) } else { - const Int bufferMode = text + const Int bufferMode = (m_access & LINEBUF) ? _IOLBF // Uses line buffering : _IOFBF; // Uses full buffering From 6fddb34d26092aeef5772c83d242bb40bb7bb483 Mon Sep 17 00:00:00 2001 From: xezon <4720891+xezon@users.noreply.github.com> Date: Fri, 18 Jul 2025 18:57:09 +0200 Subject: [PATCH 3/3] Polish comments --- Core/GameEngine/Source/Common/System/LocalFile.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/GameEngine/Source/Common/System/LocalFile.cpp b/Core/GameEngine/Source/Common/System/LocalFile.cpp index 1c450e3d7c..99073243c6 100644 --- a/Core/GameEngine/Source/Common/System/LocalFile.cpp +++ b/Core/GameEngine/Source/Common/System/LocalFile.cpp @@ -203,7 +203,7 @@ Bool LocalFile::open( const Char *filename, Int access, size_t bufferSize ) if (bufferSize == 0) { - result = setvbuf(m_file, NULL, _IONBF, 0); // Uses no buffering. + result = setvbuf(m_file, NULL, _IONBF, 0); // Uses no buffering } else { @@ -211,7 +211,7 @@ Bool LocalFile::open( const Char *filename, Int access, size_t bufferSize ) ? _IOLBF // Uses line buffering : _IOFBF; // Uses full buffering - // Buffer is expected to lazy allocate on first read or write later. + // Buffer is expected to lazy allocate on first read or write later result = setvbuf(m_file, NULL, bufferMode, bufferSize); }