diff options
Diffstat (limited to 'lib/libc/string')
127 files changed, 459 insertions, 646 deletions
diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc index 1df3d40e329f..5d4a9a6e3eed 100644 --- a/lib/libc/string/Makefile.inc +++ b/lib/libc/string/Makefile.inc @@ -1,7 +1,7 @@ -# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 -# $FreeBSD$ - -.PATH: ${LIBC_SRCTOP}/${LIBC_ARCH}/string ${LIBC_SRCTOP}/string +.if ${MK_MACHDEP_OPTIMIZATIONS} != "no" +.PATH: ${LIBC_SRCTOP}/${LIBC_ARCH}/string +.endif +.PATH: ${LIBC_SRCTOP}/string .PATH: ${SRCTOP}/sys/libkern CFLAGS+= -I${LIBC_SRCTOP}/locale @@ -11,12 +11,13 @@ MISRCS+=bcmp.c bcopy.c bzero.c explicit_bzero.c \ ffs.c ffsl.c ffsll.c fls.c flsl.c flsll.c \ memccpy.c memchr.c memrchr.c memcmp.c \ memcpy.c memmem.c memmove.c mempcpy.c memset.c memset_s.c \ + memset_explicit.c \ stpcpy.c stpncpy.c strcasecmp.c \ strcat.c strcasestr.c strchr.c strchrnul.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 strnlen.c strnstr.c \ strpbrk.c strrchr.c strsep.c strsignal.c strspn.c strstr.c strtok.c \ - strxfrm.c swab.c \ + strverscmp.c strxfrm.c swab.c \ timingsafe_bcmp.c \ timingsafe_memcmp.c \ wcpcpy.c wcpncpy.c wcscasecmp.c wcscat.c \ @@ -39,14 +40,16 @@ CFLAGS.memchr.c+= -fno-sanitize=address .endif +.if ${MK_MACHDEP_OPTIMIZATIONS} != "no" # machine-dependent string sources .sinclude "${LIBC_SRCTOP}/${LIBC_ARCH}/string/Makefile.inc" +.endif MAN+= bcmp.3 bcopy.3 bstring.3 bzero.3 ffs.3 index.3 memccpy.3 memchr.3 \ memcmp.3 memcpy.3 memmem.3 memmove.3 memset.3 strcasecmp.3 strcat.3 \ strchr.3 strcmp.3 strcoll.3 strcpy.3 strdup.3 strerror.3 \ string.3 strlcpy.3 strlen.3 strmode.3 strpbrk.3 strsep.3 \ - strspn.3 strstr.3 strtok.3 strxfrm.3 swab.3 \ + strspn.3 strstr.3 strtok.3 strverscmp.3 strxfrm.3 swab.3 \ timingsafe_bcmp.3 \ wcscoll.3 wcstok.3 \ wcswidth.3 wcsxfrm.3 wmemchr.3 @@ -60,7 +63,8 @@ MLINKS+=ffs.3 ffsl.3 \ MLINKS+=index.3 rindex.3 MLINKS+=memchr.3 memrchr.3 MLINKS+=memcpy.3 mempcpy.3 -MLINKS+=memset.3 memset_s.3 +MLINKS+=memset.3 memset_s.3 \ + memset.3 memset_explicit.3 MLINKS+=strcasecmp.3 strncasecmp.3 \ strcasecmp.3 strcasecmp_l.3 \ strcasecmp.3 strncasecmp_l.3 diff --git a/lib/libc/string/Symbol.map b/lib/libc/string/Symbol.map index ec45d7fd7ddb..6b2c41124adf 100644 --- a/lib/libc/string/Symbol.map +++ b/lib/libc/string/Symbol.map @@ -1,7 +1,3 @@ -/* - * $FreeBSD$ - */ - FBSD_1.0 { bcmp; bcopy; @@ -116,9 +112,14 @@ FBSD_1.6 { FBSD_1.7 { mempcpy; + strverscmp; wmempcpy; }; +FBSD_1.8 { + memset_explicit; +}; + FBSDprivate_1.0 { __strtok_r; }; diff --git a/lib/libc/string/bcmp.3 b/lib/libc/string/bcmp.3 index e2d4063a1654..954e10bfdeab 100644 --- a/lib/libc/string/bcmp.3 +++ b/lib/libc/string/bcmp.3 @@ -27,9 +27,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)bcmp.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD$ -.\" .Dd August 15, 2016 .Dt BCMP 3 .Os diff --git a/lib/libc/string/bcmp.c b/lib/libc/string/bcmp.c index 96cd49039eee..cf1e487d391e 100644 --- a/lib/libc/string/bcmp.c +++ b/lib/libc/string/bcmp.c @@ -29,12 +29,6 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bcmp.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <strings.h> /* @@ -51,7 +45,7 @@ bcmp(const void *b1, const void *b2, size_t length) p2 = (char *)b2; do if (*p1++ != *p2++) - break; + return (1); while (--length); - return (length); + return (0); } diff --git a/lib/libc/string/bcopy.3 b/lib/libc/string/bcopy.3 index ac480f8ca966..230ca2eea89a 100644 --- a/lib/libc/string/bcopy.3 +++ b/lib/libc/string/bcopy.3 @@ -28,9 +28,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)bcopy.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD$ -.\" .Dd August 24, 2015 .Dt BCOPY 3 .Os diff --git a/lib/libc/string/bcopy.c b/lib/libc/string/bcopy.c index 84715d0432e3..20f7bc60b76a 100644 --- a/lib/libc/string/bcopy.c +++ b/lib/libc/string/bcopy.c @@ -32,12 +32,6 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bcopy.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/types.h> typedef intptr_t word; /* "word" used for optimal copy speed */ @@ -53,6 +47,9 @@ typedef intptr_t word; /* "word" used for optimal copy speed */ #if defined(MEMCOPY) || defined(MEMMOVE) #include <string.h> +#undef memcpy /* _FORTIFY_SOURCE */ +#undef memmove /* _FORTIFY_SOURCE */ + void * #ifdef MEMCOPY memcpy @@ -63,6 +60,8 @@ memmove #else #include <strings.h> +#undef bcopy /* _FORTIFY_SOURCE */ + void bcopy(const void *src0, void *dst0, size_t length) #endif diff --git a/lib/libc/string/bstring.3 b/lib/libc/string/bstring.3 index b8ed0908c88a..dd89af44fc4a 100644 --- a/lib/libc/string/bstring.3 +++ b/lib/libc/string/bstring.3 @@ -27,10 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)bstring.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD$ -.\" -.Dd June 4, 1993 +.Dd December 5, 2023 .Dt BSTRING 3 .Os .Sh NAME @@ -59,7 +56,12 @@ .Ft int .Fn memcmp "const void *b1" "const void *b2" "size_t len" .Ft void * -.Fn memccpy "void *dst" "const void *src" "int c" "size_t len" +.Fo memccpy +.Fa "void * restrict dst" +.Fa "const void * restrict src" +.Fa "int c" +.Fa "size_t len" +.Fc .Ft void * .Fn memcpy "void *dst" "const void *src" "size_t len" .Ft void * diff --git a/lib/libc/string/bzero.3 b/lib/libc/string/bzero.3 index 130a652fe849..2c791c497d8c 100644 --- a/lib/libc/string/bzero.3 +++ b/lib/libc/string/bzero.3 @@ -28,9 +28,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)bzero.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD$ -.\" .Dd August 24, 2015 .Dt BZERO 3 .Os diff --git a/lib/libc/string/bzero.c b/lib/libc/string/bzero.c index 201bd64f808d..7bc2b3a7008a 100644 --- a/lib/libc/string/bzero.c +++ b/lib/libc/string/bzero.c @@ -1,5 +1,2 @@ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #define BZERO #include "memset.c" diff --git a/lib/libc/string/ffs.3 b/lib/libc/string/ffs.3 index 8d2601d6efc7..2a5adb01c737 100644 --- a/lib/libc/string/ffs.3 +++ b/lib/libc/string/ffs.3 @@ -27,9 +27,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)ffs.3 8.2 (Berkeley) 4/19/94 -.\" $FreeBSD$ -.\" .Dd October 17, 2015 .Dt FFS 3 .Os diff --git a/lib/libc/string/ffs.c b/lib/libc/string/ffs.c index 738ef90ce091..0e137b6bb97e 100644 --- a/lib/libc/string/ffs.c +++ b/lib/libc/string/ffs.c @@ -3,6 +3,10 @@ * * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. + * Copyright (c) 2023 The FreeBSD Foundation + * + * Portions of this software were developed by Robert Clausecker + * <fuz@FreeBSD.org> under sponsorship from the FreeBSD Foundation. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,12 +33,6 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)ffs.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <strings.h> /* @@ -43,11 +41,5 @@ __FBSDID("$FreeBSD$"); int ffs(int mask) { - int bit; - - if (mask == 0) - return(0); - for (bit = 1; !(mask & 1); bit++) - mask = (unsigned int)mask >> 1; - return (bit); + return (mask == 0 ? 0 : __builtin_ctz(mask) + 1); } diff --git a/lib/libc/string/ffsl.c b/lib/libc/string/ffsl.c index dbd894b9655b..c3a87a902526 100644 --- a/lib/libc/string/ffsl.c +++ b/lib/libc/string/ffsl.c @@ -3,6 +3,10 @@ * * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. + * Copyright (c) 2023 The FreeBSD Foundation + * + * Portions of this software were developed by Robert Clausecker + * <fuz@FreeBSD.org> under sponsorship from the FreeBSD Foundation. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,9 +33,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <strings.h> /* @@ -40,11 +41,5 @@ __FBSDID("$FreeBSD$"); int ffsl(long mask) { - int bit; - - if (mask == 0) - return (0); - for (bit = 1; !(mask & 1); bit++) - mask = (unsigned long)mask >> 1; - return (bit); + return (mask == 0 ? 0 : __builtin_ctzl(mask) + 1); } diff --git a/lib/libc/string/ffsll.c b/lib/libc/string/ffsll.c index 91886de2f127..5c7abc1f7a23 100644 --- a/lib/libc/string/ffsll.c +++ b/lib/libc/string/ffsll.c @@ -3,6 +3,10 @@ * * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. + * Copyright (c) 2023 The FreeBSD Foundation + * + * Portions of this software were developed by Robert Clausecker + * <fuz@FreeBSD.org> under sponsorship from the FreeBSD Foundation. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,9 +33,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <strings.h> /* @@ -40,11 +41,5 @@ __FBSDID("$FreeBSD$"); int ffsll(long long mask) { - int bit; - - if (mask == 0) - return (0); - for (bit = 1; !(mask & 1); bit++) - mask = (unsigned long long)mask >> 1; - return (bit); + return (mask == 0 ? 0 : __builtin_ctzll(mask) + 1); } diff --git a/lib/libc/string/fls.c b/lib/libc/string/fls.c index d9edc41f9599..ac5fb7738722 100644 --- a/lib/libc/string/fls.c +++ b/lib/libc/string/fls.c @@ -3,6 +3,10 @@ * * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. + * Copyright (c) 2023 The FreeBSD Foundation + * + * Portions of this software were developed by Robert Clausecker + * <fuz@FreeBSD.org> under sponsorship from the FreeBSD Foundation. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,9 +33,7 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - +#include <limits.h> #include <strings.h> /* @@ -40,11 +42,5 @@ __FBSDID("$FreeBSD$"); int fls(int mask) { - int bit; - - if (mask == 0) - return (0); - for (bit = 1; mask != 1; bit++) - mask = (unsigned int)mask >> 1; - return (bit); + return (mask == 0 ? 0 : CHAR_BIT * sizeof(mask) - __builtin_clz(mask)); } diff --git a/lib/libc/string/flsl.c b/lib/libc/string/flsl.c index 60370cf7d832..d88c8dfcdc63 100644 --- a/lib/libc/string/flsl.c +++ b/lib/libc/string/flsl.c @@ -3,6 +3,11 @@ * * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. + * Copyright (c) 2023 The FreeBSD Foundation + + * + * Portions of this software were developed by Robert Clausecker + * <fuz@FreeBSD.org> under sponsorship from the FreeBSD Foundation. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,9 +34,7 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - +#include <limits.h> #include <strings.h> /* @@ -40,11 +43,5 @@ __FBSDID("$FreeBSD$"); int flsl(long mask) { - int bit; - - if (mask == 0) - return (0); - for (bit = 1; mask != 1; bit++) - mask = (unsigned long)mask >> 1; - return (bit); + return (mask == 0 ? 0 : CHAR_BIT * sizeof(mask) - __builtin_clzl(mask)); } diff --git a/lib/libc/string/flsll.c b/lib/libc/string/flsll.c index 275aaa0e2e15..635ebacddf18 100644 --- a/lib/libc/string/flsll.c +++ b/lib/libc/string/flsll.c @@ -3,6 +3,10 @@ * * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. + * Copyright (c) 2023 The FreeBSD Foundation + * + * Portions of this software were developed by Robert Clausecker + * <fuz@FreeBSD.org> under sponsorship from the FreeBSD Foundation. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,9 +33,7 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - +#include <limits.h> #include <strings.h> /* @@ -40,11 +42,5 @@ __FBSDID("$FreeBSD$"); int flsll(long long mask) { - int bit; - - if (mask == 0) - return (0); - for (bit = 1; mask != 1; bit++) - mask = (unsigned long long)mask >> 1; - return (bit); + return (mask == 0 ? 0 : CHAR_BIT * sizeof(mask) - __builtin_clzll(mask)); } diff --git a/lib/libc/string/index.3 b/lib/libc/string/index.3 index dcce40031983..efab4e6d42ee 100644 --- a/lib/libc/string/index.3 +++ b/lib/libc/string/index.3 @@ -27,9 +27,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)index.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD$ -.\" .Dd March 20, 2011 .Dt INDEX 3 .Os diff --git a/lib/libc/string/memccpy.3 b/lib/libc/string/memccpy.3 index 5bf323115746..0d35a68fce67 100644 --- a/lib/libc/string/memccpy.3 +++ b/lib/libc/string/memccpy.3 @@ -25,10 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)memccpy.3 8.1 (Berkeley) 6/9/93 -.\" $FreeBSD$ -.\" -.Dd June 9, 1993 +.Dd December 5, 2023 .Dt MEMCCPY 3 .Os .Sh NAME @@ -39,7 +36,12 @@ .Sh SYNOPSIS .In string.h .Ft void * -.Fn memccpy "void *dst" "const void *src" "int c" "size_t len" +.Fo memccpy +.Fa "void * restrict dst" +.Fa "const void * restrict src" +.Fa "int c" +.Fa "size_t len" +.Fc .Sh DESCRIPTION The .Fn memccpy @@ -62,13 +64,33 @@ is returned. Otherwise, .Fa len bytes are copied, and a NULL pointer is returned. +If +.Fa src +and +.Fa dst +overlap, behavior is undefined. .Sh SEE ALSO .Xr bcopy 3 , .Xr memcpy 3 , .Xr memmove 3 , .Xr strcpy 3 +.Sh STANDARDS +The +.Fn memccpy +function conforms to +.St -p1003.1-2004 +and +.St -isoC-2023 . .Sh HISTORY The .Fn memccpy function first appeared in -.Bx 4.4 . +.Bx 4.4 +and was first specified in the +.St -svid1 . +The +.Ft restrict +keyword was added to the prototype in +.Fx 5.0.0 +in accordance with the updated specification of +.St -p1003.1-2004 . diff --git a/lib/libc/string/memccpy.c b/lib/libc/string/memccpy.c index e4c9d0e17edd..d6a446503eb6 100644 --- a/lib/libc/string/memccpy.c +++ b/lib/libc/string/memccpy.c @@ -29,16 +29,10 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)memccpy.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <string.h> void * -memccpy(void *t, const void *f, int c, size_t n) +memccpy(void * restrict t, const void * restrict f, int c, size_t n) { if (n) { diff --git a/lib/libc/string/memchr.3 b/lib/libc/string/memchr.3 index de571ca66e96..c50e932d3382 100644 --- a/lib/libc/string/memchr.3 +++ b/lib/libc/string/memchr.3 @@ -29,15 +29,12 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)memchr.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD$ -.\" .Dd April 9, 2008 .Dt MEMCHR 3 .Os .Sh NAME .Nm memchr -.Nd locate byte in byte string +.Nd locate byte in memory object .Sh LIBRARY .Lb libc .Sh SYNOPSIS @@ -54,8 +51,11 @@ locates the first occurrence of .Fa c (converted to an .Vt "unsigned char" ) -in string -.Fa b . +in object +.Fa b , +limited to at most +.Fa len +characters. .Pp The .Fn memrchr @@ -63,16 +63,19 @@ function behaves like .Fn memchr , except that it locates the last occurrence of .Fa c -in string -.Fa b . +in object +.Fa b , +limited to the first +.Fa len +characters. .Sh RETURN VALUES The .Fn memchr and .Fn memrchr -functions -return a pointer to the byte located, -or NULL if no such byte exists within +functions return a pointer to the byte located, or +.Dv NULL +if no such byte exists within .Fa len bytes. .Sh SEE ALSO diff --git a/lib/libc/string/memchr.c b/lib/libc/string/memchr.c index 4b5d6f6a4c8a..367eac5108c1 100644 --- a/lib/libc/string/memchr.c +++ b/lib/libc/string/memchr.c @@ -22,9 +22,6 @@ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <limits.h> #include <stdint.h> #include <string.h> diff --git a/lib/libc/string/memcmp.3 b/lib/libc/string/memcmp.3 index 245e2abe1d71..8f4980d61c05 100644 --- a/lib/libc/string/memcmp.3 +++ b/lib/libc/string/memcmp.3 @@ -29,15 +29,12 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)memcmp.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD$ -.\" -.Dd August 15, 2016 +.Dd November 20, 2024 .Dt MEMCMP 3 .Os .Sh NAME .Nm memcmp -.Nd compare byte string +.Nd compare bytes in memory .Sh LIBRARY .Lb libc .Sh SYNOPSIS @@ -48,27 +45,25 @@ The .Fn memcmp function -compares byte string +compares byte object .Fa b1 -against byte string +against byte object .Fa b2 . -Both strings are assumed to be +Both objects are assumed to be .Fa len bytes long. .Sh RETURN VALUES The .Fn memcmp -function -returns zero if the two strings are identical, -otherwise returns the difference between the first two differing bytes -(treated as -.Vt "unsigned char" -values, so that -.Sq Li \e200 -is greater than -.Sq Li \&\e0 , -for example). -Zero-length strings are always identical. +function returns zero if the two objects are identical. +Zero-length objects are considered identical. +The +.Fn memcmp +function returns a negative value if the first differing byte has a lower +value in +.Fa b1 +and a positive value if the first differing byte has a higher value in +.Fa b1 . .Sh SEE ALSO .Xr bcmp 3 , .Xr strcasecmp 3 , @@ -83,3 +78,14 @@ The function conforms to .St -isoC . +.Sh CAVEATS +If the objects differ, the C library +.Fn memcmp +implementation returns the difference between the first two differing bytes +.Po treated as +.Vt "unsigned char" +values +.Pc . +This behavior is not specified by +.St -isoC , +is not portable, and may not occur in light of compiler optimizations. diff --git a/lib/libc/string/memcmp.c b/lib/libc/string/memcmp.c index c8d5d92985e2..1117e0565290 100644 --- a/lib/libc/string/memcmp.c +++ b/lib/libc/string/memcmp.c @@ -32,12 +32,6 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)memcmp.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <string.h> /* diff --git a/lib/libc/string/memcpy.3 b/lib/libc/string/memcpy.3 index 66a91592d90e..c1cf93af1cdc 100644 --- a/lib/libc/string/memcpy.3 +++ b/lib/libc/string/memcpy.3 @@ -29,10 +29,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)memcpy.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD$ -.\" -.Dd July 14, 2021 +.Dd November 18, 2023 .Dt MEMCPY 3 .Os .Sh NAME @@ -78,7 +75,7 @@ function returns a pointer to the byte after the last written byte. .Xr memccpy 3 , .Xr memmove 3 , .Xr strcpy 3 , -.Xr wmemcpy 3 +.Xr wmemcpy 3 , .Xr wmempcpy 3 .Sh STANDARDS The @@ -86,3 +83,14 @@ The function conforms to .St -isoC . +.Sh HISTORY +The +.Fn memcpy +function first appeared in +.At V +and was reimplemented for +.Bx 4.3 Tahoe . +The +.Fn mempcpy +function first appeared in +.Fx 13.1 . diff --git a/lib/libc/string/memcpy.c b/lib/libc/string/memcpy.c index ed03856e54b4..ee1150473aa9 100644 --- a/lib/libc/string/memcpy.c +++ b/lib/libc/string/memcpy.c @@ -1,5 +1,2 @@ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #define MEMCOPY #include "bcopy.c" diff --git a/lib/libc/string/memmem.3 b/lib/libc/string/memmem.3 index a2a7c2ece623..e301a0bd1e0f 100644 --- a/lib/libc/string/memmem.3 +++ b/lib/libc/string/memmem.3 @@ -24,9 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD$ -.\" -.Dd March 17, 2017 +.Dd June 29, 2023 .Dt MEMMEM 3 .Os .Sh NAME @@ -69,9 +67,10 @@ is returned. .Xr memchr 3 , .Xr strchr 3 , .Xr strstr 3 -.Sh CONFORMING TO +.Sh STANDARDS .Fn memmem -is a GNU extension. +conforms to +.St -p1003.1-2024 . .Sh HISTORY The .Fn memmem diff --git a/lib/libc/string/memmem.c b/lib/libc/string/memmem.c index be52763e2652..4a244b5964ce 100644 --- a/lib/libc/string/memmem.c +++ b/lib/libc/string/memmem.c @@ -22,9 +22,6 @@ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <stdint.h> #include <string.h> diff --git a/lib/libc/string/memmove.3 b/lib/libc/string/memmove.3 index 8d1c33cd9d4e..4fd190610388 100644 --- a/lib/libc/string/memmove.3 +++ b/lib/libc/string/memmove.3 @@ -29,9 +29,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)memmove.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD$ -.\" .Dd June 4, 1993 .Dt MEMMOVE 3 .Os diff --git a/lib/libc/string/memmove.c b/lib/libc/string/memmove.c index 05cf75a2ce6a..e9bb2c2ed14c 100644 --- a/lib/libc/string/memmove.c +++ b/lib/libc/string/memmove.c @@ -1,5 +1,2 @@ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #define MEMMOVE #include "bcopy.c" diff --git a/lib/libc/string/mempcpy.c b/lib/libc/string/mempcpy.c index 520f1839f981..4ea0af87aef1 100644 --- a/lib/libc/string/mempcpy.c +++ b/lib/libc/string/mempcpy.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2021 The FreeBSD Foundation * @@ -28,13 +28,12 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <string.h> +#include <ssp/ssp.h> void * -mempcpy(void *__restrict dst, const void *__restrict src, size_t len) +(mempcpy)(void *__restrict dst, const void *__restrict src, + size_t len) { return ((char *)memcpy(dst, src, len) + len); } diff --git a/lib/libc/string/memrchr.c b/lib/libc/string/memrchr.c index f477bc356491..bd27ebc620e5 100644 --- a/lib/libc/string/memrchr.c +++ b/lib/libc/string/memrchr.c @@ -14,8 +14,6 @@ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * $FreeBSD$ */ #include <string.h> diff --git a/lib/libc/string/memset.3 b/lib/libc/string/memset.3 index 87635e2a8ac3..f6ab9dacb516 100644 --- a/lib/libc/string/memset.3 +++ b/lib/libc/string/memset.3 @@ -29,10 +29,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)memset.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD$ -.\" -.Dd August 19, 2018 +.Dd October 24, 2024 .Dt MEMSET 3 .Os .Sh NAME @@ -44,6 +41,8 @@ .In string.h .Ft void * .Fn memset "void *dest" "int c" "size_t len" +.Ft void * +.Fn memset_explicit "void *dest" "int c" "size_t len" .Fd #define __STDC_WANT_LIB_EXT1__ 1 .Ft errno_t .Fn memset_s "void *dest" "rsize_t destsz" "int c" "rsize_t len" @@ -71,6 +70,13 @@ The behaviour is also undefined if is an invalid pointer. .Pp The +.Fn memset_explicit +function behaves the same as +.Fn memset, but will not be removed by a compiler's dead store +optimization pass, making it useful for clearing sensitive memory +such as a password. +.Pp +The .Fn memset_s function behaves the same as .Fn memset @@ -111,7 +117,9 @@ before .Sh RETURN VALUES The .Fn memset -function returns its first argument. +and +.Fn memset_explicit +functions return their first argument. The .Fn memset_s function returns zero on success, non-zero on error. @@ -131,3 +139,6 @@ conforms to conforms to .St -isoC-2011 K.3.7.4.1. +.Fn memset_explicit +conforms to +.St -isoC-2023 . diff --git a/lib/libc/string/memset.c b/lib/libc/string/memset.c index e2d4027eea0c..811def0fc9b4 100644 --- a/lib/libc/string/memset.c +++ b/lib/libc/string/memset.c @@ -32,12 +32,6 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)memset.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/types.h> #include <limits.h> @@ -48,6 +42,8 @@ __FBSDID("$FreeBSD$"); #ifdef BZERO #include <strings.h> +#undef bzero /* _FORTIFY_SOURCE */ + #define RETURN return #define VAL 0 #define WIDEVAL 0 @@ -57,6 +53,8 @@ bzero(void *dst0, size_t length) #else #include <string.h> +#undef memset /* _FORTIFY_SOURCE */ + #define RETURN return (dst0) #define VAL c0 #define WIDEVAL c diff --git a/lib/libc/string/memset_explicit.c b/lib/libc/string/memset_explicit.c new file mode 100644 index 000000000000..b2b9a79c40c8 --- /dev/null +++ b/lib/libc/string/memset_explicit.c @@ -0,0 +1,27 @@ +/*- + * SPDF-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Robert Clausecker <fuz@FreeBSD.org> + */ + +#include <string.h> +#include <ssp/ssp.h> + +__attribute__((weak)) void __memset_explicit_hook(void *, int, size_t); + +__attribute__((weak)) void +__memset_explicit_hook(void *buf, int ch, size_t len) +{ + (void)buf; + (void)ch; + (void)len; +} + +void * +__ssp_real(memset_explicit)(void *buf, int ch, size_t len) +{ + memset(buf, ch, len); + __memset_explicit_hook(buf, ch, len); + + return (buf); +} diff --git a/lib/libc/string/memset_s.c b/lib/libc/string/memset_s.c index 7dcef678ca00..d6da7be8385d 100644 --- a/lib/libc/string/memset_s.c +++ b/lib/libc/string/memset_s.c @@ -23,9 +23,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <errno.h> #include <stddef.h> #include <stdint.h> diff --git a/lib/libc/string/stpcpy.c b/lib/libc/string/stpcpy.c index f31cce131777..4521e0877e07 100644 --- a/lib/libc/string/stpcpy.c +++ b/lib/libc/string/stpcpy.c @@ -31,14 +31,10 @@ * 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 <string.h> +#undef stpcpy /* _FORTIFY_SOURCE */ + char * stpcpy(char * __restrict to, const char * __restrict from) { diff --git a/lib/libc/string/stpncpy.c b/lib/libc/string/stpncpy.c index d8267cc812c7..d3a1dddb4a65 100644 --- a/lib/libc/string/stpncpy.c +++ b/lib/libc/string/stpncpy.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2009 David Schultz <das@FreeBSD.org> * All rights reserved. @@ -26,11 +26,10 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <string.h> +#undef stpncpy /* _FORTIFY_SOURCE */ + char * stpncpy(char * __restrict dst, const char * __restrict src, size_t n) { diff --git a/lib/libc/string/strcasecmp.3 b/lib/libc/string/strcasecmp.3 index 4a13cc41d934..7297ec328724 100644 --- a/lib/libc/string/strcasecmp.3 +++ b/lib/libc/string/strcasecmp.3 @@ -27,9 +27,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)strcasecmp.3 8.1 (Berkeley) 6/9/93 -.\" $FreeBSD$ -.\" .Dd May 29, 2014 .Dt STRCASECMP 3 .Os diff --git a/lib/libc/string/strcasecmp.c b/lib/libc/string/strcasecmp.c index efe36f8c012d..69c6d0aa4492 100644 --- a/lib/libc/string/strcasecmp.c +++ b/lib/libc/string/strcasecmp.c @@ -34,12 +34,6 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <strings.h> #include <ctype.h> #include "xlocale_private.h" diff --git a/lib/libc/string/strcasestr.c b/lib/libc/string/strcasestr.c index be6c55df2f5f..c1be973f01f4 100644 --- a/lib/libc/string/strcasestr.c +++ b/lib/libc/string/strcasestr.c @@ -37,9 +37,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <ctype.h> #include <string.h> #include "xlocale_private.h" diff --git a/lib/libc/string/strcat.3 b/lib/libc/string/strcat.3 index 500611eb2154..a8365b8fbdf8 100644 --- a/lib/libc/string/strcat.3 +++ b/lib/libc/string/strcat.3 @@ -29,9 +29,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)strcat.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD$ -.\" .Dd April 3, 2022 .Dt STRCAT 3 .Os diff --git a/lib/libc/string/strcat.c b/lib/libc/string/strcat.c index adaad598ec22..1c13c519b563 100644 --- a/lib/libc/string/strcat.c +++ b/lib/libc/string/strcat.c @@ -29,14 +29,10 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strcat.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <string.h> +#undef strcat /* _FORTIFY_SOURCE */ + char * strcat(char * __restrict s, const char * __restrict append) { diff --git a/lib/libc/string/strchr.3 b/lib/libc/string/strchr.3 index a39ea3e79d71..45179a0001fc 100644 --- a/lib/libc/string/strchr.3 +++ b/lib/libc/string/strchr.3 @@ -29,9 +29,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)strchr.3 8.2 (Berkeley) 4/19/94 -.\" $FreeBSD$ -.\" .Dd February 13, 2013 .Dt STRCHR 3 .Os diff --git a/lib/libc/string/strchr.c b/lib/libc/string/strchr.c index 4a20ea658252..8f6f947e9983 100644 --- a/lib/libc/string/strchr.c +++ b/lib/libc/string/strchr.c @@ -22,9 +22,6 @@ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <string.h> char *__strchrnul(const char *, int); diff --git a/lib/libc/string/strchrnul.c b/lib/libc/string/strchrnul.c index e1fb83886042..3a42c0e7c4c5 100644 --- a/lib/libc/string/strchrnul.c +++ b/lib/libc/string/strchrnul.c @@ -22,9 +22,6 @@ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <limits.h> #include <stdint.h> #include <string.h> diff --git a/lib/libc/string/strcmp.3 b/lib/libc/string/strcmp.3 index df5d67253032..6f39d8d95dd4 100644 --- a/lib/libc/string/strcmp.3 +++ b/lib/libc/string/strcmp.3 @@ -29,9 +29,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)strcmp.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD$ -.\" .Dd April 3, 2022 .Dt STRCMP 3 .Os diff --git a/lib/libc/string/strcmp.c b/lib/libc/string/strcmp.c index 63cb4468415b..216efd318906 100644 --- a/lib/libc/string/strcmp.c +++ b/lib/libc/string/strcmp.c @@ -32,12 +32,6 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strcmp.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <string.h> /* diff --git a/lib/libc/string/strcoll.3 b/lib/libc/string/strcoll.3 index d53a23d11b2f..863bc3a43d4e 100644 --- a/lib/libc/string/strcoll.3 +++ b/lib/libc/string/strcoll.3 @@ -29,9 +29,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)strcoll.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD$ -.\" .Dd June 4, 1993 .Dt STRCOLL 3 .Os diff --git a/lib/libc/string/strcoll.c b/lib/libc/string/strcoll.c index c16c09bb0826..77566f0c7cd7 100644 --- a/lib/libc/string/strcoll.c +++ b/lib/libc/string/strcoll.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright 2010 Nexenta Systems, Inc. All rights reserved. * Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua> @@ -33,9 +33,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <stdlib.h> #include <string.h> #include <errno.h> diff --git a/lib/libc/string/strcpy.3 b/lib/libc/string/strcpy.3 index ce586f95e5dc..ed32d78826eb 100644 --- a/lib/libc/string/strcpy.3 +++ b/lib/libc/string/strcpy.3 @@ -29,9 +29,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)strcpy.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD$ -.\" .Dd June 6, 2018 .Dt STRCPY 3 .Os diff --git a/lib/libc/string/strcpy.c b/lib/libc/string/strcpy.c index f58cbd9784a2..432bcc0e9d62 100644 --- a/lib/libc/string/strcpy.c +++ b/lib/libc/string/strcpy.c @@ -29,12 +29,6 @@ * 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 <string.h> #ifdef WEAK_STRCPY diff --git a/lib/libc/string/strcspn.c b/lib/libc/string/strcspn.c index 6e07c8c920d2..88bf68ff0733 100644 --- a/lib/libc/string/strcspn.c +++ b/lib/libc/string/strcspn.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG> * All rights reserved. @@ -26,9 +26,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/types.h> #include <limits.h> #include <string.h> diff --git a/lib/libc/string/strdup.3 b/lib/libc/string/strdup.3 index 881dcdb6a9e7..576fa122b8d6 100644 --- a/lib/libc/string/strdup.3 +++ b/lib/libc/string/strdup.3 @@ -25,9 +25,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)strdup.3 8.1 (Berkeley) 6/9/93 -.\" $FreeBSD$ -.\" .Dd May 5, 2020 .Dt STRDUP 3 .Os diff --git a/lib/libc/string/strdup.c b/lib/libc/string/strdup.c index 45ed95c2ea9d..2d595e53eb6b 100644 --- a/lib/libc/string/strdup.c +++ b/lib/libc/string/strdup.c @@ -29,12 +29,6 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strdup.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <stddef.h> #include <stdlib.h> #include <string.h> diff --git a/lib/libc/string/strerror.3 b/lib/libc/string/strerror.3 index c877ceb309b5..fa72dcff627b 100644 --- a/lib/libc/string/strerror.3 +++ b/lib/libc/string/strerror.3 @@ -29,9 +29,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)strerror.3 8.1 (Berkeley) 6/9/93 -.\" $FreeBSD$ -.\" .Dd December 17, 2020 .Dt STRERROR 3 .Os diff --git a/lib/libc/string/strerror.c b/lib/libc/string/strerror.c index bb685e4f7dc9..922bb0284497 100644 --- a/lib/libc/string/strerror.c +++ b/lib/libc/string/strerror.c @@ -29,12 +29,6 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strerror.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #if defined(NLS) #include <nl_types.h> #endif @@ -44,6 +38,8 @@ __FBSDID("$FreeBSD$"); #include <string.h> #include <stdio.h> +#include <ssp/ssp.h> + #include "errlst.h" #include "../locale/xlocale_private.h" #include "libc_private.h" @@ -80,8 +76,8 @@ errstr(int num, const char *uprefix, char *buf, size_t len) strlcat(buf, t, len); } -static int -strerror_rl(int errnum, char *strerrbuf, size_t buflen, locale_t locale) +int +__strerror_rl(int errnum, char *strerrbuf, size_t buflen, locale_t locale) { int retval = 0; #if defined(NLS) @@ -120,9 +116,9 @@ strerror_rl(int errnum, char *strerrbuf, size_t buflen, locale_t locale) } int -strerror_r(int errnum, char *strerrbuf, size_t buflen) +__ssp_real(strerror_r)(int errnum, char *strerrbuf, size_t buflen) { - return (strerror_rl(errnum, strerrbuf, buflen, __get_locale())); + return (__strerror_rl(errnum, strerrbuf, buflen, __get_locale())); } char * @@ -130,7 +126,7 @@ strerror_l(int num, locale_t locale) { static _Thread_local char ebuf[NL_TEXTMAX]; - if (strerror_rl(num, ebuf, sizeof(ebuf), locale) != 0) + if (__strerror_rl(num, ebuf, sizeof(ebuf), locale) != 0) errno = EINVAL; return (ebuf); } @@ -140,7 +136,7 @@ strerror(int num) { static char ebuf[NL_TEXTMAX]; - if (strerror_rl(num, ebuf, sizeof(ebuf), __get_locale()) != 0) + if (__strerror_rl(num, ebuf, sizeof(ebuf), __get_locale()) != 0) errno = EINVAL; return (ebuf); } diff --git a/lib/libc/string/string.3 b/lib/libc/string/string.3 index e9ef152bb8ee..3ffea6ce0369 100644 --- a/lib/libc/string/string.3 +++ b/lib/libc/string/string.3 @@ -27,10 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)string.3 8.2 (Berkeley) 12/11/93 -.\" $FreeBSD$ -.\" -.Dd December 11, 1993 +.Dd September 2, 2023 .Dt STRING 3 .Os .Sh NAME @@ -133,7 +130,8 @@ for size limitations. .Xr strsep 3 , .Xr strspn 3 , .Xr strstr 3 , -.Xr strtok 3 +.Xr strtok 3 , +.Xr simd 7 .Sh STANDARDS The .Fn strcat , diff --git a/lib/libc/string/strlcat.c b/lib/libc/string/strlcat.c index f5ed6c6cf70c..fc18fad179db 100644 --- a/lib/libc/string/strlcat.c +++ b/lib/libc/string/strlcat.c @@ -16,12 +16,11 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/types.h> #include <string.h> +#undef strlcat /* FORTIFY_SOURCE */ + /* * Appends src to string dst of size dsize (unlike strncat, dsize is the * full size of dst, not space left). At most dsize-1 characters diff --git a/lib/libc/string/strlcpy.3 b/lib/libc/string/strlcpy.3 index e659078a6ee0..89c9d62c5a25 100644 --- a/lib/libc/string/strlcpy.3 +++ b/lib/libc/string/strlcpy.3 @@ -25,9 +25,7 @@ .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.\" $FreeBSD$ -.\" -.Dd May 1, 2020 +.Dd October 27, 2023 .Dt STRLCPY 3 .Os .Sh NAME @@ -47,9 +45,11 @@ The .Fn strlcpy and .Fn strlcat -functions copy and concatenate strings with the -same input parameters and output result as -.Xr snprintf 3 . +functions copy and concatenate strings with the same input parameters and output result as +.Xr strcpy 3 +and +.Xr strcat 3 +with proper overflow protection. They are designed to be safer, more consistent, and less error prone replacements for the easily misused functions .Xr strncpy 3 @@ -102,22 +102,7 @@ and .Fa dst strings overlap, the behavior is undefined. .Sh RETURN VALUES -Besides quibbles over the return type -.Pf ( Va size_t -versus -.Va int ) -and signal handler safety -.Pf ( Xr snprintf 3 -is not entirely safe on some systems), the -following two are equivalent: -.Bd -literal -offset indent -n = strlcpy(dst, src, len); -n = snprintf(dst, len, "%s", src); -.Ed -.Pp -Like -.Xr snprintf 3 , -the +The .Fn strlcpy and .Fn strlcat @@ -196,8 +181,7 @@ As a matter of fact, the first version of this manual page got it wrong. .%I USENIX Association .%B Proceedings of the FREENIX Track: 1999 USENIX Annual Technical Conference .%D June 6-11, 1999 -.%U http://www.usenix.org/publications/library/proceedings/usenix99/ -.%U full_papers/millert/millert.pdf +.%U http://www.usenix.org/publications/library/proceedings/usenix99/full_papers/millert/millert.pdf .Re .Sh HISTORY The diff --git a/lib/libc/string/strlcpy.c b/lib/libc/string/strlcpy.c index 019d2316a046..79f7ab19cdfd 100644 --- a/lib/libc/string/strlcpy.c +++ b/lib/libc/string/strlcpy.c @@ -16,12 +16,11 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/types.h> #include <string.h> +#undef strlcpy /* FORTIFY_SOURCE */ + /* * Copy string src to buffer dst of size dsize. At most dsize-1 * chars will be copied. Always NUL terminates (unless dsize == 0). diff --git a/lib/libc/string/strlen.3 b/lib/libc/string/strlen.3 index 55f7b09a2016..91b82a085b01 100644 --- a/lib/libc/string/strlen.3 +++ b/lib/libc/string/strlen.3 @@ -29,9 +29,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)strlen.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD$ -.\" .Dd April 3, 2022 .Dt STRLEN 3 .Os @@ -99,3 +96,8 @@ and was ported to .At v7 . The .Fn strnlen +function first appeared in +.Fx 8.0 , +.Ox 4.8 , +and +.Nx 6.0 . diff --git a/lib/libc/string/strlen.c b/lib/libc/string/strlen.c index 2d1803b1e078..c33819707dce 100644 --- a/lib/libc/string/strlen.c +++ b/lib/libc/string/strlen.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2009, 2010 Xin LI <delphij@FreeBSD.org> * @@ -25,9 +25,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/limits.h> #include <sys/types.h> #include <string.h> diff --git a/lib/libc/string/strmode.3 b/lib/libc/string/strmode.3 index e963d28b9cde..7c9319979acd 100644 --- a/lib/libc/string/strmode.3 +++ b/lib/libc/string/strmode.3 @@ -25,9 +25,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)strmode.3 8.3 (Berkeley) 7/28/94 -.\" $FreeBSD$ -.\" .Dd July 28, 1994 .Dt STRMODE 3 .Os diff --git a/lib/libc/string/strmode.c b/lib/libc/string/strmode.c index d601bd0430e1..ae52c08b0c33 100644 --- a/lib/libc/string/strmode.c +++ b/lib/libc/string/strmode.c @@ -29,12 +29,6 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strmode.c 8.3 (Berkeley) 8/15/94"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/types.h> #include <sys/stat.h> #include <string.h> diff --git a/lib/libc/string/strncat.c b/lib/libc/string/strncat.c index 116fc53f92f4..086bdef32b68 100644 --- a/lib/libc/string/strncat.c +++ b/lib/libc/string/strncat.c @@ -32,14 +32,10 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strncat.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <string.h> +#undef strncat /* _FORTIFY_SOURCE */ + /* * Concatenate src on the end of dst. At most strlen(dst)+n+1 bytes * are written at dst (at most n+1 bytes being appended). Return dst. diff --git a/lib/libc/string/strncmp.c b/lib/libc/string/strncmp.c index c68fe005fcbc..abffdd41588b 100644 --- a/lib/libc/string/strncmp.c +++ b/lib/libc/string/strncmp.c @@ -29,12 +29,6 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strncmp.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <string.h> int diff --git a/lib/libc/string/strncpy.c b/lib/libc/string/strncpy.c index 2ffce161c5c5..67240a855196 100644 --- a/lib/libc/string/strncpy.c +++ b/lib/libc/string/strncpy.c @@ -32,14 +32,10 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strncpy.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <string.h> +#undef strncpy /* FORTIFY_SOURCE */ + /* * Copy src to dst, truncating or null-padding to always copy n bytes. * Return dst. diff --git a/lib/libc/string/strndup.c b/lib/libc/string/strndup.c index bee944db167a..56034d1732fe 100644 --- a/lib/libc/string/strndup.c +++ b/lib/libc/string/strndup.c @@ -16,9 +16,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <stddef.h> #include <stdlib.h> #include <string.h> diff --git a/lib/libc/string/strnlen.c b/lib/libc/string/strnlen.c index fca7ad260ef8..b44f8ab21947 100644 --- a/lib/libc/string/strnlen.c +++ b/lib/libc/string/strnlen.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2009 David Schultz <das@FreeBSD.org> * All rights reserved. @@ -26,9 +26,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <string.h> size_t diff --git a/lib/libc/string/strnstr.c b/lib/libc/string/strnstr.c index 756399fea902..71e6b1d0f0a7 100644 --- a/lib/libc/string/strnstr.c +++ b/lib/libc/string/strnstr.c @@ -33,12 +33,6 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strstr.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <string.h> /* diff --git a/lib/libc/string/strpbrk.3 b/lib/libc/string/strpbrk.3 index bfa50990a71d..cdccf0da957f 100644 --- a/lib/libc/string/strpbrk.3 +++ b/lib/libc/string/strpbrk.3 @@ -29,9 +29,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)strpbrk.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD$ -.\" .Dd June 4, 1993 .Dt STRPBRK 3 .Os diff --git a/lib/libc/string/strpbrk.c b/lib/libc/string/strpbrk.c index 964379e19074..c7dd6c2cff37 100644 --- a/lib/libc/string/strpbrk.c +++ b/lib/libc/string/strpbrk.c @@ -29,12 +29,6 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strpbrk.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <string.h> /* diff --git a/lib/libc/string/strrchr.c b/lib/libc/string/strrchr.c index 6afb8c1a497f..10cb32011cbd 100644 --- a/lib/libc/string/strrchr.c +++ b/lib/libc/string/strrchr.c @@ -29,12 +29,6 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)rindex.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <stddef.h> #include <string.h> diff --git a/lib/libc/string/strsep.3 b/lib/libc/string/strsep.3 index 0dbf1294db27..452f646d96d2 100644 --- a/lib/libc/string/strsep.3 +++ b/lib/libc/string/strsep.3 @@ -28,9 +28,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)strsep.3 8.1 (Berkeley) 6/9/93 -.\" $FreeBSD$ -.\" .Dd May 28, 2018 .Dt STRSEP 3 .Os diff --git a/lib/libc/string/strsep.c b/lib/libc/string/strsep.c index 5de452109df7..bc7510362f62 100644 --- a/lib/libc/string/strsep.c +++ b/lib/libc/string/strsep.c @@ -29,12 +29,6 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strsep.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <string.h> #include <stdio.h> diff --git a/lib/libc/string/strsignal.c b/lib/libc/string/strsignal.c index 5f3292d10255..b99da800cee9 100644 --- a/lib/libc/string/strsignal.c +++ b/lib/libc/string/strsignal.c @@ -29,12 +29,6 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strerror.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include "namespace.h" #if defined(NLS) #include <nl_types.h> diff --git a/lib/libc/string/strspn.3 b/lib/libc/string/strspn.3 index 4a8e3f40ce59..3c87afaed1d9 100644 --- a/lib/libc/string/strspn.3 +++ b/lib/libc/string/strspn.3 @@ -29,9 +29,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)strspn.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD$ -.\" .Dd May 24, 2014 .Dt STRSPN 3 .Os diff --git a/lib/libc/string/strspn.c b/lib/libc/string/strspn.c index f2e9f2706ba7..5f046cf4e66b 100644 --- a/lib/libc/string/strspn.c +++ b/lib/libc/string/strspn.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG> * All rights reserved. @@ -26,9 +26,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/types.h> #include <limits.h> #include <string.h> diff --git a/lib/libc/string/strstr.3 b/lib/libc/string/strstr.3 index b1106b3c5759..8957388db535 100644 --- a/lib/libc/string/strstr.3 +++ b/lib/libc/string/strstr.3 @@ -30,9 +30,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)strstr.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD$ -.\" .Dd October 11, 2001 .Dt STRSTR 3 .Os @@ -153,3 +150,9 @@ The function conforms to .St -isoC . +.Sh HISTORY +The +.Fn strnstr +function was introduced by +.Fx 4.5 +and is non-standard. diff --git a/lib/libc/string/strstr.c b/lib/libc/string/strstr.c index 2ca0d4fd03c1..90f8bc701e0f 100644 --- a/lib/libc/string/strstr.c +++ b/lib/libc/string/strstr.c @@ -22,9 +22,6 @@ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <stdint.h> #include <string.h> diff --git a/lib/libc/string/strtok.3 b/lib/libc/string/strtok.3 index c8ea7a7bfe7f..e905b655b024 100644 --- a/lib/libc/string/strtok.3 +++ b/lib/libc/string/strtok.3 @@ -41,9 +41,6 @@ .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)strtok.3 8.2 (Berkeley) 2/3/94 -.\" $FreeBSD$ -.\" .Dd January 22, 2016 .Dt STRTOK 3 .Os diff --git a/lib/libc/string/strtok.c b/lib/libc/string/strtok.c index 46e40bfa4a61..fb22913505ba 100644 --- a/lib/libc/string/strtok.c +++ b/lib/libc/string/strtok.c @@ -34,12 +34,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strtok.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <stddef.h> #ifdef DEBUG_STRTOK #include <stdio.h> diff --git a/lib/libc/string/strverscmp.3 b/lib/libc/string/strverscmp.3 new file mode 100644 index 000000000000..495e5c8780c1 --- /dev/null +++ b/lib/libc/string/strverscmp.3 @@ -0,0 +1,56 @@ +.\" SPDX-License-Identifier: BSD-2-Clause +.\" Copyright (c) 2022 Aymeric Wibo <obiwac@gmail.com> +.Dd August 31, 2023 +.Dt STRVERSCMP 3 +.Os +.Sh NAME +.Nm strverscmp +.Nd compare strings according to natural order +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In string.h +.Ft int +.Fn strverscmp "const char *s1" "const char *s2" +.Sh DESCRIPTION +The +.Fn strverscmp +function +compares the null-terminated strings +.Fa s1 +and +.Fa s2 +according to their natural order +and returns an integer greater than, equal to, or less than 0, +depending on whether +.Fa s1 +is greater than, equal to, or less than +.Fa s2 . +.Pp +More specifically, this natural order is found by iterating over both +strings until a difference is found. +If the difference is between non-decimal characters, +.Fn strverscmp +acts like +.Xr strcmp 3 +(thus, the ordering would be "a", "b", "train"). +If a decimal digit is found, the whole number is read and compared +(thus, the ordering would be "9", "10", "420" which is different to lexicographic order, +what +.Xr strcmp 3 +would have done). +Numbers with leading zeroes are interpreted as fractional parts (even without a decimal point), +and numbers with more leading zeroes are placed before numbers with fewer leading zeroes +(thus, the ordering would be "000", "00", "01", "010", "09", "0", "1", "9", "10"). +.Sh SEE ALSO +.Xr strcmp 3 , +.Xr versionsort 3 +.Sh STANDARDS +The +.Fn strverscmp +function is a GNU extension and conforms to no standard. +.Sh HISTORY +The +.Fn strverscmp +function was added in +.Fx 13.2 . diff --git a/lib/libc/string/strverscmp.c b/lib/libc/string/strverscmp.c new file mode 100644 index 000000000000..6051adb35499 --- /dev/null +++ b/lib/libc/string/strverscmp.c @@ -0,0 +1,91 @@ +/*- +* SPDX-License-Identifier: BSD-2-Clause +* Copyright (c) 2022 Aymeric Wibo <obiwac@gmail.com> +*/ + +#include <ctype.h> +#include <stddef.h> + +int +strverscmp(const char *s1, const char *s2) +{ + size_t digit_count_1, digit_count_2; + size_t zeros_count_1, zeros_count_2; + const unsigned char *num_1, *num_2; + const unsigned char *u1 = __DECONST(const unsigned char *, s1); + const unsigned char *u2 = __DECONST(const unsigned char *, s2); + + /* + * If pointers are the same, no need to go through to process of + * comparing them. + */ + if (s1 == s2) + return (0); + + while (*u1 != '\0' && *u2 != '\0') { + /* If either character is not a digit, act like strcmp(3). */ + + if (!isdigit(*u1) || !isdigit(*u2)) { + if (*u1 != *u2) + return (*u1 - *u2); + u1++; + u2++; + continue; + } + if (*u1 == '0' || *u2 == '0') { + /* + * Treat leading zeros as if they were the fractional + * part of a number, i.e. as if they had a decimal point + * in front. First, count the leading zeros (more zeros + * == smaller number). + */ + zeros_count_1 = 0; + zeros_count_2 = 0; + for (; *u1 == '0'; u1++) + zeros_count_1++; + for (; *u2 == '0'; u2++) + zeros_count_2++; + if (zeros_count_1 != zeros_count_2) + return (zeros_count_2 - zeros_count_1); + + /* Handle the case where 0 < 09. */ + if (!isdigit(*u1) && isdigit(*u2)) + return (1); + if (!isdigit(*u2) && isdigit(*u1)) + return (-1); + } else { + /* + * No leading zeros; we're simply comparing two numbers. + * It is necessary to first count how many digits there + * are before going back to compare each digit, so that + * e.g. 7 is not considered larger than 60. + */ + num_1 = u1; + num_2 = u2; + + /* Count digits (more digits == larger number). */ + for (; isdigit(*u1); u1++) + ; + for (; isdigit(*u2); u2++) + ; + digit_count_1 = u1 - num_1; + digit_count_2 = u2 - num_2; + if (digit_count_1 != digit_count_2) + return (digit_count_1 - digit_count_2); + + /* + * If there are the same number of digits, go back to + * the start of the number. + */ + u1 = num_1; + u2 = num_2; + } + + /* Compare each digit until there are none left. */ + for (; isdigit(*u1) && isdigit(*u2); u1++, u2++) { + if (*u1 != *u2) + return (*u1 - *u2); + } + } + return (*u1 - *u2); +} diff --git a/lib/libc/string/strxfrm.3 b/lib/libc/string/strxfrm.3 index f2750f4a385a..15964c72a04d 100644 --- a/lib/libc/string/strxfrm.3 +++ b/lib/libc/string/strxfrm.3 @@ -29,9 +29,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)strxfrm.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD$ -.\" .Dd June 4, 1993 .Dt STRXFRM 3 .Os diff --git a/lib/libc/string/strxfrm.c b/lib/libc/string/strxfrm.c index 5842f7c781f0..e327aaf1c2ff 100644 --- a/lib/libc/string/strxfrm.c +++ b/lib/libc/string/strxfrm.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright 2010 Nexenta Systems, Inc. All rights reserved. * Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua> @@ -33,9 +33,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <stdlib.h> #include <string.h> #include <errno.h> diff --git a/lib/libc/string/swab.3 b/lib/libc/string/swab.3 index 204b976ab1f4..050cab6c4dd6 100644 --- a/lib/libc/string/swab.3 +++ b/lib/libc/string/swab.3 @@ -25,9 +25,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)swab.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD$ -.\" .Dd March 4, 2012 .Dt SWAB 3 .Os diff --git a/lib/libc/string/swab.c b/lib/libc/string/swab.c index 1a30ce813784..ed4436a49810 100644 --- a/lib/libc/string/swab.c +++ b/lib/libc/string/swab.c @@ -1,63 +1,25 @@ /*- - * SPDX-License-Identifier: BSD-3-Clause - * - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Jeffrey Mogul. - * - * 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. + * SPDX-License-Identifier: BSD-2-Clause + * Copyright (c) 2024 rilysh <nightquick@proton.me> */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)swab.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <unistd.h> +#include <sys/endian.h> void swab(const void * __restrict from, void * __restrict to, ssize_t len) { - unsigned long temp; - int n; - char *fp, *tp; + const uint16_t *f __aligned(1) = from; + uint16_t *t __aligned(1) = to; - if (len <= 0) - return; - n = len >> 1; - fp = (char *)from; - tp = (char *)to; -#define STEP temp = *fp++,*tp++ = *fp++,*tp++ = temp - /* round to multiple of 8 */ - for (; n & 0x7; --n) - STEP; - for (n >>= 3; n > 0; --n) { - STEP; STEP; STEP; STEP; - STEP; STEP; STEP; STEP; + /* + * POSIX says overlapping copy behavior is undefined, however many + * applications assume the old FreeBSD and current GNU libc behavior + * that will swap the bytes correctly when from == to. Reading both bytes + * and swapping them before writing them back accomplishes this. + */ + while (len > 1) { + *t++ = bswap16(*f++); + len -= 2; } } diff --git a/lib/libc/string/timingsafe_bcmp.3 b/lib/libc/string/timingsafe_bcmp.3 index 502e57176806..52c7be7410ef 100644 --- a/lib/libc/string/timingsafe_bcmp.3 +++ b/lib/libc/string/timingsafe_bcmp.3 @@ -13,8 +13,6 @@ .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -.\" -.\" $FreeBSD$ .Dd August 15, 2016 .Dt TIMINGSAFE_BCMP 3 .Os @@ -89,4 +87,4 @@ function first appeared in .Ox 5.6 . .Pp Both functions first appeared in -.Fx 12.0 . +.Fx 11.1 . diff --git a/lib/libc/string/timingsafe_bcmp.c b/lib/libc/string/timingsafe_bcmp.c index d098158059f3..c3a595a18695 100644 --- a/lib/libc/string/timingsafe_bcmp.c +++ b/lib/libc/string/timingsafe_bcmp.c @@ -15,9 +15,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <string.h> int __timingsafe_bcmp(const void *, const void *, size_t); diff --git a/lib/libc/string/timingsafe_memcmp.c b/lib/libc/string/timingsafe_memcmp.c index 7abfb48045f8..97a146e06a2b 100644 --- a/lib/libc/string/timingsafe_memcmp.c +++ b/lib/libc/string/timingsafe_memcmp.c @@ -15,9 +15,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <limits.h> #include <string.h> diff --git a/lib/libc/string/wcpcpy.c b/lib/libc/string/wcpcpy.c index 41b7c5178269..2ae014b31d29 100644 --- a/lib/libc/string/wcpcpy.c +++ b/lib/libc/string/wcpcpy.c @@ -31,16 +31,11 @@ * 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> +#include <ssp/ssp.h> wchar_t * -wcpcpy(wchar_t * __restrict to, const wchar_t * __restrict from) +__ssp_real(wcpcpy)(wchar_t * __restrict to, const wchar_t * __restrict from) { for (; (*to = *from); ++from, ++to); diff --git a/lib/libc/string/wcpncpy.c b/lib/libc/string/wcpncpy.c index 58b7d39aa3cf..e89facfeb642 100644 --- a/lib/libc/string/wcpncpy.c +++ b/lib/libc/string/wcpncpy.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2009 David Schultz <das@FreeBSD.org> * All rights reserved. @@ -26,13 +26,12 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <wchar.h> +#include <ssp/ssp.h> wchar_t * -wcpncpy(wchar_t * __restrict dst, const wchar_t * __restrict src, size_t n) +__ssp_real(wcpncpy)(wchar_t * __restrict dst, const wchar_t * __restrict src, + size_t n) { for (; n--; dst++, src++) { diff --git a/lib/libc/string/wcscasecmp.c b/lib/libc/string/wcscasecmp.c index 1f75ef93cdd1..0132966fe0cf 100644 --- a/lib/libc/string/wcscasecmp.c +++ b/lib/libc/string/wcscasecmp.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2009 David Schultz <das@FreeBSD.org> * All rights reserved. @@ -26,9 +26,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <wchar.h> #include <wctype.h> diff --git a/lib/libc/string/wcscat.c b/lib/libc/string/wcscat.c index 7428ba3364f2..98e088100a87 100644 --- a/lib/libc/string/wcscat.c +++ b/lib/libc/string/wcscat.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c)1999 Citrus Project, * All rights reserved. @@ -34,12 +34,11 @@ __RCSID("$NetBSD: wcscat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $"); #endif /* LIBC_SCCS and not lint */ #endif -__FBSDID("$FreeBSD$"); - #include <wchar.h> +#include <ssp/ssp.h> wchar_t * -wcscat(wchar_t * __restrict s1, const wchar_t * __restrict s2) +__ssp_real(wcscat)(wchar_t * __restrict s1, const wchar_t * __restrict s2) { wchar_t *cp; diff --git a/lib/libc/string/wcschr.c b/lib/libc/string/wcschr.c index 1375ed9181cf..356f8025c317 100644 --- a/lib/libc/string/wcschr.c +++ b/lib/libc/string/wcschr.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2002 Tim J. Robbins * All rights reserved. @@ -26,9 +26,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <wchar.h> wchar_t * diff --git a/lib/libc/string/wcscmp.c b/lib/libc/string/wcscmp.c index 7205238d5637..66e08ff782a7 100644 --- a/lib/libc/string/wcscmp.c +++ b/lib/libc/string/wcscmp.c @@ -32,14 +32,8 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strcmp.c 8.1 (Berkeley) 6/4/93"; -#if 0 -__RCSID("$NetBSD: wcscmp.c,v 1.3 2001/01/05 12:13:12 itojun Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ -__FBSDID("$FreeBSD$"); + +/* $NetBSD: wcscmp.c,v 1.3 2001/01/05 12:13:12 itojun Exp $ */ #include <wchar.h> diff --git a/lib/libc/string/wcscoll.3 b/lib/libc/string/wcscoll.3 index ba89fb3c268e..620787861f3a 100644 --- a/lib/libc/string/wcscoll.3 +++ b/lib/libc/string/wcscoll.3 @@ -28,10 +28,7 @@ .\" 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. -.\" -.\" @(#)strcoll.3 8.1 (Berkeley) 6/4/93 .\" FreeBSD: src/lib/libc/string/strcoll.3,v 1.11 2001/10/01 16:09:00 ru Exp -.\" $FreeBSD$ .\" .Dd October 4, 2002 .Dt WCSCOLL 3 diff --git a/lib/libc/string/wcscoll.c b/lib/libc/string/wcscoll.c index f68de0de1bbf..e9394a83f60c 100644 --- a/lib/libc/string/wcscoll.c +++ b/lib/libc/string/wcscoll.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright 2017 Nexenta Systems, Inc. * Copyright (c) 2002 Tim J. Robbins @@ -32,9 +32,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <errno.h> #include <stdlib.h> #include <string.h> diff --git a/lib/libc/string/wcscpy.c b/lib/libc/string/wcscpy.c index b400fae1cb5c..d4aed8721bb8 100644 --- a/lib/libc/string/wcscpy.c +++ b/lib/libc/string/wcscpy.c @@ -34,12 +34,11 @@ __RCSID("$NetBSD: wcscpy.c,v 1.1 2000/12/23 23:14:36 itojun Exp $"); #endif /* LIBC_SCCS and not lint */ #endif -__FBSDID("$FreeBSD$"); - #include <wchar.h> +#include <ssp/ssp.h> wchar_t * -wcscpy(wchar_t * __restrict s1, const wchar_t * __restrict s2) +__ssp_real(wcscpy)(wchar_t * __restrict s1, const wchar_t * __restrict s2) { wchar_t *cp; diff --git a/lib/libc/string/wcscspn.c b/lib/libc/string/wcscspn.c index a0db7157e9e0..2bfd5e9f8604 100644 --- a/lib/libc/string/wcscspn.c +++ b/lib/libc/string/wcscspn.c @@ -34,8 +34,6 @@ __RCSID("$NetBSD: wcscspn.c,v 1.1 2000/12/23 23:14:36 itojun Exp $"); #endif /* LIBC_SCCS and not lint */ #endif -__FBSDID("$FreeBSD$"); - #include <wchar.h> size_t diff --git a/lib/libc/string/wcsdup.c b/lib/libc/string/wcsdup.c index eecc0557d284..517acfa7ec49 100644 --- a/lib/libc/string/wcsdup.c +++ b/lib/libc/string/wcsdup.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2005 Tim J. Robbins. * All rights reserved. @@ -26,9 +26,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <stdlib.h> #include <wchar.h> diff --git a/lib/libc/string/wcslcat.c b/lib/libc/string/wcslcat.c index f954b7351fe5..f74ce520b6a7 100644 --- a/lib/libc/string/wcslcat.c +++ b/lib/libc/string/wcslcat.c @@ -35,10 +35,9 @@ __RCSID("$NetBSD: wcslcat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $"); #endif /* LIBC_SCCS and not lint */ #endif -__FBSDID("$FreeBSD$"); - #include <sys/types.h> #include <wchar.h> +#include <ssp/ssp.h> /* * Appends src to string dst of size siz (unlike wcsncat, siz is the @@ -48,7 +47,7 @@ __FBSDID("$FreeBSD$"); * truncation occurred. */ size_t -wcslcat(wchar_t *dst, const wchar_t *src, size_t siz) +__ssp_real(wcslcat)(wchar_t *dst, const wchar_t *src, size_t siz) { wchar_t *d = dst; const wchar_t *s = src; diff --git a/lib/libc/string/wcslcpy.c b/lib/libc/string/wcslcpy.c index ca60d587004f..82269656b985 100644 --- a/lib/libc/string/wcslcpy.c +++ b/lib/libc/string/wcslcpy.c @@ -35,10 +35,9 @@ __RCSID("$NetBSD: wcslcpy.c,v 1.1 2000/12/23 23:14:36 itojun Exp $"); #endif /* LIBC_SCCS and not lint */ #endif -__FBSDID("$FreeBSD$"); - #include <sys/types.h> #include <wchar.h> +#include <ssp/ssp.h> /* * Copy src to string dst of size siz. At most siz-1 characters @@ -46,7 +45,7 @@ __FBSDID("$FreeBSD$"); * Returns wcslen(src); if retval >= siz, truncation occurred. */ size_t -wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz) +__ssp_real(wcslcpy)(wchar_t *dst, const wchar_t *src, size_t siz) { wchar_t *d = dst; const wchar_t *s = src; diff --git a/lib/libc/string/wcslen.c b/lib/libc/string/wcslen.c index cfd3aa23cc99..e81d981c799b 100644 --- a/lib/libc/string/wcslen.c +++ b/lib/libc/string/wcslen.c @@ -34,8 +34,6 @@ __RCSID("$NetBSD: wcslen.c,v 1.1 2000/12/23 23:14:36 itojun Exp $"); #endif /* LIBC_SCCS and not lint */ #endif -__FBSDID("$FreeBSD$"); - #include <wchar.h> size_t diff --git a/lib/libc/string/wcsncasecmp.c b/lib/libc/string/wcsncasecmp.c index 34833d185fdf..0cd9f16796fa 100644 --- a/lib/libc/string/wcsncasecmp.c +++ b/lib/libc/string/wcsncasecmp.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2009 David Schultz <das@FreeBSD.org> * All rights reserved. @@ -26,9 +26,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <wchar.h> #include <wctype.h> diff --git a/lib/libc/string/wcsncat.c b/lib/libc/string/wcsncat.c index eb13fab8de34..5b36fd40bb4f 100644 --- a/lib/libc/string/wcsncat.c +++ b/lib/libc/string/wcsncat.c @@ -34,12 +34,12 @@ __RCSID("$NetBSD: wcsncat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $"); #endif /* LIBC_SCCS and not lint */ #endif -__FBSDID("$FreeBSD$"); - #include <wchar.h> +#include <ssp/ssp.h> wchar_t * -wcsncat(wchar_t * __restrict s1, const wchar_t * __restrict s2, size_t n) +__ssp_real(wcsncat)(wchar_t * __restrict s1, const wchar_t * __restrict s2, + size_t n) { wchar_t *p; wchar_t *q; diff --git a/lib/libc/string/wcsncmp.c b/lib/libc/string/wcsncmp.c index 55c88f60e6fa..141e42c3087f 100644 --- a/lib/libc/string/wcsncmp.c +++ b/lib/libc/string/wcsncmp.c @@ -29,14 +29,7 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strncmp.c 8.1 (Berkeley) 6/4/93"; -__RCSID("$NetBSD: wcsncmp.c,v 1.3 2001/01/05 12:13:13 itojun Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif -__FBSDID("$FreeBSD$"); +/* $NetBSD: wcsncmp.c,v 1.3 2001/01/05 12:13:13 itojun Exp $ */ #include <wchar.h> diff --git a/lib/libc/string/wcsncpy.c b/lib/libc/string/wcsncpy.c index f86e40fe9536..2491dadadfa4 100644 --- a/lib/libc/string/wcsncpy.c +++ b/lib/libc/string/wcsncpy.c @@ -32,22 +32,16 @@ * SUCH DAMAGE. */ -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strncpy.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#endif -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <wchar.h> +#include <ssp/ssp.h> /* * Copy src to dst, truncating or null-padding to always copy n bytes. * Return dst. */ wchar_t * -wcsncpy(wchar_t * __restrict dst, const wchar_t * __restrict src, size_t n) +__ssp_real(wcsncpy)(wchar_t * __restrict dst, const wchar_t * __restrict src, + size_t n) { if (n != 0) { wchar_t *d = dst; diff --git a/lib/libc/string/wcsnlen.c b/lib/libc/string/wcsnlen.c index f7e30d766c02..1dfc2d5ef913 100644 --- a/lib/libc/string/wcsnlen.c +++ b/lib/libc/string/wcsnlen.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2009 David Schultz <das@FreeBSD.org> * All rights reserved. @@ -26,9 +26,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <wchar.h> size_t diff --git a/lib/libc/string/wcspbrk.c b/lib/libc/string/wcspbrk.c index 0e9ccf66e312..62ad9a8130a2 100644 --- a/lib/libc/string/wcspbrk.c +++ b/lib/libc/string/wcspbrk.c @@ -34,8 +34,6 @@ __RCSID("$NetBSD: wcspbrk.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); #endif /* LIBC_SCCS and not lint */ #endif -__FBSDID("$FreeBSD$"); - #include <wchar.h> wchar_t * diff --git a/lib/libc/string/wcsrchr.c b/lib/libc/string/wcsrchr.c index 73a0395fdc41..1679d808be2b 100644 --- a/lib/libc/string/wcsrchr.c +++ b/lib/libc/string/wcsrchr.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2002 Tim J. Robbins * All rights reserved. @@ -26,9 +26,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <wchar.h> wchar_t * diff --git a/lib/libc/string/wcsspn.c b/lib/libc/string/wcsspn.c index 2b08acbd94f6..487ef6bdf3b4 100644 --- a/lib/libc/string/wcsspn.c +++ b/lib/libc/string/wcsspn.c @@ -34,8 +34,6 @@ __RCSID("$NetBSD: wcsspn.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); #endif /* LIBC_SCCS and not lint */ #endif -__FBSDID("$FreeBSD$"); - #include <wchar.h> size_t diff --git a/lib/libc/string/wcsstr.c b/lib/libc/string/wcsstr.c index 74921fecf047..beb5e8931742 100644 --- a/lib/libc/string/wcsstr.c +++ b/lib/libc/string/wcsstr.c @@ -32,14 +32,6 @@ * SUCH DAMAGE. */ -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strstr.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#endif -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <wchar.h> /* diff --git a/lib/libc/string/wcstok.3 b/lib/libc/string/wcstok.3 index 0de24d8366c8..136c733f9708 100644 --- a/lib/libc/string/wcstok.3 +++ b/lib/libc/string/wcstok.3 @@ -47,8 +47,6 @@ .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD$ -.\" .Dd October 3, 2002 .Dt WCSTOK 3 .Os diff --git a/lib/libc/string/wcstok.c b/lib/libc/string/wcstok.c index b4bdc869a2e1..839a650ce316 100644 --- a/lib/libc/string/wcstok.c +++ b/lib/libc/string/wcstok.c @@ -34,9 +34,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <wchar.h> wchar_t * diff --git a/lib/libc/string/wcswidth.3 b/lib/libc/string/wcswidth.3 index 76d32ad8e4b9..20ba1fa5a3e1 100644 --- a/lib/libc/string/wcswidth.3 +++ b/lib/libc/string/wcswidth.3 @@ -22,8 +22,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD$ -.\" .Dd August 20, 2002 .Dt WCSWIDTH 3 .Os diff --git a/lib/libc/string/wcswidth.c b/lib/libc/string/wcswidth.c index d5bf7ce5fe41..b6f3abd761eb 100644 --- a/lib/libc/string/wcswidth.c +++ b/lib/libc/string/wcswidth.c @@ -42,9 +42,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <wchar.h> #include "xlocale_private.h" diff --git a/lib/libc/string/wcsxfrm.3 b/lib/libc/string/wcsxfrm.3 index ac30d38e1131..8fca7c1b62df 100644 --- a/lib/libc/string/wcsxfrm.3 +++ b/lib/libc/string/wcsxfrm.3 @@ -28,10 +28,7 @@ .\" 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. -.\" -.\" @(#)strxfrm.3 8.1 (Berkeley) 6/4/93 .\" FreeBSD: src/lib/libc/string/strxfrm.3,v 1.16 2002/09/06 11:24:06 tjr Exp -.\" $FreeBSD$ .\" .Dd October 4, 2002 .Dt WCSXFRM 3 diff --git a/lib/libc/string/wcsxfrm.c b/lib/libc/string/wcsxfrm.c index c9fbaf3e70a5..8c6c542c9255 100644 --- a/lib/libc/string/wcsxfrm.c +++ b/lib/libc/string/wcsxfrm.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright 2010 Nexenta Systems, Inc. All rights reserved. * Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua> @@ -33,9 +33,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <stdlib.h> #include <string.h> #include <wchar.h> diff --git a/lib/libc/string/wmemchr.3 b/lib/libc/string/wmemchr.3 index 8a926eef456a..c1701facb7d5 100644 --- a/lib/libc/string/wmemchr.3 +++ b/lib/libc/string/wmemchr.3 @@ -31,11 +31,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" from: @(#)strcpy.3 8.1 (Berkeley) 6/4/93 -.\" -.\" $FreeBSD$ -.\" -.Dd July 14, 2021 +.Dd March 21, 2024 .Dt WMEMCHR 3 .Os .Sh NAME @@ -84,9 +80,9 @@ .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" +.Fn wcpcpy "wchar_t * restrict s1" "const wchar_t * restrict s2" .Ft wchar_t * -.Fn wcpncpy "wchar_t *s1" "wchar_t *s2" "size_t n" +.Fn wcpncpy "wchar_t * restrict s1" "const wchar_t * restrict s2" "size_t n" .Ft int .Fn wcscasecmp "const wchar_t *s1" "const wchar_t *s2" .Ft wchar_t * diff --git a/lib/libc/string/wmemchr.c b/lib/libc/string/wmemchr.c index 42ae286aaec7..8724187ffd63 100644 --- a/lib/libc/string/wmemchr.c +++ b/lib/libc/string/wmemchr.c @@ -34,8 +34,6 @@ __RCSID("$NetBSD: wmemchr.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); #endif /* LIBC_SCCS and not lint */ #endif -__FBSDID("$FreeBSD$"); - #include <wchar.h> wchar_t * diff --git a/lib/libc/string/wmemcmp.c b/lib/libc/string/wmemcmp.c index f1b1b00eb5da..1abebfd8da95 100644 --- a/lib/libc/string/wmemcmp.c +++ b/lib/libc/string/wmemcmp.c @@ -34,8 +34,6 @@ __RCSID("$NetBSD: wmemcmp.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); #endif /* LIBC_SCCS and not lint */ #endif -__FBSDID("$FreeBSD$"); - #include <wchar.h> int diff --git a/lib/libc/string/wmemcpy.c b/lib/libc/string/wmemcpy.c index 30956eb4f483..9db16fe77a69 100644 --- a/lib/libc/string/wmemcpy.c +++ b/lib/libc/string/wmemcpy.c @@ -34,13 +34,13 @@ __RCSID("$NetBSD: wmemcpy.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); #endif /* LIBC_SCCS and not lint */ #endif -__FBSDID("$FreeBSD$"); - #include <string.h> #include <wchar.h> +#include <ssp/ssp.h> wchar_t * -wmemcpy(wchar_t * __restrict d, const wchar_t * __restrict s, size_t n) +__ssp_real(wmemcpy)(wchar_t * __restrict d, const wchar_t * __restrict s, + size_t n) { return (wchar_t *)memcpy(d, s, n * sizeof(wchar_t)); } diff --git a/lib/libc/string/wmemmove.c b/lib/libc/string/wmemmove.c index 5e8da9f4004c..837dbe12dc7a 100644 --- a/lib/libc/string/wmemmove.c +++ b/lib/libc/string/wmemmove.c @@ -34,13 +34,12 @@ __RCSID("$NetBSD: wmemmove.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); #endif /* LIBC_SCCS and not lint */ #endif -__FBSDID("$FreeBSD$"); - #include <string.h> #include <wchar.h> +#include <ssp/ssp.h> wchar_t * -wmemmove(wchar_t *d, const wchar_t *s, size_t n) +__ssp_real(wmemmove)(wchar_t *d, const wchar_t *s, size_t n) { return (wchar_t *)memmove(d, s, n * sizeof(wchar_t)); } diff --git a/lib/libc/string/wmempcpy.c b/lib/libc/string/wmempcpy.c index 21bf34503396..152bb76c7e80 100644 --- a/lib/libc/string/wmempcpy.c +++ b/lib/libc/string/wmempcpy.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2021 The FreeBSD Foundation * @@ -28,14 +28,13 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <string.h> #include <wchar.h> +#include <ssp/ssp.h> wchar_t * -wmempcpy(wchar_t *__restrict dst, const wchar_t *__restrict src, size_t len) +__ssp_real(wmempcpy)(wchar_t *__restrict dst, const wchar_t *__restrict src, + size_t len) { return (wmemcpy(dst, src, len) + len); } diff --git a/lib/libc/string/wmemset.c b/lib/libc/string/wmemset.c index fcf40efb8e32..60fb14b6a4af 100644 --- a/lib/libc/string/wmemset.c +++ b/lib/libc/string/wmemset.c @@ -34,12 +34,11 @@ __RCSID("$NetBSD: wmemset.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); #endif /* LIBC_SCCS and not lint */ #endif -__FBSDID("$FreeBSD$"); - #include <wchar.h> +#include <ssp/ssp.h> wchar_t * -wmemset(wchar_t *s, wchar_t c, size_t n) +__ssp_real(wmemset)(wchar_t *s, wchar_t c, size_t n) { size_t i; wchar_t *p; |