1 |
the_paya 09/01/29 06:52:45 |
2 |
|
3 |
Added: freebsd-lib-7.1-strndup_bport.patch |
4 |
Log: |
5 |
Backported strndup into libc from upstream, revbump. |
6 |
(Portage version: 2.2_rc23/cvs/FreeBSD i386) |
7 |
|
8 |
Revision Changes Path |
9 |
1.1 sys-freebsd/freebsd-lib/files/freebsd-lib-7.1-strndup_bport.patch |
10 |
|
11 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-freebsd/freebsd-lib/files/freebsd-lib-7.1-strndup_bport.patch?rev=1.1&view=markup |
12 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-freebsd/freebsd-lib/files/freebsd-lib-7.1-strndup_bport.patch?rev=1.1&content-type=text/plain |
13 |
|
14 |
Index: freebsd-lib-7.1-strndup_bport.patch |
15 |
=================================================================== |
16 |
Backport of strndup from -CURRENT. |
17 |
|
18 |
Fixes bugs 249731 and 256741. |
19 |
|
20 |
According to the manpage this will appear on 8.0, |
21 |
so try to keep it around. |
22 |
--- lib.orig/libc/string/Makefile.inc |
23 |
+++ lib/libc/string/Makefile.inc |
24 |
@@ -9,9 +9,9 @@ |
25 |
MISRCS+=bcmp.c bcopy.c bzero.c ffs.c ffsl.c ffsll.c fls.c flsl.c flsll.c \ |
26 |
index.c memccpy.c memchr.c memrchr.c memcmp.c \ |
27 |
memcpy.c memmem.c memmove.c memset.c rindex.c stpcpy.c strcasecmp.c \ |
28 |
- strcat.c strchr.c strcmp.c strcoll.c strcpy.c strcspn.c strdup.c \ |
29 |
- strerror.c strlcat.c strlcpy.c strlen.c strmode.c strncat.c strncmp.c \ |
30 |
- strncpy.c strcasestr.c strnstr.c \ |
31 |
+ strcat.c strcasestr.c strchr.c strcmp.c strcoll.c strcpy.c strcspn.c \ |
32 |
+ strdup.c strerror.c strlcat.c strlcpy.c strlen.c strmode.c strncat.c \ |
33 |
+ strncmp.c strncpy.c strndup.c strnstr.c \ |
34 |
strpbrk.c strrchr.c strsep.c strsignal.c strspn.c strstr.c strtok.c \ |
35 |
strxfrm.c swab.c wcscat.c wcschr.c wcscmp.c wcscoll.c wcscpy.c \ |
36 |
wcscspn.c wcsdup.c \ |
37 |
@@ -47,6 +47,7 @@ |
38 |
MLINKS+=strchr.3 strrchr.3 |
39 |
MLINKS+=strcmp.3 strncmp.3 |
40 |
MLINKS+=strcpy.3 stpcpy.3 |
41 |
+MLINKS+=strdup.3 strndup.3 |
42 |
MLINKS+=strcpy.3 strncpy.3 |
43 |
MLINKS+=strerror.3 perror.3 strerror.3 sys_errlist.3 strerror.3 sys_nerr.3 |
44 |
MLINKS+=strerror.3 strerror_r.3 |
45 |
--- lib.orig/libc/string/Symbol.map |
46 |
+++ lib/libc/string/Symbol.map |
47 |
@@ -81,6 +81,7 @@ |
48 |
ffsll; |
49 |
flsll; |
50 |
memrchr; |
51 |
+ strndup; |
52 |
}; |
53 |
|
54 |
FBSDprivate_1.0 { |
55 |
--- lib.orig/libc/string/strdup.3 |
56 |
+++ lib/libc/string/strdup.3 |
57 |
@@ -32,7 +32,8 @@ |
58 |
.Dt STRDUP 3 |
59 |
.Os |
60 |
.Sh NAME |
61 |
-.Nm strdup |
62 |
+.Nm strdup , |
63 |
+.Nm strndup |
64 |
.Nd save a copy of a string |
65 |
.Sh LIBRARY |
66 |
.Lb libc |
67 |
@@ -40,6 +41,8 @@ |
68 |
.In string.h |
69 |
.Ft char * |
70 |
.Fn strdup "const char *str" |
71 |
+.Ft char * |
72 |
+.Fn strndup "const char *str" "size_t len" |
73 |
.Sh DESCRIPTION |
74 |
The |
75 |
.Fn strdup |
76 |
@@ -56,6 +59,16 @@ |
77 |
.Va errno |
78 |
is set to |
79 |
.Er ENOMEM . |
80 |
+.Pp |
81 |
+The |
82 |
+.Fn strndup |
83 |
+function copies at most |
84 |
+.Fa len |
85 |
+characters from the string |
86 |
+.Fa str |
87 |
+always |
88 |
+.Dv NUL |
89 |
+terminating the copied string. |
90 |
.Sh SEE ALSO |
91 |
.Xr free 3 , |
92 |
.Xr malloc 3 |
93 |
@@ -64,3 +77,7 @@ |
94 |
.Fn strdup |
95 |
function first appeared in |
96 |
.Bx 4.4 . |
97 |
+The |
98 |
+.Fn strndup |
99 |
+function was added in |
100 |
+.Fx 8.0 . |
101 |
--- lib.orig/libc/string/strndup.c |
102 |
+++ lib/libc/string/strndup.c |
103 |
@@ -0,0 +1,53 @@ |
104 |
+/* $NetBSD: strndup.c,v 1.3 2007/01/14 23:41:24 cbiere Exp $ */ |
105 |
+ |
106 |
+/* |
107 |
+ * Copyright (c) 1988, 1993 |
108 |
+ * The Regents of the University of California. All rights reserved. |
109 |
+ * |
110 |
+ * Redistribution and use in source and binary forms, with or without |
111 |
+ * modification, are permitted provided that the following conditions |
112 |
+ * are met: |
113 |
+ * 1. Redistributions of source code must retain the above copyright |
114 |
+ * notice, this list of conditions and the following disclaimer. |
115 |
+ * 2. Redistributions in binary form must reproduce the above copyright |
116 |
+ * notice, this list of conditions and the following disclaimer in the |
117 |
+ * documentation and/or other materials provided with the distribution. |
118 |
+ * 4. Neither the name of the University nor the names of its contributors |
119 |
+ * may be used to endorse or promote products derived from this software |
120 |
+ * without specific prior written permission. |
121 |
+ * |
122 |
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
123 |
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
124 |
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
125 |
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
126 |
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
127 |
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
128 |
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
129 |
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
130 |
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
131 |
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
132 |
+ * SUCH DAMAGE. |
133 |
+ */ |
134 |
+ |
135 |
+#include <sys/cdefs.h> |
136 |
+__FBSDID("$FreeBSD: src/lib/libc/string/strndup.c,v 1.1.2.1 2009/01/08 09:50:20 kib Exp $"); |
137 |
+ |
138 |
+#include <stddef.h> |
139 |
+#include <stdlib.h> |
140 |
+#include <string.h> |
141 |
+ |
142 |
+char * |
143 |
+strndup(const char *str, size_t n) |
144 |
+{ |
145 |
+ size_t len; |
146 |
+ char *copy; |
147 |
+ |
148 |
+ for (len = 0; len < n && str[len]; len++) |
149 |
+ continue; |
150 |
+ |
151 |
+ if ((copy = malloc(len + 1)) == NULL) |
152 |
+ return (NULL); |
153 |
+ memcpy(copy, str, len); |
154 |
+ copy[len] = '\0'; |
155 |
+ return (copy); |
156 |
+} |
157 |
--- include.orig/string.h |
158 |
+++ include/string.h |
159 |
@@ -96,6 +96,7 @@ |
160 |
int strncmp(const char *, const char *, size_t) __pure; |
161 |
char *strncpy(char * __restrict, const char * __restrict, size_t); |
162 |
#if __BSD_VISIBLE |
163 |
+char *strndup(const char *, size_t); |
164 |
char *strnstr(const char *, const char *, size_t) __pure; |
165 |
#endif |
166 |
char *strpbrk(const char *, const char *) __pure; |