On Tue, 4 Sep 2012 14:32:12 -0500, Kirk Wolf wrote: > >(BTW - strncpy() also zeros bytes after the terminator, if necessary) > >For more information, see: http://www.courtesan.com/todd/papers/strlcpy.html >under "Common Misconceptions" > There's no discernible date of publication of that paper save for some interior references to events ca. 1996. And strlcpy() and strlcat() appear not to have made it into POSIX.
That paper mentions performance consequences of strncpy()'s zeroing bytes after the terminator when the target buffer may be much larger than the source. It does not mention that str(l|n)cat() suffers a similar performance impact when concatenating multiple strings into a single buffer because the content previously concatenated must be re-scanned to find the null terminator. Of course, the programmer could bypass this by using the length returned by strlcat()/strlcpy() as an offset in the target. But this reintroduces the hazard of programmer arithmetic errors. If strlcat() were inline rather than a library function, an optimizing compiler could take care of much of this by remembering the length of the previous call. You, Lynn, and John G. are correct to distrust null-terminated strings. -- gil ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN