From owner-freebsd-arch@FreeBSD.ORG Thu Dec 4 19:27:03 2008 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C7AFB106564A for ; Thu, 4 Dec 2008 19:27:03 +0000 (UTC) (envelope-from peter@wemm.org) Received: from mail-qy0-f18.google.com (mail-qy0-f18.google.com [209.85.221.18]) by mx1.freebsd.org (Postfix) with ESMTP id 77FEE8FC20 for ; Thu, 4 Dec 2008 19:27:03 +0000 (UTC) (envelope-from peter@wemm.org) Received: by qyk11 with SMTP id 11so5275982qyk.19 for ; Thu, 04 Dec 2008 11:27:02 -0800 (PST) Received: by 10.142.48.3 with SMTP id v3mr6049693wfv.0.1228418821714; Thu, 04 Dec 2008 11:27:01 -0800 (PST) Received: by 10.142.255.21 with HTTP; Thu, 4 Dec 2008 11:27:01 -0800 (PST) Message-ID: Date: Thu, 4 Dec 2008 11:27:01 -0800 From: "Peter Wemm" To: d@delphij.net In-Reply-To: <49382502.1040403@delphij.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <49381DD4.2000506@kasimir.com> <49382502.1040403@delphij.net> Cc: Florian Smeets , freebsd-arch@freebsd.org Subject: Re: Adding strndup(3) to libc viable/useful? X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Dec 2008 19:27:03 -0000 On Thu, Dec 4, 2008 at 10:44 AM, Xin LI 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