[openbeos] Re: strlcpy in string.h
- From: "Axel Dörfler" <axeld@xxxxxxxxxxxxxxxx>
- To: openbeos@xxxxxxxxxxxxx
- Date: Tue, 27 Jan 2004 13:24:56 +0100 CET
Hi Andrew,
"Andrew Bachmann" <shatty@xxxxxxxxxxxxx> wrote:
> 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
Oh, sorry, I fixed it for now.
> 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?
Hm, I think we shouldn't remove the prototypes; that would change the
whole build and all of a sudden, the kernel would use snprintf() all
over the place.
I think we should rather do what I did for with the syslog_daemon - add
it manually to the build.
I'll try to fix these bugs earlier when I do them the next time :)
Bye,
Axel.
- References:
- [openbeos] strlcpy in string.h
- From: Andrew Bachmann
Other related posts:
- » [openbeos] strlcpy in string.h
- » [openbeos] Re: strlcpy in string.h
- » [openbeos] Re: strlcpy in string.h
- [openbeos] strlcpy in string.h
- From: Andrew Bachmann