mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-17 00:26:44 -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";
|
const char* new_line = "\n";
|
||||||
|
|
||||||
|
std::string buffer;
|
||||||
|
|
||||||
void append_to_file(const char* s, size_t length){
|
void append_to_file(const char* s, size_t length){
|
||||||
auto fd = vfs::open("/messages", std::OPEN_CREATE);
|
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;
|
stat_info info;
|
||||||
if(vfs::stat(fd, info) == 0){
|
if(vfs::stat(fd, info) == 0){
|
||||||
if(vfs::truncate(fd, info.size + length + 1) == 0){
|
if(vfs::truncate(fd, info.size + length + 1) == 0){
|
||||||
vfs::write(fd, s, length, info.size);
|
buffer = s;
|
||||||
vfs::write(fd, new_line, 1, info.size + length);
|
buffer += '\n';
|
||||||
|
|
||||||
|
vfs::write(fd, buffer.c_str(), buffer.size(), info.size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user