diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libc/string/Makefile.inc | 6 | ||||
-rw-r--r-- | src/lib/libc/string/wcsdup.3 | 86 | ||||
-rw-r--r-- | src/lib/libc/string/wcsdup.c | 31 |
3 files changed, 120 insertions, 3 deletions
diff --git a/src/lib/libc/string/Makefile.inc b/src/lib/libc/string/Makefile.inc index 44e011e3c1..bb285e135e 100644 --- a/src/lib/libc/string/Makefile.inc +++ b/src/lib/libc/string/Makefile.inc | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: Makefile.inc,v 1.25 2011/05/28 15:16:46 espie Exp $ | 1 | # $OpenBSD: Makefile.inc,v 1.26 2011/07/04 04:37:34 nicm Exp $ |
2 | 2 | ||
3 | # string sources | 3 | # string sources |
4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/string ${LIBCSRCDIR}/string | 4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/string ${LIBCSRCDIR}/string |
@@ -9,7 +9,7 @@ SRCS+= bm.c memccpy.c memrchr.c strcasecmp.c strcasestr.c strcoll.c strdup.c \ | |||
9 | wcscat.c wcschr.c wcscmp.c wcscpy.c wcscspn.c wcslcat.c wcslcpy.c \ | 9 | wcscat.c wcschr.c wcscmp.c wcscpy.c wcscspn.c wcslcat.c wcslcpy.c \ |
10 | wcslen.c wcsncat.c wcsncmp.c wcsncpy.c wcspbrk.c wcsrchr.c wcsspn.c \ | 10 | wcslen.c wcsncat.c wcsncmp.c wcsncpy.c wcspbrk.c wcsrchr.c wcsspn.c \ |
11 | wcsstr.c wcstok.c wcswcs.c wcswidth.c wmemchr.c wmemcmp.c wmemcpy.c \ | 11 | wcsstr.c wcstok.c wcswcs.c wcswidth.c wmemchr.c wmemcmp.c wmemcpy.c \ |
12 | wmemmove.c wmemset.c \ | 12 | wmemmove.c wmemset.c wcsdup.c \ |
13 | timingsafe_bcmp.c wcscasecmp.c | 13 | timingsafe_bcmp.c wcscasecmp.c |
14 | 14 | ||
15 | # machine-dependent net sources | 15 | # machine-dependent net sources |
@@ -144,7 +144,7 @@ MAN+= bm.3 bcmp.3 bcopy.3 bstring.3 bzero.3 ffs.3 memccpy.3 memchr.3 \ | |||
144 | strchr.3 strcmp.3 strcoll.3 strcpy.3 strcspn.3 strerror.3 \ | 144 | strchr.3 strcmp.3 strcoll.3 strcpy.3 strcspn.3 strerror.3 \ |
145 | string.3 strlen.3 strmode.3 strdup.3 strpbrk.3 strrchr.3 strsep.3 \ | 145 | string.3 strlen.3 strmode.3 strdup.3 strpbrk.3 strrchr.3 strsep.3 \ |
146 | strsignal.3 strspn.3 strstr.3 strtok.3 strxfrm.3 swab.3 strlcpy.3 \ | 146 | strsignal.3 strspn.3 strstr.3 strtok.3 strxfrm.3 swab.3 strlcpy.3 \ |
147 | wcstok.3 wmemchr.3 wcswidth.3 | 147 | wcstok.3 wmemchr.3 wcswidth.3 wcsdup.3 |
148 | 148 | ||
149 | MLINKS+=bm.3 bm_comp.3 bm.3 bm_exec.3 bm.3 bm_free.3 | 149 | MLINKS+=bm.3 bm_comp.3 bm.3 bm_exec.3 bm.3 bm_free.3 |
150 | MLINKS+=memchr.3 memrchr.3 | 150 | MLINKS+=memchr.3 memrchr.3 |
diff --git a/src/lib/libc/string/wcsdup.3 b/src/lib/libc/string/wcsdup.3 new file mode 100644 index 0000000000..37f82181eb --- /dev/null +++ b/src/lib/libc/string/wcsdup.3 | |||
@@ -0,0 +1,86 @@ | |||
1 | .\" $OpenBSD: wcsdup.3,v 1.1 2011/07/04 04:37:34 nicm Exp $ | ||
2 | .\" $NetBSD: wcsdup.3,v 1.3 2010/12/16 17:42:28 wiz Exp $ | ||
3 | .\" | ||
4 | .\" Copyright (c) 1990, 1991, 1993 | ||
5 | .\" The Regents of the University of California. All rights reserved. | ||
6 | .\" | ||
7 | .\" Redistribution and use in source and binary forms, with or without | ||
8 | .\" modification, are permitted provided that the following conditions | ||
9 | .\" are met: | ||
10 | .\" 1. Redistributions of source code must retain the above copyright | ||
11 | .\" notice, this list of conditions and the following disclaimer. | ||
12 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
13 | .\" notice, this list of conditions and the following disclaimer in the | ||
14 | .\" documentation and/or other materials provided with the distribution. | ||
15 | .\" 3. Neither the name of the University nor the names of its contributors | ||
16 | .\" may be used to endorse or promote products derived from this software | ||
17 | .\" without specific prior written permission. | ||
18 | .\" | ||
19 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
20 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
21 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
22 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
23 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
24 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
25 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
26 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
27 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
28 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
29 | .\" SUCH DAMAGE. | ||
30 | .\" | ||
31 | .\" from: @(#)strdup.3 8.1 (Berkeley) 6/9/93 | ||
32 | .\" | ||
33 | .Dd $Mdocdate: July 4 2011 $ | ||
34 | .Dt WCSDUP 3 | ||
35 | .Os | ||
36 | .Sh NAME | ||
37 | .Nm wcsdup | ||
38 | .Nd save a copy of a string | ||
39 | .Sh SYNOPSIS | ||
40 | .In wchar.h | ||
41 | .Ft wchar_t * | ||
42 | .Fn wcsdup "const wchar_t *str" | ||
43 | .Sh DESCRIPTION | ||
44 | The | ||
45 | .Fn wcsdup | ||
46 | function | ||
47 | allocates sufficient memory for a copy | ||
48 | of the wide-character string | ||
49 | .Fa str , | ||
50 | does the copy, and returns a pointer to it. | ||
51 | The pointer may subsequently be used as an | ||
52 | argument to the function | ||
53 | .Xr free 3 . | ||
54 | .Pp | ||
55 | If insufficient memory is available, | ||
56 | .Dv NULL | ||
57 | is returned. | ||
58 | .Sh EXAMPLES | ||
59 | The following will point | ||
60 | .Va p | ||
61 | to an allocated area of memory containing the nul-terminated string | ||
62 | .Qq foobar : | ||
63 | .Bd -literal -offset indent | ||
64 | wchar_t *p; | ||
65 | |||
66 | if (p = wcsdup(L"foobar"), p == NULL) { | ||
67 | fprintf(stderr, "Out of memory.\en"); | ||
68 | exit(1); | ||
69 | } | ||
70 | .Ed | ||
71 | .Sh ERRORS | ||
72 | The | ||
73 | .Fn wcsdup | ||
74 | function may fail and set the external variable | ||
75 | .Va errno | ||
76 | for any of the errors specified for the library function | ||
77 | .Xr malloc 3 . | ||
78 | .Sh SEE ALSO | ||
79 | .Xr free 3 , | ||
80 | .Xr malloc 3 , | ||
81 | .Xr strdup 3 | ||
82 | .Sh HISTORY | ||
83 | The | ||
84 | .Fn wcsdup | ||
85 | function first appeared in | ||
86 | .Ox 5.0 . | ||
diff --git a/src/lib/libc/string/wcsdup.c b/src/lib/libc/string/wcsdup.c new file mode 100644 index 0000000000..57a328a8c2 --- /dev/null +++ b/src/lib/libc/string/wcsdup.c | |||
@@ -0,0 +1,31 @@ | |||
1 | /* $OpenBSD: wcsdup.c,v 1.1 2011/07/04 04:37:34 nicm Exp $ */ | ||
2 | /* $NetBSD: wcsdup.c,v 1.3 2008/05/26 13:17:48 haad Exp $ */ | ||
3 | |||
4 | /* | ||
5 | * Copyright (C) 2006 Aleksey Cheusov | ||
6 | * | ||
7 | * This material is provided "as is", with absolutely no warranty expressed | ||
8 | * or implied. Any use is at your own risk. | ||
9 | * | ||
10 | * Permission to use or copy this software for any purpose is hereby granted | ||
11 | * without fee. Permission to modify the code and to distribute modified | ||
12 | * code is also granted without any restrictions. | ||
13 | */ | ||
14 | |||
15 | #include <stdlib.h> | ||
16 | #include <wchar.h> | ||
17 | |||
18 | wchar_t * | ||
19 | wcsdup(const wchar_t *str) | ||
20 | { | ||
21 | wchar_t *copy; | ||
22 | size_t len; | ||
23 | |||
24 | len = wcslen(str) + 1; | ||
25 | copy = malloc(len * sizeof (wchar_t)); | ||
26 | |||
27 | if (!copy) | ||
28 | return (NULL); | ||
29 | |||
30 | return (wmemcpy(copy, str, len)); | ||
31 | } | ||