Date: Thu, 4 Dec 2008 11:27:01 -0800 From: "Peter Wemm" <peter@wemm.org> To: d@delphij.net Cc: Florian Smeets <flo@kasimir.com>, freebsd-arch@freebsd.org Subject: Re: Adding strndup(3) to libc viable/useful? Message-ID: <e7db6d980812041127t6109ebbcr8a68822bdd91cc92@mail.gmail.com> In-Reply-To: <49382502.1040403@delphij.net> References: <49381DD4.2000506@kasimir.com> <49382502.1040403@delphij.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Dec 4, 2008 at 10:44 AM, Xin LI <delphij@delphij.net> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi, Florian, > > Florian Smeets wrote: >> Hi, >> >> first of all i hope arch is the correct place to discuss this. >> >> While porting an application to FreeBSD i found that FreeBSDs libc does >> not have strndup. NetBSD added this about 2 years ago. A port of this to >> FreeBSD was very easy. >> >> There are 13 ports in the ports tree right now that patch in strndup via >> a patch in the files/ dir, well actually 12 bring there own version of >> strndup and one replaces it with a call to malloc/strncpy. >> >> Would it make sense to add this to our libc? A patch which does this is >> available here at http://webmail.solomo.de/~flo/strndup.patch >> >> I don't know if there is such a thing as minimum number of ports to >> require a function so that it can be added to the base system... >> >> Any feedback appreciated. > > I think whether or not to add it really depends on how popular it is :) > We included strdup() because it is a very common extension. > > Your patch looks fine but perhaps it would be a good idea to explicitly > mention that this is not a commonly implemented GNU extension > (inheritedly, this could reduce portability). glibc has had this for a long time and the trend for this function seems to be gaining ground. I think solaris is the last remaining major holdout. str*() namespace belongs to the implementation (us). There are lots of places where I've seen strndup() implemented as compatability shims. Everything from Asterisk to Varnish. I wouldn't be suprised if there were ports that had this knowledge hard coded. FWIW, there are a bunch of other useful utility str*() and mem*() functions that glibc has that we do not. I've run into the lack of fmemopen() in the past. I found an implementation from rwatson. -- Peter Wemm - peter@wemm.org; peter@FreeBSD.org; peter@yahoo-inc.com; KI6FJV "All of this is for nothing if we don't go to the stars" - JMS/B5 "If Java had true garbage collection, most programs would delete themselves upon execution." -- Robert Sewell
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?e7db6d980812041127t6109ebbcr8a68822bdd91cc92>