svn commit: r186890 - in stable/7: gnu/usr.bin/cc gnu/usr.bin/cc/libiberty gnu/usr.bin/sort include kerberos5 kerberos5/include lib/bind lib/bind/bind lib/libc lib/libc/string lib/libmagic usr.bin/...

Konstantin Belousov kib at FreeBSD.org
Thu Jan 8 01:50:22 PST 2009


Author: kib
Date: Thu Jan  8 09:50:20 2009
New Revision: 186890
URL: http://svn.freebsd.org/changeset/base/186890

Log:
  MFC r185689:
  Order the str*.c files mostly alphabetical.
  
  MFC r185690:
  Import the strndup(3) function.
  
  MFC r185777:
  Add strndup(3) prototype to string.h. Manually change
  #undef HAVE_STRNDUP to #define HAVE_STRNDUP 1 for the configure.h
  files that need it.

Added:
  stable/7/lib/libc/string/strndup.c
     - copied unchanged from r185690, head/lib/libc/string/strndup.c
Modified:
  stable/7/gnu/usr.bin/cc/   (props changed)
  stable/7/gnu/usr.bin/cc/libiberty/config.h
  stable/7/gnu/usr.bin/sort/   (props changed)
  stable/7/gnu/usr.bin/sort/config.h
  stable/7/include/   (props changed)
  stable/7/include/string.h
  stable/7/kerberos5/   (props changed)
  stable/7/kerberos5/include/config.h
  stable/7/lib/bind/   (props changed)
  stable/7/lib/bind/bind/port_after.h
  stable/7/lib/libc/   (props changed)
  stable/7/lib/libc/string/Makefile.inc
  stable/7/lib/libc/string/Symbol.map
  stable/7/lib/libc/string/ffsll.c   (props changed)
  stable/7/lib/libc/string/flsll.c   (props changed)
  stable/7/lib/libc/string/strdup.3
  stable/7/lib/libmagic/   (props changed)
  stable/7/lib/libmagic/config.h
  stable/7/usr.bin/file/   (props changed)
  stable/7/usr.bin/file/config.h

Modified: stable/7/gnu/usr.bin/cc/libiberty/config.h
==============================================================================
--- stable/7/gnu/usr.bin/cc/libiberty/config.h	Thu Jan  8 09:38:18 2009	(r186889)
+++ stable/7/gnu/usr.bin/cc/libiberty/config.h	Thu Jan  8 09:50:20 2009	(r186890)
@@ -235,7 +235,7 @@
 #define HAVE_STRNCASECMP 1
 
 /* Define to 1 if you have the `strndup' function. */
-/* #undef HAVE_STRNDUP */
+#define HAVE_STRNDUP 1
 
 /* Define to 1 if you have the `strrchr' function. */
 #define HAVE_STRRCHR 1

Modified: stable/7/gnu/usr.bin/sort/config.h
==============================================================================
--- stable/7/gnu/usr.bin/sort/config.h	Thu Jan  8 09:38:18 2009	(r186889)
+++ stable/7/gnu/usr.bin/sort/config.h	Thu Jan  8 09:50:20 2009	(r186890)
@@ -759,7 +759,7 @@
 #define HAVE_STRNCASECMP 1
 
 /* Define to 1 if you have the `strndup' function. */
-/* #undef HAVE_STRNDUP */
+#define HAVE_STRNDUP 1
 
 /* Define to 1 if you have the `strpbrk' function. */
 #define HAVE_STRPBRK 1

