Re: Faster StrNCpy
От | Alvaro Herrera |
---|---|
Тема | Re: Faster StrNCpy |
Дата | |
Msg-id | 20060926204937.GA22101@alvh.no-ip.org обсуждение исходный текст |
Ответ на | Re: Faster StrNCpy (Martijn van Oosterhout <kleptog@svana.org>) |
Ответы |
Re: Faster StrNCpy
|
Список | pgsql-hackers |
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
В списке pgsql-hackers по дате отправления: