[openbeos] strlcpy in string.h

  • From: "Andrew Bachmann" <shatty@xxxxxxxxxxxxx>
  • To: "openbeos" <openbeos@xxxxxxxxxxxxx>
  • Date: Mon, 26 Jan 2004 22:19:11 -0800 PST

Hello all,

I got annoyed by watching the syslog_daemon build failing again for the n'th 
time so I went to 
take a look at this strlcpy thing that was used in there.  It turns out that 
strlcpy is actually a really 
good thing, more efficient than strncpy and also more secure.  Looking at it I 
realized that I 
could implement a simple macro to reproduce the functionality of strlcpy:

#define strlcpy(target, source, length) snprintf(target, length, "%s", source)

I figured I would stick this in string.h and go on my happy way, using strlcpy 
with aplomb.  Then 
I noticed, hey! we already have a strlcpy proto in string.h:

extern size_t   strlcpy(char *dest, const char *source, size_t length);

And it so happens that it's correct according to some man pages out there.  
(strlcpy is not posix, at 
least not yet)  I also noticed its friend nearby:

extern size_t   strlcat(char *dest, const char *source, size_t length);

What should we do about these?  Is it okay to comment out the strlcpy proto and 
add the macro?  
It seems that a number of other functions in string.h have been replaced by 
macros.  This will 
enable the syslog_daemon to run on R5, and hopefully encourage more widespread 
use of strlcpy.  
I don't have a macro for strlcat, perhaps we should also do one for that?

Andrew


Other related posts: