Re: Faster StrNCpy - Mailing list pgsql-hackers

From Martijn van Oosterhout
Subject Re: Faster StrNCpy
Date
Msg-id 20060926204018.GF19913@svana.org
Whole thread Raw
In response to Faster StrNCpy  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Faster StrNCpy  (Alvaro Herrera <alvherre@commandprompt.com>)
Re: Faster StrNCpy  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
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

Do you really think it's worth making a macro rather than just a normal
function?

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Faster StrNCpy
Next
From: Alvaro Herrera
Date:
Subject: Re: Faster StrNCpy