Martijn van Oosterhout wrote: > On Tue, Sep 26, 2006 at 04:24:51PM -0400, Tom Lane wrote: > > David Strong points out here > > http://archives.postgresql.org/pgsql-hackers/2006-09/msg02071.php > > that some popular implementations of strncpy(dst,src,n) are quite > > inefficient when strlen(src) is much less than n, because they don't > > optimize the zero-pad step that is required by the standard. > > I think that's why strlcpy was invented, to deal with the issues with > strncpy. > > http://www.gratisoft.us/todd/papers/strlcpy.html > > There's an implementation here (used in glib), though you could > probably find more. > > http://mail.gnome.org/archives/gtk-devel-list/2000-May/msg00029.html
That one would be LGPL (glib's license). Here is OpenBSD's version, linked from that one: ftp://ftp.openbsd.org/pub/OpenBSD/src/lib/libc/string/strlcpy.c You'll notice that it iterates once per char. Between that and the strlen() call in Tom's version, not sure which is the lesser evil. -- Alvaro Herrera http://www.CommandPrompt.com/ PostgreSQL Replication, Consulting, Custom Development, 24x7 support ---------------------------(end of broadcast)--------------------------- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly