From meem@triplex.East.Sun.COM Wed Nov  1 17:30:25 2006
Received: from sunmail1brm.Central.Sun.COM (sunmail1brm.Central.Sun.COM [129.147.62.17])
	by sac.sfbay.sun.com (8.13.6+Sun/8.13.6) with ESMTP id kA21UOj8001195
	for <psarc-ext@sac.sfbay.Sun.COM>; Wed, 1 Nov 2006 17:30:25 -0800 (PST)
Received: from nwk-avmta-2.sfbay.sun.com (nwk-avmta-2.SFBay.Sun.COM [129.149.247.22])
	by sunmail1brm.Central.Sun.COM (8.11.7p1+Sun/8.11.7/ENSMAIL,v2.2) with ESMTP id kA21UO718390
	for <@sunmail3.sfbay.sun.com:PSARC-EXT@sun.com>; Wed, 1 Nov 2006 18:30:24 -0700 (MST)
Received: from pmxchannel-daemon.nwk-avmta-2.sfbay.sun.com by
 nwk-avmta-2.sfbay.sun.com
 (Sun Java System Messaging Server 6.2-3.04 (built Jul 15 2005))
 id <0J8200C0HXIMCB00@nwk-avmta-2.sfbay.sun.com> for PSARC-EXT@sun.com
 (ORCPT PSARC-EXT@sun.com); Wed, 01 Nov 2006 17:30:22 -0800 (PST)
Received: from triplex.East.Sun.COM ([129.148.174.104])
 by nwk-avmta-2.sfbay.sun.com
 (Sun Java System Messaging Server 6.2-3.04 (built Jul 15 2005))
 with ESMTP id <0J82004T8XILZ660@nwk-avmta-2.sfbay.sun.com> for
 PSARC-EXT@sun.com (ORCPT PSARC-EXT@sun.com); Wed,
 01 Nov 2006 17:30:22 -0800 (PST)
Received: from triplex.East.Sun.COM (localhost [127.0.0.1])
	by triplex.East.Sun.COM (8.13.8+Sun/8.13.8) with ESMTP id kA21UL1i006661; Wed,
 01 Nov 2006 20:30:21 -0500 (EST)
Received: (from meem@localhost)
	by triplex.East.Sun.COM (8.13.8+Sun/8.13.8/Submit) id kA21ULs3006658; Wed,
 01 Nov 2006 20:30:21 -0500 (EST)
Date: Wed, 01 Nov 2006 20:30:20 -0500
From: Peter Memishian <peter.memishian@sun.com>
Subject: PSARC/2006/617 strnlen()
To: PSARC-EXT@sun.com
Cc: rlhamil@smart.net
Message-id: <17737.18988.986535.344067@triplex.East.Sun.COM>
MIME-version: 1.0
X-Mailer: VM 7.17 under 21.4 (patch 18) "Social Property" XEmacs Lucid
Content-type: text/plain; charset=us-ascii
Content-transfer-encoding: 7BIT
X-PMX-Version: 5.2.0.264296
Status: RO
Content-Length: 4271


I am sponsoring the following case for Richard Hamilton.

Patch binding is requested, with a stability classification of
"committed".  The timer is set for Wednesday, November 8th.

*** NOTE: This case has "open" exposure, and will be visible to the    ***
***       OpenSolaris community.  No confidential information, please! ***

Overview
========

  This case proposes to add the well-known strnlen() function to libc,
  which determines the length of a fixed-size string:

	#include <string.h>

  	size_t strnlen(const char *s, size_t n);

  Specifically, the strnlen() functions returns the smaller of `n' or the
  number of bytes in `s', not including the terminating NUL character.
  The strnlen() function will never examine more than `n' bytes of the
  string pointed to by `s'.

Details
=======
   
  The subject of strnlen() came up in a discussion of the libdlpi code
  review on clearview-discuss@opensolaris.org, where it might have been
  handy if a function like strnlen() was available.  Richard Hamilton
  pointed out the concept (and function name) were well-defined in other
  environments, and posted an earlier implementation.  Others, both within
  and outside Sun, provided essential suggestions and assistance.

  The proposed strnlen() function complies with Linux Standards Base 1.2:

    http://refspecs.freestandards.org/LSB_1.2.0/gLSB/baselib-strnlen-3.html

  ... and also with the (identical) version in LSB3.0Preview1.

  The strnlen() function is also under consideration for addition to POSIX:

    http://www.opengroup.org/austin/plato/uploads/40/9756/NAPI_overview.txt

  However, the established #ifdef guards will prevent strnlen() from being
  exposed via <string.h> in standards-conforming environments for now.

  Microsoft also has an interface-compatible implementation of strnlen():

    http://msdn2.microsoft.com/en-us/library/z50ty2zh.aspx

  Microsoft notes that strnlen() does not validate its parameters, i.e. a
  NULL string argument would cause an "access violation".  The same seems
  true of other implementations, which is consistent with the behavior of
  similar functions such as strlen(3C).  Our proposed version leaves the
  behavior of passing a NULL pointer unspecified.

  Platform-optimized implementations are certainly possible (another
  open-source implementation appears to be restructuring to allow that for
  strnlen()), but are beyond the scope of this proposal (and may not be
  desirable anyway from a maintenance perspective).

  Various open source applications use strnlen(); some will auto-configure
  to use a system library provided version if available.  Such applications
  will automatically take advantage of strnlen() once it is available.
  Others can be modified to use it as the need arises.

