[Asterisk-Dev] [RFC] strncpy -> ast_copy_string

Kevin P. Fleming kpfleming at digium.com
Mon May 2 07:09:21 MST 2005


Tzafrir Cohen wrote:

> There is one popular strncpy alternative that doesn't seem to do this
> padding: strlcpy
> 
>   http://www.courtesan.com/todd/papers/strlcpy.html

That paper covers exactly the issue we are discussing here, thanks for 
the reference.

strlcpy has one feature that we don't use in Asterisk; it still has a 
return value, and it returns the length of the string it wanted to 
create, so you can determine whether truncation occurred or not. Since 
very few places in Asterisk bother to even check the return value, this 
too is wasted CPU cycles.

At this point, it's pretty clear to me that the semantics of 
ast_copy_string() are exactly what we want, and the only remaining issue 
is whether there should be optimized versions produced. I'm going to 
start the conversion process from strncpy() to ast_copy_string() in CVS 
HEAD, and we'll see where things lead from there.



More information about the asterisk-dev mailing list