mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-16 07:57:13 -04:00
Reduce the number of write()
This commit is contained in:
parent
7af924f154
commit
5993ad3504
@ -26,6 +26,8 @@ const char* early_logs[MAX_EARLY];
|
||||
|
||||
const char* new_line = "\n";
|
||||
|
||||
std::string buffer;
|
||||
|
||||
void append_to_file(const char* s, size_t length){
|
||||
auto fd = vfs::open("/messages", std::OPEN_CREATE);
|
||||
|
||||
@ -33,8 +35,10 @@ void append_to_file(const char* s, size_t length){
|
||||
stat_info info;
|
||||
if(vfs::stat(fd, info) == 0){
|
||||
if(vfs::truncate(fd, info.size + length + 1) == 0){
|
||||
vfs::write(fd, s, length, info.size);
|
||||
vfs::write(fd, new_line, 1, info.size + length);
|
||||
buffer = s;
|
||||
buffer += '\n';
|
||||
|
||||
vfs::write(fd, buffer.c_str(), buffer.size(), info.size);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user