Manpage Changes
===============

  --- string.3c.old       Wed Nov  1 01:42:38 2006
  +++ string.3c   Wed Nov  1 17:47:08 2006
  @@ -5,8 +5,8 @@
   NAME
        string, strcasecmp, strncasecmp, strcat,  strncat,  strlcat,
        strchr,  strrchr, strcmp, strncmp, strcpy, strncpy, strlcpy,
  -     strcspn, strspn, strdup, strlen,  strpbrk,  strstr,  strtok,
  -     strtok_r - string operations
  +     strcspn, strspn, strdup, strlen,  strnlen, strpbrk,  strstr,
  +     strtok, strtok_r - string operations
  
   SYNOPSIS
        #include <strings.h>
  @@ -47,6 +47,8 @@
  
        size_t strlen(const char *s);
  
  +     size_t strnlen(const char *s, size_t n);
  +
        char *strpbrk(const char *s1, const char *s2);
  
        char *strstr(const char *s1, const char *s2);
  @@ -171,10 +173,15 @@
        set  to  ENOMEM to indicate that the storage space available
        is insufficient.
  
  -  strlen()
  +  strlen(), strnlen()
        The strlen() function returns the number of bytes in s,  not
        including the terminating null character.
  
  +     The strnlen()  function  returns  the  smaller of n  or  the
  +     number  of bytes  in s,  not including the terminating  null
  +     character.  The strnlen() function  never examines more than
  +     n bytes of the string pointed to by s.
  +
     strpbrk()
        The strpbrk()  function  returns  a  pointer  to  the  first
        occurrence  in string s1 of any character from string s2, or

-- 
meem

From meem@triplex.East.Sun.COM Wed Nov  8 10:23:50 2006
Received: from sunmail4.Singapore.Sun.COM (sunmail4.Singapore.Sun.COM [129.158.71.19])
	by sac.sfbay.sun.com (8.13.6+Sun/8.13.6) with ESMTP id kA8INnb5010421
	for <psarc-ext@sac.sfbay.Sun.COM>; Wed, 8 Nov 2006 10:23:50 -0800 (PST)
Received: from nwk-avmta-1.sfbay.sun.com (nwk-avmta-1.SFBay.Sun.COM [129.149.246.28])
	by sunmail4.Singapore.Sun.COM (8.13.4+Sun/8.13.3/ENSMAIL,v2.2) with ESMTP id kA8INhS3028252
	for <@sunmail2.sfbay.sun.com:PSARC-EXT@sun.com>; Thu, 9 Nov 2006 02:23:48 +0800 (SGT)
Received: from pmxchannel-daemon.nwk-avmta-1.sfbay.Sun.COM by
 nwk-avmta-1.sfbay.Sun.COM
 (Sun Java System Messaging Server 6.2 (built Dec  2 2004))
 id <0J8F0092BCFN0W00@nwk-avmta-1.sfbay.Sun.COM> for PSARC-EXT@sun.com
 (ORCPT PSARC-EXT@sun.com); Wed, 08 Nov 2006 10:23:47 -0800 (PST)
Received: from triplex.East.Sun.COM ([129.148.174.104])
 by nwk-avmta-1.sfbay.Sun.COM
 (Sun Java System Messaging Server 6.2 (built Dec  2 2004))
 with ESMTP id <0J8F00MSNCFLZMB0@nwk-avmta-1.sfbay.Sun.COM> for
 PSARC-EXT@sun.com (ORCPT PSARC-EXT@sun.com); Wed,
 08 Nov 2006 10:23:46 -0800 (PST)
Received: from triplex.East.Sun.COM (localhost [127.0.0.1])
	by triplex.East.Sun.COM (8.13.8+Sun/8.13.8) with ESMTP id kA8INjI9103501; Wed,
 08 Nov 2006 13:23:45 -0500 (EST)
Received: (from meem@localhost)
	by triplex.East.Sun.COM (8.13.8+Sun/8.13.8/Submit) id kA8INirV103498; Wed,
 08 Nov 2006 13:23:44 -0500 (EST)
Date: Wed, 08 Nov 2006 13:23:44 -0500
From: Peter Memishian <peter.memishian@sun.com>
Subject: re: PSARC/2006/617 strnlen()
To: PSARC-EXT@sun.com
Cc: rlhamil@smart.net
Message-id: <17746.8368.863894.267863@triplex.East.Sun.COM>
MIME-version: 1.0
X-Mailer: VM 7.17 under 21.4 (patch 18) "Social Property" XEmacs Lucid
Content-type: text/plain; charset=us-ascii
Content-transfer-encoding: 7BIT
X-PMX-Version: 5.2.0.264296
Status: RO
Content-Length: 70


This fast-track was approved during today's PSARC meeting.

-- 
meem

