Date: Wed, 23 Apr 2008 19:57:47 +0200 From: Hans Petter Selasky <hselasky@c2i.net> To: freebsd-hackers@freebsd.org Cc: Simun Mikecin <numisemis@yahoo.com>, Mike Meyer <mwm@mired.org>, hackers@freebsd.org Subject: Re: strdup(NULL) supposed to create SIGSEGV? Message-ID: <200804231957.49035.hselasky@c2i.net> In-Reply-To: <20080423124023.54ca505e@mbook-fbsd> References: <293918.47889.qm@web36608.mail.mud.yahoo.com> <20080423124023.54ca505e@mbook-fbsd>
next in thread | previous in thread | raw e-mail | index | archive | help
Hi, I recently had to tell someone that "strncpy" does not always zero terminate the destination string. Surprised by what I was telling they immediately wanted to change the way the function worked. When a function is defined by an ISO standard you are not supposed to change the definition. Instead I pointed the person at "strlcpy". Else you will have serious trouble when code is ported to a new platform. http://www.gratisoft.us/todd/papers/strlcpy.html The name "strdup" is very appealing, but it has already been taken and defined. You have to give your variant a different name and convince everyone that your function is good and solves a problem so that it deserves to be in the C-library. Then you simply run a script on your code: sed -s "s/ strdup[(]/ strsdup(/g" *.[ch] --HPS :-)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200804231957.49035.hselasky>