mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-07 19:34:56 +00:00
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:
parent
23c2c7c5a8
commit
20faa8b84e
@ -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
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user