From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 23 22:20:32 2008 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BDC1C10656AC; Wed, 23 Apr 2008 22:20:32 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id 2E6AE8FC22; Wed, 23 Apr 2008 22:20:31 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from kobe.laptop (adsl23-13.kln.forthnet.gr [77.49.150.13]) (authenticated bits=128) by igloo.linux.gr (8.14.2/8.14.2/Debian-3) with ESMTP id m3NMKF7j022023 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 24 Apr 2008 01:20:21 +0300 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.2/8.14.2) with ESMTP id m3NMKEnc002357; Thu, 24 Apr 2008 01:20:15 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.2/8.14.2/Submit) id m3NMKCuW002356; Thu, 24 Apr 2008 01:20:12 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) From: Giorgos Keramidas To: Hans Petter Selasky References: <293918.47889.qm@web36608.mail.mud.yahoo.com> <20080423124023.54ca505e@mbook-fbsd> <200804231957.49035.hselasky@c2i.net> Date: Thu, 24 Apr 2008 01:20:11 +0300 In-Reply-To: <200804231957.49035.hselasky@c2i.net> (Hans Petter Selasky's message of "Wed, 23 Apr 2008 19:57:47 +0200") Message-ID: <878wz49pt0.fsf@kobe.laptop> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-MailScanner-ID: m3NMKF7j022023 X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-3.908, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.49, BAYES_00 -2.60) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Cc: Simun Mikecin , freebsd-hackers@freebsd.org, Mike Meyer , hackers@freebsd.org Subject: Re: strdup(NULL) supposed to create SIGSEGV? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Apr 2008 22:20:32 -0000 On Wed, 23 Apr 2008 19:57:47 +0200, Hans Petter Selasky = wrote: > 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. Right on the spot, Hans :) You may have to pick a name that doesn't start from "str", though, because the "str*" function names are reserved for future extensions to the standard. ISO/IEC 9899:1999 (E), page 401, =C2=A77.26.11 says: 7.26 Future library directions [...] 7.26.11 String handling 1 Function names that begin with "str", "mem", or "wcs" and a lowercase letter may be added to the declarations in the header. You're quite right about 'not replacing' the standard functions in a lighthearted manner though. The short-term benefits of making a single application "easier to write", are dwarfed by the possibilities for introducing gratuitous incompatibilities for all the _other_ programs running on the same platform, and any other platforms conforming to the "real" standard behavior.