Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Edited VFSFileImpl::read to use both read/fread #6456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion 26 libraries/FS/src/vfs_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
// limitations under the License.

#include "vfs_api.h"
#include <stdio_ext.h>

using namespace fs;

#define READ_SIZE_SWITCH 128 //swithc to read func when read size > 128bytes

FileImplPtr VFSImpl::open(const char* fpath, const char* mode, const bool create)
{
if(!_mountpoint) {
Expand Down Expand Up @@ -374,7 +377,28 @@ size_t VFSFileImpl::read(uint8_t* buf, size_t size)
return 0;
}

return fread(buf, 1, size, _f);
//ERASE BYTEBUFFER and use read when size > READ_SIZE_SWITCH always
if(size > READ_SIZE_SWITCH)
{
//check some data in buffer exists –> clear buffer and move pointer to deleted data
size_t bytesinbuf = __fpending(_f);
if (bytesinbuf && (bytesinbuf != 128)) //buffer lenght is 128 bytes
{
fpurge(_f);
lseek(fileno(_f),(-128+bytesinbuf),SEEK_CUR);
}

int res = ::read(fileno(_f), buf, size);
if (res < 0) {
// an error occurred
return 0;
}
return res;
}
else
{
return fread(buf, 1, size, _f);
}
}

void VFSFileImpl::flush()
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.