base: 'String' constructor overload for literals

This overload covers the common case for initializing a string from a
literal without employing the 'Output' mechanism. This way, such
strings can by constructed without calling virtual functions, which in
turn makes the 'String' usable for the 'init_rtld' phase of the dynamic
linker.
This commit is contained in:
Norman Feske 2016-10-28 12:12:08 +02:00 committed by Christian Helmuth
parent 23c2c7c5a8
commit 20faa8b84e

View File

@ -545,6 +545,8 @@ class Genode::Cstring
{ }
void print(Output &out) const { out.out_string(_str, _len); }
size_t length() const { return _len; }
};
@ -629,6 +631,17 @@ class Genode::String
_len = output.num_chars() + 1;
}
/**
* Constructor
*
* Overload for the common case of constructing a 'String' from a
* string literal.
*/
String(char const *cstr) : _len(min(Genode::strlen(cstr) + 1, CAPACITY))
{
Genode::strncpy(_buf, cstr, _len);
}
/**
* Copy constructor
*/