mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-31 00:24:51 +00:00
os/vfs.h: handle zero-sized files
The 'File_content' class failed to consider zero-sized files. Fixes #3557
This commit is contained in:
parent
2aa6471608
commit
f85ec313de
@ -498,8 +498,15 @@ class Genode::File_content
|
||||
template <typename FN>
|
||||
void xml(FN const &fn) const
|
||||
{
|
||||
try { fn(Xml_node(_buffer.ptr, _buffer.size)); }
|
||||
catch (Xml_node::Invalid_syntax) { fn(Xml_node("<empty/>")); }
|
||||
try {
|
||||
if (_buffer.size) {
|
||||
fn(Xml_node(_buffer.ptr, _buffer.size));
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Xml_node::Invalid_syntax) { }
|
||||
|
||||
fn(Xml_node("<empty/>"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -510,6 +517,9 @@ class Genode::File_content
|
||||
template <typename STRING, typename FN>
|
||||
void for_each_line(FN const &fn) const
|
||||
{
|
||||
if (_buffer.size == 0)
|
||||
return;
|
||||
|
||||
char const *src = _buffer.ptr;
|
||||
char const *curr_line = src;
|
||||
size_t curr_line_len = 0;
|
||||
@ -538,9 +548,15 @@ class Genode::File_content
|
||||
|
||||
/**
|
||||
* Call functor 'fn' with the data pointer and size in bytes
|
||||
*
|
||||
* If the buffer has a size of zero, 'fn' is not called.
|
||||
*/
|
||||
template <typename FN>
|
||||
void bytes(FN const &fn) const { fn((char const *)_buffer.ptr, _buffer.size); }
|
||||
void bytes(FN const &fn) const
|
||||
{
|
||||
if (_buffer.size)
|
||||
fn((char const *)_buffer.ptr, _buffer.size);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user