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>
|
template <typename FN>
|
||||||
void xml(FN const &fn) const
|
void xml(FN const &fn) const
|
||||||
{
|
{
|
||||||
try { fn(Xml_node(_buffer.ptr, _buffer.size)); }
|
try {
|
||||||
catch (Xml_node::Invalid_syntax) { fn(Xml_node("<empty/>")); }
|
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>
|
template <typename STRING, typename FN>
|
||||||
void for_each_line(FN const &fn) const
|
void for_each_line(FN const &fn) const
|
||||||
{
|
{
|
||||||
|
if (_buffer.size == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
char const *src = _buffer.ptr;
|
char const *src = _buffer.ptr;
|
||||||
char const *curr_line = src;
|
char const *curr_line = src;
|
||||||
size_t curr_line_len = 0;
|
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
|
* 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>
|
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…
Reference in New Issue