LWN.net Logo

The ups and downs of strlcpy()

The ups and downs of strlcpy()

Posted Jul 20, 2012 21:08 UTC (Fri) by smurf (subscriber, #17840)
In reply to: The ups and downs of strlcpy() by cmccabe
Parent article: The ups and downs of strlcpy()

Not to mention the fact that you don't need two passes through your string.

Look, we all know that there's no magic bullet in programming. Different tools do different parts of the job well, others … not so much.

Fortunately, there are two quite simple workarounds for not having strlcpy in libc:

* add -lbsd to your GCC command line.

* #define strlcpy(d,n,s) snprintf((d),(n),"%s",(s))

Which of these is more efficient is left as an exercise to the reader. :-P


(Log in to post comments)

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds