The Better String Library is an abstraction of a string data type which is superior to the C library char buffer string type, or C++'s std::string.DON'T FUCKING WHO ARE YOU QUOTING ME
DON'T FUCKING WHO ARE YOU QUOTING MEYou know you're provoking the sage downvote retard, why do it then?
buffer
there should be no cause to use strlcpy at all - it can just check the length of the source literal first, and allocate a buffer of sufficient size.So what's the New Improved Method to replace strlcpy(buffer, "the default value", size_of_buffer);, then?
buffer? buffer : "the default value"
buffer
in this example needs to escape the scope where the strlcpy is done - otherwise I agree totally. Now, strncpy is nasty too, because of the two main flaws:
- no guaranteed NUL at the end
- crazy "fill with NUL" at the end
strncpy(d, s, n)
always writes n characters and pads with zeroes if necessary. However, it doesn't write a terminating NUL, when strlen(s) >= n
. There are some easy fixes to this, though. I don't understand the standard library worship.In this case, it's not worship but rather knowing your shit (or just looking it up) before asking any questions.
There is nothing preventing you rolling your own functions and its trivial to rewrite them.This isn't always true, even for such ``trivial'' functions: bugs hide everywhere, especially when you want optimize some of this stuff (which is usually done because it's very rewarding when string handling appears almost anywhere).