Skip to content

Commit fb3838a

Browse files
authored
Update vfs_api.cpp
1 parent bc05920 commit fb3838a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Diff for: libraries/FS/src/vfs_api.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
using namespace fs;
1818

19+
#define DEFAULT_FILE_BUFFER_SIZE 4096
20+
1921
FileImplPtr VFSImpl::open(const char* fpath, const char* mode, const bool create)
2022
{
2123
if(!_mountpoint) {
@@ -280,6 +282,10 @@ VFSFileImpl::VFSFileImpl(VFSImpl* fs, const char* fpath, const char* mode)
280282
if(!_f) {
281283
log_e("fopen(%s) failed", temp);
282284
}
285+
if(_f && (_stat.st_blksize == 0))
286+
{
287+
setvbuf(_f,NULL,_IOFBF,DEFAULT_FILE_BUFFER_SIZE);
288+
}
283289
} else if(S_ISDIR(_stat.st_mode)) {
284290
_isDirectory = true;
285291
_d = opendir(temp);
@@ -307,6 +313,10 @@ VFSFileImpl::VFSFileImpl(VFSImpl* fs, const char* fpath, const char* mode)
307313
if(!_f) {
308314
log_e("fopen(%s) failed", temp);
309315
}
316+
if(_f && (_stat.st_blksize == 0))
317+
{
318+
setvbuf(_f,NULL,_IOFBF,DEFAULT_FILE_BUFFER_SIZE);
319+
}
310320
}
311321
}
312322
free(temp);
@@ -415,6 +425,19 @@ size_t VFSFileImpl::size() const
415425
return _stat.st_size;
416426
}
417427

428+
/*
429+
* Change size of files internal buffer used for read / write operations.
430+
* Need to be called right after opening file before any other operation!
431+
*/
432+
bool VFSFileImpl::setBufferSize(size_t size)
433+
{
434+
if(_isDirectory || !_f) {
435+
return 0;
436+
}
437+
int res = setvbuf(_f,NULL,_IOFBF,size);
438+
return res == 0;
439+
}
440+
418441
const char* VFSFileImpl::path() const
419442
{
420443
return (const char*) _path;

0 commit comments

Comments
 (0)