Skip to content


Decent C String APIs

meanwhile, back in C-land…

strlcpy() – a replacement for strcpy() and strncpy(), with some very nice performance figures.

I usually use snprintf() to do this, but even that has differint semantics between platforms which needs workarounds. Plus the perf numbers regarding strlcpy() are nice. Plus it’s BSD-licensed. (Found via Linux Weekly News.)

In passing, it’s worth noting that strncpy() imposes a pretty hefty performance hit (4x – 10x in tests there), due to a wierd specified behaviour; it NULs out unused parts of the buffer! ouch.

See also MS’ strsafe APIs. However, the code for that is available only on Windows, which makes it pretty much useless for most C code I’d be writing, and they note ‘performance hits’.

Comments closed