Modified: stable/7/include/string.h
==============================================================================
--- stable/7/include/string.h	Thu Jan  8 09:38:18 2009	(r186889)
+++ stable/7/include/string.h	Thu Jan  8 09:50:20 2009	(r186890)
@@ -96,6 +96,7 @@ char	*strncat(char * __restrict, const c
 int	 strncmp(const char *, const char *, size_t) __pure;
 char	*strncpy(char * __restrict, const char * __restrict, size_t);
 #if __BSD_VISIBLE
+char	*strndup(const char *, size_t);
 char	*strnstr(const char *, const char *, size_t) __pure;
 #endif
 char	*strpbrk(const char *, const char *) __pure;

Modified: stable/7/kerberos5/include/config.h
==============================================================================
--- stable/7/kerberos5/include/config.h	Thu Jan  8 09:38:18 2009	(r186889)
+++ stable/7/kerberos5/include/config.h	Thu Jan  8 09:50:20 2009	(r186890)
@@ -747,7 +747,7 @@ static /**/const char *const rcsid[] = {
 #define HAVE_STRNCASECMP 1
 
 /* Define if you have the function `strndup'. */
-/* #undef HAVE_STRNDUP */
+#define HAVE_STRNDUP 1
 
 /* Define if you have the function `strnlen'. */
 /* #undef HAVE_STRNLEN */

Modified: stable/7/lib/bind/bind/port_after.h
==============================================================================
--- stable/7/lib/bind/bind/port_after.h	Thu Jan  8 09:38:18 2009	(r186889)
+++ stable/7/lib/bind/bind/port_after.h	Thu Jan  8 09:50:20 2009	(r186890)
@@ -30,7 +30,7 @@
 #undef HAS_IN_ADDR6
 #define HAVE_SOCKADDR_STORAGE 1
 #undef NEED_GETTIMEOFDAY
-#undef HAVE_STRNDUP
+#define HAVE_STRNDUP 1
 #undef USE_FIONBIO_IOCTL
 #undef USE_SYSERROR_LIST
 #undef INNETGR_ARGS

Modified: stable/7/lib/libc/string/Makefile.inc
==============================================================================
--- stable/7/lib/libc/string/Makefile.inc	Thu Jan  8 09:38:18 2009	(r186889)
+++ stable/7/lib/libc/string/Makefile.inc	Thu Jan  8 09:50:20 2009	(r186890)
@@ -9,9 +9,9 @@ CFLAGS+= -I${.CURDIR}/locale
 MISRCS+=bcmp.c bcopy.c bzero.c ffs.c ffsl.c ffsll.c fls.c flsl.c flsll.c \
 	index.c memccpy.c memchr.c memrchr.c memcmp.c \
 	memcpy.c memmem.c memmove.c memset.c rindex.c stpcpy.c strcasecmp.c \
-	strcat.c strchr.c strcmp.c strcoll.c strcpy.c strcspn.c strdup.c \
-	strerror.c strlcat.c strlcpy.c strlen.c strmode.c strncat.c strncmp.c \
-	strncpy.c strcasestr.c strnstr.c \
+	strcat.c strcasestr.c strchr.c strcmp.c strcoll.c strcpy.c strcspn.c \
+	strdup.c strerror.c strlcat.c strlcpy.c strlen.c strmode.c strncat.c \
+	strncmp.c strncpy.c strndup.c strnstr.c \
 	strpbrk.c strrchr.c strsep.c strsignal.c strspn.c strstr.c strtok.c \
 	strxfrm.c swab.c wcscat.c wcschr.c wcscmp.c wcscoll.c wcscpy.c \
 	wcscspn.c wcsdup.c \
@@ -47,6 +47,7 @@ MLINKS+=strcat.3 strncat.3
 MLINKS+=strchr.3 strrchr.3
 MLINKS+=strcmp.3 strncmp.3
 MLINKS+=strcpy.3 stpcpy.3
+MLINKS+=strdup.3 strndup.3
 MLINKS+=strcpy.3 strncpy.3
 MLINKS+=strerror.3 perror.3 strerror.3 sys_errlist.3 strerror.3 sys_nerr.3
 MLINKS+=strerror.3 strerror_r.3

Modified: stable/7/lib/libc/string/Symbol.map
==============================================================================
--- stable/7/lib/libc/string/Symbol.map	Thu Jan  8 09:38:18 2009	(r186889)
+++ stable/7/lib/libc/string/Symbol.map	Thu Jan  8 09:50:20 2009	(r186890)
@@ -81,6 +81,7 @@ FBSD_1.1 {
 	ffsll;
 	flsll;
 	memrchr;
+	strndup;
 };
 
 FBSDprivate_1.0 {

Modified: stable/7/lib/libc/string/strdup.3
==============================================================================
--- stable/7/lib/libc/string/strdup.3	Thu Jan  8 09:38:18 2009	(r186889)
+++ stable/7/lib/libc/string/strdup.3	Thu Jan  8 09:50:20 2009	(r186890)
@@ -28,11 +28,12 @@
 .\"     @(#)strdup.3	8.1 (Berkeley) 6/9/93
 .\" $FreeBSD$
 .\"
-.Dd June 9, 1993
+.Dd Dec 5, 2008
 .Dt STRDUP 3
 .Os
 .Sh NAME
-.Nm strdup
+.Nm strdup ,
+.Nm strndup
 .Nd save a copy of a string
 .Sh LIBRARY
 .Lb libc
@@ -40,6 +41,8 @@
 .In string.h
 .Ft char *
 .Fn strdup "const char *str"
+.Ft char *
+.Fn strndup "const char *str" "size_t len"
 .Sh DESCRIPTION
 The
 .Fn strdup
@@ -56,6 +59,16 @@ If insufficient memory is available, NUL
 .Va errno
 is set to
 .Er ENOMEM .
+.Pp
+The
+.Fn strndup
+function copies at most
+.Fa len
+characters from the string
+.Fa str
+always
+.Dv NUL
+terminating the copied string.
 .Sh SEE ALSO
 .Xr free 3 ,
 .Xr malloc 3
@@ -64,3 +77,7 @@ The
 .Fn strdup
 function first appeared in
 .Bx 4.4 .
+The
+.Fn strndup
+function was added in
+.Fx 8.0 .

Copied: stable/7/lib/libc/string/strndup.c (from r185690, head/lib/libc/string/strndup.c)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/7/lib/libc/string/strndup.c	Thu Jan  8 09:50:20 2009	(r186890, copy of r185690, head/lib/libc/string/strndup.c)
@@ -0,0 +1,53 @@
+/*      $NetBSD: strndup.c,v 1.3 2007/01/14 23:41:24 cbiere Exp $       */
+
+/*
+ * Copyright (c) 1988, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+char *
+strndup(const char *str, size_t n)
+{
+	size_t len;
+	char *copy;
+
+	for (len = 0; len < n && str[len]; len++)
+		continue;
+
+	if ((copy = malloc(len + 1)) == NULL)
+		return (NULL);
+	memcpy(copy, str, len);
+	copy[len] = '\0';
+	return (copy);
+}

Modified: stable/7/lib/libmagic/config.h
==============================================================================
--- stable/7/lib/libmagic/config.h	Thu Jan  8 09:38:18 2009	(r186889)
+++ stable/7/lib/libmagic/config.h	Thu Jan  8 09:50:20 2009	(r186890)
@@ -77,7 +77,7 @@
 #define HAVE_STRING_H 1
 
 /* Define to 1 if you have the `strndup' function. */
-/* #undef HAVE_STRNDUP */
+#define HAVE_STRNDUP 1
 
 /* Define to 1 if you have the `strtof' function. */
 #define HAVE_STRTOF 1

Modified: stable/7/usr.bin/file/config.h
==============================================================================
--- stable/7/usr.bin/file/config.h	Thu Jan  8 09:38:18 2009	(r186889)
+++ stable/7/usr.bin/file/config.h	Thu Jan  8 09:50:20 2009	(r186890)
@@ -77,7 +77,7 @@
 #define HAVE_STRING_H 1
 
 /* Define to 1 if you have the `strndup' function. */
-/* #undef HAVE_STRNDUP */
+#define HAVE_STRNDUP 1
 
 /* Define to 1 if you have the `strtof' function. */
 #define HAVE_STRTOF 1


More information about the svn-src-all mailing list