1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-12 09:58:36 +00:00

Add wcpcpy(3) and wcpncpy(3).

This commit is contained in:
David Schultz 2009-03-04 06:01:27 +00:00
parent dc4b1d1662
commit 09efd0ec6a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=189361
6 changed files with 110 additions and 3 deletions

View File

@ -213,6 +213,8 @@ int wcwidth(wchar_t);
#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE
size_t mbsnrtowcs(wchar_t * __restrict, const char ** __restrict, size_t,
size_t, mbstate_t * __restrict);
wchar_t *wcpcpy(wchar_t __restrict *, const wchar_t * __restrict);
wchar_t *wcpncpy(wchar_t __restrict *, const wchar_t * __restrict, size_t);
wchar_t *wcsdup(const wchar_t *) __malloc_like;
int wcscasecmp(const wchar_t *, const wchar_t *);
int wcsncasecmp(const wchar_t *, const wchar_t *, size_t n);

View File

@ -14,7 +14,7 @@ MISRCS+=bcmp.c bcopy.c bzero.c ffs.c ffsl.c ffsll.c fls.c flsl.c flsll.c \
strdup.c strerror.c strlcat.c strlcpy.c strlen.c strmode.c strncat.c \
strncmp.c strncpy.c strndup.c strnlen.c strnstr.c \
strpbrk.c strrchr.c strsep.c strsignal.c strspn.c strstr.c strtok.c \
strxfrm.c swab.c wcscasecmp.c wcscat.c \
strxfrm.c swab.c wcpcpy.c wcpncpy.c wcscasecmp.c wcscat.c \
wcschr.c wcscmp.c wcscoll.c wcscpy.c wcscspn.c wcsdup.c \
wcslcat.c wcslcpy.c wcslen.c wcsncasecmp.c wcsncat.c wcsncmp.c \
wcsncpy.c wcsnlen.c wcspbrk.c \
@ -61,7 +61,9 @@ MLINKS+=strlen.3 strnlen.3
MLINKS+=strstr.3 strcasestr.3 \
strstr.3 strnstr.3
MLINKS+=strtok.3 strtok_r.3
MLINKS+=wmemchr.3 wcscasecmp.3 \
MLINKS+=wmemchr.3 wcpcpy.3 \
wmemchr.3 wcpncpy.3 \
wmemchr.3 wcscasecmp.3 \
wmemchr.3 wcscat.3 \
wmemchr.3 wcschr.3 \
wmemchr.3 wcscmp.3 \

View File

@ -84,6 +84,8 @@ FBSD_1.1 {
stpncpy;
strndup;
strnlen;
wcpcpy;
wcpncpy;
wcscasecmp;
wcsncasecmp;
wcsnlen;

46
lib/libc/string/wcpcpy.c Normal file
View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 1999
* David E. O'Brien
* 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.
* 3. 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.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)strcpy.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <wchar.h>
wchar_t *
wcpcpy(wchar_t * __restrict to, const wchar_t * __restrict from)
{
for (; (*to = *from); ++from, ++to);
return(to);
}

45
lib/libc/string/wcpncpy.c Normal file
View File

@ -0,0 +1,45 @@
/*-
* Copyright (c) 2009 David Schultz <das@FreeBSD.org>
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 <wchar.h>
wchar_t *
wcpncpy(wchar_t * __restrict dst, const wchar_t * __restrict src, size_t n)
{
for (; n--; dst++, src++) {
if (!(*dst = *src)) {
wchar_t *ret = dst;
while (n--)
*++dst = L'\0';
return (ret);
}
}
return (dst);
}

View File

@ -35,7 +35,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd February 28, 2009
.Dd March 4, 2009
.Dt WMEMCHR 3
.Os
.Sh NAME
@ -44,6 +44,8 @@
.Nm wmemcpy ,
.Nm wmemmove ,
.Nm wmemset ,
.Nm wcpcpy ,
.Nm wcpncpy ,
.Nm wcscasecmp ,
.Nm wcscat ,
.Nm wcschr ,
@ -78,6 +80,10 @@
.Fn wmemmove "wchar_t *s1" "const wchar_t *s2" "size_t n"
.Ft wchar_t *
.Fn wmemset "wchar_t *s" "wchar_t c" "size_t n"
.Ft wchar_t *
.Fn wcpcpy "wchar_t *s1" "wchar_t *s2"
.Ft wchar_t *
.Fn wcpncpy "wchar_t *s1" "wchar_t *s2" "size_t n"
.Ft int
.Fn wcscasecmp "const wchar_t *s1" "const wchar_t *s2"
.Ft wchar_t *
@ -128,6 +134,8 @@ counterpart, such as
.Xr memcpy 3 ,
.Xr memmove 3 ,
.Xr memset 3 ,
.Xr stpcpy 3 ,
.Xr stpncpy 3 ,
.Xr strcasecmp 3 ,
.Xr strcat 3 ,
.Xr strchr 3 ,
@ -150,6 +158,8 @@ counterpart, such as
These functions conform to
.St -isoC-99 ,
with the exception of
.Fn wcpcpy ,
.Fn wcpncpy ,
.Fn wcscasecmp ,
.Fn wcsdup ,
.Fn wcsncasecmp ,