aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/string
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/string')
-rw-r--r--lib/libc/string/Makefile.inc6
-rw-r--r--lib/libc/string/Symbol.map7
-rw-r--r--lib/libc/string/bcmp.32
-rw-r--r--lib/libc/string/bcmp.c4
-rw-r--r--lib/libc/string/bcopy.32
-rw-r--r--lib/libc/string/bcopy.c9
-rw-r--r--lib/libc/string/bstring.311
-rw-r--r--lib/libc/string/bzero.32
-rw-r--r--lib/libc/string/bzero.c1
-rw-r--r--lib/libc/string/ffs.32
-rw-r--r--lib/libc/string/ffs.c4
-rw-r--r--lib/libc/string/ffsl.c1
-rw-r--r--lib/libc/string/ffsll.c1
-rw-r--r--lib/libc/string/fls.c1
-rw-r--r--lib/libc/string/flsl.c1
-rw-r--r--lib/libc/string/flsll.c1
-rw-r--r--lib/libc/string/index.32
-rw-r--r--lib/libc/string/memccpy.333
-rw-r--r--lib/libc/string/memccpy.c6
-rw-r--r--lib/libc/string/memchr.324
-rw-r--r--lib/libc/string/memchr.c1
-rw-r--r--lib/libc/string/memcmp.343
-rw-r--r--lib/libc/string/memcmp.c4
-rw-r--r--lib/libc/string/memcpy.317
-rw-r--r--lib/libc/string/memcpy.c1
-rw-r--r--lib/libc/string/memmem.36
-rw-r--r--lib/libc/string/memmem.c1
-rw-r--r--lib/libc/string/memmove.32
-rw-r--r--lib/libc/string/memmove.c1
-rw-r--r--lib/libc/string/mempcpy.c5
-rw-r--r--lib/libc/string/memset.320
-rw-r--r--lib/libc/string/memset.c8
-rw-r--r--lib/libc/string/memset_explicit.c27
-rw-r--r--lib/libc/string/memset_s.c1
-rw-r--r--lib/libc/string/stpcpy.c6
-rw-r--r--lib/libc/string/stpncpy.c3
-rw-r--r--lib/libc/string/strcasecmp.32
-rw-r--r--lib/libc/string/strcasecmp.c4
-rw-r--r--lib/libc/string/strcasestr.c1
-rw-r--r--lib/libc/string/strcat.32
-rw-r--r--lib/libc/string/strcat.c6
-rw-r--r--lib/libc/string/strchr.32
-rw-r--r--lib/libc/string/strchr.c1
-rw-r--r--lib/libc/string/strchrnul.c1
-rw-r--r--lib/libc/string/strcmp.32
-rw-r--r--lib/libc/string/strcmp.c4
-rw-r--r--lib/libc/string/strcoll.32
-rw-r--r--lib/libc/string/strcoll.c1
-rw-r--r--lib/libc/string/strcpy.32
-rw-r--r--lib/libc/string/strcpy.c4
-rw-r--r--lib/libc/string/strcspn.c1
-rw-r--r--lib/libc/string/strdup.32
-rw-r--r--lib/libc/string/strdup.c4
-rw-r--r--lib/libc/string/strerror.32
-rw-r--r--lib/libc/string/strerror.c18
-rw-r--r--lib/libc/string/string.37
-rw-r--r--lib/libc/string/strlcat.c3
-rw-r--r--lib/libc/string/strlcpy.327
-rw-r--r--lib/libc/string/strlcpy.c3
-rw-r--r--lib/libc/string/strlen.37
-rw-r--r--lib/libc/string/strlen.c1
-rw-r--r--lib/libc/string/strmode.32
-rw-r--r--lib/libc/string/strmode.c4
-rw-r--r--lib/libc/string/strncat.c6
-rw-r--r--lib/libc/string/strncmp.c4
-rw-r--r--lib/libc/string/strncpy.c6
-rw-r--r--lib/libc/string/strndup.c1
-rw-r--r--lib/libc/string/strnlen.c1
-rw-r--r--lib/libc/string/strnstr.c4
-rw-r--r--lib/libc/string/strpbrk.32
-rw-r--r--lib/libc/string/strpbrk.c4
-rw-r--r--lib/libc/string/strrchr.c4
-rw-r--r--lib/libc/string/strsep.32
-rw-r--r--lib/libc/string/strsep.c4
-rw-r--r--lib/libc/string/strsignal.c4
-rw-r--r--lib/libc/string/strspn.32
-rw-r--r--lib/libc/string/strspn.c1
-rw-r--r--lib/libc/string/strstr.32
-rw-r--r--lib/libc/string/strstr.c1
-rw-r--r--lib/libc/string/strtok.32
-rw-r--r--lib/libc/string/strtok.c4
-rw-r--r--lib/libc/string/strxfrm.32
-rw-r--r--lib/libc/string/strxfrm.c1
-rw-r--r--lib/libc/string/swab.32
-rw-r--r--lib/libc/string/swab.c65
-rw-r--r--lib/libc/string/timingsafe_bcmp.32
-rw-r--r--lib/libc/string/timingsafe_bcmp.c1
-rw-r--r--lib/libc/string/timingsafe_memcmp.c1
-rw-r--r--lib/libc/string/wcpcpy.c7
-rw-r--r--lib/libc/string/wcpncpy.c5
-rw-r--r--lib/libc/string/wcscasecmp.c1
-rw-r--r--lib/libc/string/wcscat.c3
-rw-r--r--lib/libc/string/wcschr.c1
-rw-r--r--lib/libc/string/wcscmp.c10
-rw-r--r--lib/libc/string/wcscoll.32
-rw-r--r--lib/libc/string/wcscoll.c1
-rw-r--r--lib/libc/string/wcscpy.c3
-rw-r--r--lib/libc/string/wcsdup.c1
-rw-r--r--lib/libc/string/wcslcat.c3
-rw-r--r--lib/libc/string/wcslcpy.c3
-rw-r--r--lib/libc/string/wcsncasecmp.c1
-rw-r--r--lib/libc/string/wcsncat.c4
-rw-r--r--lib/libc/string/wcsncmp.c9
-rw-r--r--lib/libc/string/wcsncpy.c10
-rw-r--r--lib/libc/string/wcsnlen.c1
-rw-r--r--lib/libc/string/wcsrchr.c1
-rw-r--r--lib/libc/string/wcsstr.c6
-rw-r--r--lib/libc/string/wcstok.c1
-rw-r--r--lib/libc/string/wcswidth.c1
-rw-r--r--lib/libc/string/wcsxfrm.32
-rw-r--r--lib/libc/string/wcsxfrm.c1
-rw-r--r--lib/libc/string/wmemchr.38
-rw-r--r--lib/libc/string/wmemcpy.c4
-rw-r--r--lib/libc/string/wmemmove.c3
-rw-r--r--lib/libc/string/wmempcpy.c5
-rw-r--r--lib/libc/string/wmemset.c3
116 files changed, 242 insertions, 367 deletions
diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc
index a18eb62fddb8..5d4a9a6e3eed 100644
--- a/lib/libc/string/Makefile.inc
+++ b/lib/libc/string/Makefile.inc
@@ -1,5 +1,3 @@
-# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
-
.if ${MK_MACHDEP_OPTIMIZATIONS} != "no"
.PATH: ${LIBC_SRCTOP}/${LIBC_ARCH}/string
.endif
@@ -13,6 +11,7 @@ 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 \
@@ -64,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 ec4778ff3c24..6b2c41124adf 100644
--- a/lib/libc/string/Symbol.map
+++ b/lib/libc/string/Symbol.map
@@ -1,6 +1,3 @@
-/*
- */
-
FBSD_1.0 {
bcmp;
bcopy;
@@ -119,6 +116,10 @@ FBSD_1.7 {
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 7867e643c542..954e10bfdeab 100644
--- a/lib/libc/string/bcmp.3
+++ b/lib/libc/string/bcmp.3
@@ -27,8 +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
-.\"
.Dd August 15, 2016
.Dt BCMP 3
.Os
diff --git a/lib/libc/string/bcmp.c b/lib/libc/string/bcmp.c
index 0a7c6f0948a6..cf1e487d391e 100644
--- a/lib/libc/string/bcmp.c
+++ b/lib/libc/string/bcmp.c
@@ -29,10 +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>
#include <strings.h>
/*
diff --git a/lib/libc/string/bcopy.3 b/lib/libc/string/bcopy.3
index 6cae69c083b2..230ca2eea89a 100644
--- a/lib/libc/string/bcopy.3
+++ b/lib/libc/string/bcopy.3
@@ -28,8 +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
-.\"
.Dd August 24, 2015
.Dt BCOPY 3
.Os
diff --git a/lib/libc/string/bcopy.c b/lib/libc/string/bcopy.c
index 4328542d2d54..20f7bc60b76a 100644
--- a/lib/libc/string/bcopy.c
+++ b/lib/libc/string/bcopy.c
@@ -32,10 +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>
#include <sys/types.h>
typedef intptr_t word; /* "word" used for optimal copy speed */
@@ -51,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
@@ -61,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 cb29a6db6b14..dd89af44fc4a 100644
--- a/lib/libc/string/bstring.3
+++ b/lib/libc/string/bstring.3
@@ -27,9 +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
-.\"
-.Dd June 4, 1993
+.Dd December 5, 2023
.Dt BSTRING 3
.Os
.Sh NAME
@@ -58,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 a9e515763e25..2c791c497d8c 100644
--- a/lib/libc/string/bzero.3
+++ b/lib/libc/string/bzero.3
@@ -28,8 +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
-.\"
.Dd August 24, 2015
.Dt BZERO 3
.Os
diff --git a/lib/libc/string/bzero.c b/lib/libc/string/bzero.c
index fe149def7930..7bc2b3a7008a 100644
--- a/lib/libc/string/bzero.c
+++ b/lib/libc/string/bzero.c
@@ -1,3 +1,2 @@
-#include <sys/cdefs.h>
#define BZERO
#include "memset.c"
diff --git a/lib/libc/string/ffs.3 b/lib/libc/string/ffs.3
index 1adece73c8ae..2a5adb01c737 100644
--- a/lib/libc/string/ffs.3
+++ b/lib/libc/string/ffs.3
@@ -27,8 +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
-.\"
.Dd October 17, 2015
.Dt FFS 3
.Os
diff --git a/lib/libc/string/ffs.c b/lib/libc/string/ffs.c
index b318c33f641b..0e137b6bb97e 100644
--- a/lib/libc/string/ffs.c
+++ b/lib/libc/string/ffs.c
@@ -33,10 +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>
#include <strings.h>
/*
diff --git a/lib/libc/string/ffsl.c b/lib/libc/string/ffsl.c
index 237e62617315..c3a87a902526 100644
--- a/lib/libc/string/ffsl.c
+++ b/lib/libc/string/ffsl.c
@@ -33,7 +33,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <strings.h>
/*
diff --git a/lib/libc/string/ffsll.c b/lib/libc/string/ffsll.c
index 4fb5ccc4ef7c..5c7abc1f7a23 100644
--- a/lib/libc/string/ffsll.c
+++ b/lib/libc/string/ffsll.c
@@ -33,7 +33,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <strings.h>
/*
diff --git a/lib/libc/string/fls.c b/lib/libc/string/fls.c
index 554b8dc4b413..ac5fb7738722 100644
--- a/lib/libc/string/fls.c
+++ b/lib/libc/string/fls.c
@@ -33,7 +33,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <limits.h>
#include <strings.h>
diff --git a/lib/libc/string/flsl.c b/lib/libc/string/flsl.c
index 6b881bc39b9e..d88c8dfcdc63 100644
--- a/lib/libc/string/flsl.c
+++ b/lib/libc/string/flsl.c
@@ -34,7 +34,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <limits.h>
#include <strings.h>
diff --git a/lib/libc/string/flsll.c b/lib/libc/string/flsll.c
index 68d6d52bee4b..635ebacddf18 100644
--- a/lib/libc/string/flsll.c
+++ b/lib/libc/string/flsll.c
@@ -33,7 +33,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <limits.h>
#include <strings.h>
diff --git a/lib/libc/string/index.3 b/lib/libc/string/index.3
index cbc174a94f60..efab4e6d42ee 100644
--- a/lib/libc/string/index.3
+++ b/lib/libc/string/index.3
@@ -27,8 +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
-.\"
.Dd March 20, 2011
.Dt INDEX 3
.Os
diff --git a/lib/libc/string/memccpy.3 b/lib/libc/string/memccpy.3
index fb2409ada846..0d35a68fce67 100644
--- a/lib/libc/string/memccpy.3
+++ b/lib/libc/string/memccpy.3
@@ -25,9 +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
-.\"
-.Dd June 9, 1993
+.Dd December 5, 2023
.Dt MEMCCPY 3
.Os
.Sh NAME
@@ -38,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
@@ -61,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 a81e8936e46a..d6a446503eb6 100644
--- a/lib/libc/string/memccpy.c
+++ b/lib/libc/string/memccpy.c
@@ -29,14 +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>
#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 72a4fa70e536..c50e932d3382 100644
--- a/lib/libc/string/memchr.3
+++ b/lib/libc/string/memchr.3
@@ -29,14 +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
-.\"
.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
@@ -53,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
@@ -62,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 10df015c5b64..367eac5108c1 100644
--- a/lib/libc/string/memchr.c
+++ b/lib/libc/string/memchr.c
@@ -22,7 +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>
#include <limits.h>
#include <stdint.h>
#include <string.h>
diff --git a/lib/libc/string/memcmp.3 b/lib/libc/string/memcmp.3
index bf02412d9e70..8f4980d61c05 100644
--- a/lib/libc/string/memcmp.3
+++ b/lib/libc/string/memcmp.3
@@ -29,14 +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
-.\"
-.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
@@ -47,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 ,
@@ -82,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 1a72e376c37a..1117e0565290 100644
--- a/lib/libc/string/memcmp.c
+++ b/lib/libc/string/memcmp.c
@@ -32,10 +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>
#include <string.h>
/*
diff --git a/lib/libc/string/memcpy.3 b/lib/libc/string/memcpy.3
index 5ce43d5dfe75..c1cf93af1cdc 100644
--- a/lib/libc/string/memcpy.3
+++ b/lib/libc/string/memcpy.3
@@ -29,9 +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
-.\"
-.Dd July 14, 2021
+.Dd November 18, 2023
.Dt MEMCPY 3
.Os
.Sh NAME
@@ -77,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
@@ -85,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 886b7cb2c654..ee1150473aa9 100644
--- a/lib/libc/string/memcpy.c
+++ b/lib/libc/string/memcpy.c
@@ -1,3 +1,2 @@
-#include <sys/cdefs.h>
#define MEMCOPY
#include "bcopy.c"
diff --git a/lib/libc/string/memmem.3 b/lib/libc/string/memmem.3
index 5d8bcc84e31f..e301a0bd1e0f 100644
--- a/lib/libc/string/memmem.3
+++ b/lib/libc/string/memmem.3
@@ -67,10 +67,10 @@ is returned.
.Xr memchr 3 ,
.Xr strchr 3 ,
.Xr strstr 3
-.Sh CONFORMING TO
+.Sh STANDARDS
.Fn memmem
-started as a GNU extension but is now available in at least
-the GNU, musl, bionic, OpenBSD, NetBSD, macOS, and illumos C runtime libraries.
+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 11e1540bf1fc..4a244b5964ce 100644
--- a/lib/libc/string/memmem.c
+++ b/lib/libc/string/memmem.c
@@ -22,7 +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>
#include <stdint.h>
#include <string.h>
diff --git a/lib/libc/string/memmove.3 b/lib/libc/string/memmove.3
index 0b4ea6d3fa8f..4fd190610388 100644
--- a/lib/libc/string/memmove.3
+++ b/lib/libc/string/memmove.3
@@ -29,8 +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
-.\"
.Dd June 4, 1993
.Dt MEMMOVE 3
.Os
diff --git a/lib/libc/string/memmove.c b/lib/libc/string/memmove.c
index 089a77a892a0..e9bb2c2ed14c 100644
--- a/lib/libc/string/memmove.c
+++ b/lib/libc/string/memmove.c
@@ -1,3 +1,2 @@
-#include <sys/cdefs.h>
#define MEMMOVE
#include "bcopy.c"
diff --git a/lib/libc/string/mempcpy.c b/lib/libc/string/mempcpy.c
index 2c645da97627..4ea0af87aef1 100644
--- a/lib/libc/string/mempcpy.c
+++ b/lib/libc/string/mempcpy.c
@@ -28,11 +28,12 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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/memset.3 b/lib/libc/string/memset.3
index 656f1bbad749..f6ab9dacb516 100644
--- a/lib/libc/string/memset.3
+++ b/lib/libc/string/memset.3
@@ -29,9 +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
-.\"
-.Dd August 19, 2018
+.Dd October 24, 2024
.Dt MEMSET 3
.Os
.Sh NAME
@@ -43,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"
@@ -70,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
@@ -110,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.
@@ -130,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 eed47014356f..811def0fc9b4 100644
--- a/lib/libc/string/memset.c
+++ b/lib/libc/string/memset.c
@@ -32,10 +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>
#include <sys/types.h>
#include <limits.h>
@@ -46,6 +42,8 @@ static char sccsid[] = "@(#)memset.c 8.1 (Berkeley) 6/4/93";
#ifdef BZERO
#include <strings.h>
+#undef bzero /* _FORTIFY_SOURCE */
+
#define RETURN return
#define VAL 0
#define WIDEVAL 0
@@ -55,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 3c7f76d19d7b..d6da7be8385d 100644
--- a/lib/libc/string/memset_s.c
+++ b/lib/libc/string/memset_s.c
@@ -23,7 +23,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
diff --git a/lib/libc/string/stpcpy.c b/lib/libc/string/stpcpy.c
index 02640a68b0ae..4521e0877e07 100644
--- a/lib/libc/string/stpcpy.c
+++ b/lib/libc/string/stpcpy.c
@@ -31,12 +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>
#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 46e61c468d99..d3a1dddb4a65 100644
--- a/lib/libc/string/stpncpy.c
+++ b/lib/libc/string/stpncpy.c
@@ -26,9 +26,10 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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 a28b1e196e90..7297ec328724 100644
--- a/lib/libc/string/strcasecmp.3
+++ b/lib/libc/string/strcasecmp.3
@@ -27,8 +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
-.\"
.Dd May 29, 2014
.Dt STRCASECMP 3
.Os
diff --git a/lib/libc/string/strcasecmp.c b/lib/libc/string/strcasecmp.c
index c959869ad9f0..69c6d0aa4492 100644
--- a/lib/libc/string/strcasecmp.c
+++ b/lib/libc/string/strcasecmp.c
@@ -34,10 +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>
#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 591a2d95304b..c1be973f01f4 100644
--- a/lib/libc/string/strcasestr.c
+++ b/lib/libc/string/strcasestr.c
@@ -37,7 +37,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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 061bd714a05d..a8365b8fbdf8 100644
--- a/lib/libc/string/strcat.3
+++ b/lib/libc/string/strcat.3
@@ -29,8 +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
-.\"
.Dd April 3, 2022
.Dt STRCAT 3
.Os
diff --git a/lib/libc/string/strcat.c b/lib/libc/string/strcat.c
index 94f851d4a257..1c13c519b563 100644
--- a/lib/libc/string/strcat.c
+++ b/lib/libc/string/strcat.c
@@ -29,12 +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>
#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 3d420624abd9..45179a0001fc 100644
--- a/lib/libc/string/strchr.3
+++ b/lib/libc/string/strchr.3
@@ -29,8 +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
-.\"
.Dd February 13, 2013
.Dt STRCHR 3
.Os
diff --git a/lib/libc/string/strchr.c b/lib/libc/string/strchr.c
index d4e35b07c8c1..8f6f947e9983 100644
--- a/lib/libc/string/strchr.c
+++ b/lib/libc/string/strchr.c
@@ -22,7 +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>
#include <string.h>
char *__strchrnul(const char *, int);
diff --git a/lib/libc/string/strchrnul.c b/lib/libc/string/strchrnul.c
index 1841185dc9b6..3a42c0e7c4c5 100644
--- a/lib/libc/string/strchrnul.c
+++ b/lib/libc/string/strchrnul.c
@@ -22,7 +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>
#include <limits.h>
#include <stdint.h>
#include <string.h>
diff --git a/lib/libc/string/strcmp.3 b/lib/libc/string/strcmp.3
index 65baf65ed40b..6f39d8d95dd4 100644
--- a/lib/libc/string/strcmp.3
+++ b/lib/libc/string/strcmp.3
@@ -29,8 +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
-.\"
.Dd April 3, 2022
.Dt STRCMP 3
.Os
diff --git a/lib/libc/string/strcmp.c b/lib/libc/string/strcmp.c
index 9d590cc5a4f0..216efd318906 100644
--- a/lib/libc/string/strcmp.c
+++ b/lib/libc/string/strcmp.c
@@ -32,10 +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>
#include <string.h>
/*
diff --git a/lib/libc/string/strcoll.3 b/lib/libc/string/strcoll.3
index 178e87fd7d48..863bc3a43d4e 100644
--- a/lib/libc/string/strcoll.3
+++ b/lib/libc/string/strcoll.3
@@ -29,8 +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
-.\"
.Dd June 4, 1993
.Dt STRCOLL 3
.Os
diff --git a/lib/libc/string/strcoll.c b/lib/libc/string/strcoll.c
index a682f352320f..77566f0c7cd7 100644
--- a/lib/libc/string/strcoll.c
+++ b/lib/libc/string/strcoll.c
@@ -33,7 +33,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
diff --git a/lib/libc/string/strcpy.3 b/lib/libc/string/strcpy.3
index db9cf39b3b38..ed32d78826eb 100644
--- a/lib/libc/string/strcpy.3
+++ b/lib/libc/string/strcpy.3
@@ -29,8 +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
-.\"
.Dd June 6, 2018
.Dt STRCPY 3
.Os
diff --git a/lib/libc/string/strcpy.c b/lib/libc/string/strcpy.c
index 5b0ca98fb8b5..432bcc0e9d62 100644
--- a/lib/libc/string/strcpy.c
+++ b/lib/libc/string/strcpy.c
@@ -29,10 +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>
#include <string.h>
#ifdef WEAK_STRCPY
diff --git a/lib/libc/string/strcspn.c b/lib/libc/string/strcspn.c
index 687a309d01d9..88bf68ff0733 100644
--- a/lib/libc/string/strcspn.c
+++ b/lib/libc/string/strcspn.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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 a19a00f5430b..576fa122b8d6 100644
--- a/lib/libc/string/strdup.3
+++ b/lib/libc/string/strdup.3
@@ -25,8 +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
-.\"
.Dd May 5, 2020
.Dt STRDUP 3
.Os
diff --git a/lib/libc/string/strdup.c b/lib/libc/string/strdup.c
index 3e6849abe12c..2d595e53eb6b 100644
--- a/lib/libc/string/strdup.c
+++ b/lib/libc/string/strdup.c
@@ -29,10 +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>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
diff --git a/lib/libc/string/strerror.3 b/lib/libc/string/strerror.3
index 9c6847144f89..fa72dcff627b 100644
--- a/lib/libc/string/strerror.3
+++ b/lib/libc/string/strerror.3
@@ -29,8 +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
-.\"
.Dd December 17, 2020
.Dt STRERROR 3
.Os
diff --git a/lib/libc/string/strerror.c b/lib/libc/string/strerror.c
index 673ccbf37ef7..922bb0284497 100644
--- a/lib/libc/string/strerror.c
+++ b/lib/libc/string/strerror.c
@@ -29,10 +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>
#if defined(NLS)
#include <nl_types.h>
#endif
@@ -42,6 +38,8 @@ static char sccsid[] = "@(#)strerror.c 8.1 (Berkeley) 6/4/93";
#include <string.h>
#include <stdio.h>
+#include <ssp/ssp.h>
+
#include "errlst.h"
#include "../locale/xlocale_private.h"
#include "libc_private.h"
@@ -78,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)
@@ -118,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 *
@@ -128,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);
}
@@ -138,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 a164aae01eec..3ffea6ce0369 100644
--- a/lib/libc/string/string.3
+++ b/lib/libc/string/string.3
@@ -27,9 +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
-.\"
-.Dd December 11, 1993
+.Dd September 2, 2023
.Dt STRING 3
.Os
.Sh NAME
@@ -132,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 e5040019b29b..fc18fad179db 100644
--- a/lib/libc/string/strlcat.c
+++ b/lib/libc/string/strlcat.c
@@ -16,10 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/cdefs.h>
#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 148afcbbd2bd..89c9d62c5a25 100644
--- a/lib/libc/string/strlcpy.3
+++ b/lib/libc/string/strlcpy.3
@@ -25,7 +25,7 @@
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd May 1, 2020
+.Dd October 27, 2023
.Dt STRLCPY 3
.Os
.Sh NAME
@@ -45,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
@@ -100,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
diff --git a/lib/libc/string/strlcpy.c b/lib/libc/string/strlcpy.c
index 8c7daa858960..79f7ab19cdfd 100644
--- a/lib/libc/string/strlcpy.c
+++ b/lib/libc/string/strlcpy.c
@@ -16,10 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/cdefs.h>
#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 17427fc4c96c..91b82a085b01 100644
--- a/lib/libc/string/strlen.3
+++ b/lib/libc/string/strlen.3
@@ -29,8 +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
-.\"
.Dd April 3, 2022
.Dt STRLEN 3
.Os
@@ -98,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 d7c744d6aa60..c33819707dce 100644
--- a/lib/libc/string/strlen.c
+++ b/lib/libc/string/strlen.c
@@ -25,7 +25,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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 503bd3b1ae4a..7c9319979acd 100644
--- a/lib/libc/string/strmode.3
+++ b/lib/libc/string/strmode.3
@@ -25,8 +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
-.\"
.Dd July 28, 1994
.Dt STRMODE 3
.Os
diff --git a/lib/libc/string/strmode.c b/lib/libc/string/strmode.c
index 58b9490bb163..ae52c08b0c33 100644
--- a/lib/libc/string/strmode.c
+++ b/lib/libc/string/strmode.c
@@ -29,10 +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>
#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 3220f036c458..086bdef32b68 100644
--- a/lib/libc/string/strncat.c
+++ b/lib/libc/string/strncat.c
@@ -32,12 +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>
#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 111d77b592c2..abffdd41588b 100644
--- a/lib/libc/string/strncmp.c
+++ b/lib/libc/string/strncmp.c
@@ -29,10 +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>
#include <string.h>
int
diff --git a/lib/libc/string/strncpy.c b/lib/libc/string/strncpy.c
index 6a00e1ba5135..67240a855196 100644
--- a/lib/libc/string/strncpy.c
+++ b/lib/libc/string/strncpy.c
@@ -32,12 +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>
#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 a2351bf40722..56034d1732fe 100644
--- a/lib/libc/string/strndup.c
+++ b/lib/libc/string/strndup.c
@@ -16,7 +16,6 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/cdefs.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
diff --git a/lib/libc/string/strnlen.c b/lib/libc/string/strnlen.c
index 8fa984551b8e..b44f8ab21947 100644
--- a/lib/libc/string/strnlen.c
+++ b/lib/libc/string/strnlen.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <string.h>
size_t
diff --git a/lib/libc/string/strnstr.c b/lib/libc/string/strnstr.c
index 023b167e9c36..71e6b1d0f0a7 100644
--- a/lib/libc/string/strnstr.c
+++ b/lib/libc/string/strnstr.c
@@ -33,10 +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>
#include <string.h>
/*
diff --git a/lib/libc/string/strpbrk.3 b/lib/libc/string/strpbrk.3
index 2e27c1dda46a..cdccf0da957f 100644
--- a/lib/libc/string/strpbrk.3
+++ b/lib/libc/string/strpbrk.3
@@ -29,8 +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
-.\"
.Dd June 4, 1993
.Dt STRPBRK 3
.Os
diff --git a/lib/libc/string/strpbrk.c b/lib/libc/string/strpbrk.c
index 80ac5ebc4bde..c7dd6c2cff37 100644
--- a/lib/libc/string/strpbrk.c
+++ b/lib/libc/string/strpbrk.c
@@ -29,10 +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>
#include <string.h>
/*
diff --git a/lib/libc/string/strrchr.c b/lib/libc/string/strrchr.c
index cfe6f9270bce..10cb32011cbd 100644
--- a/lib/libc/string/strrchr.c
+++ b/lib/libc/string/strrchr.c
@@ -29,10 +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>
#include <stddef.h>
#include <string.h>
diff --git a/lib/libc/string/strsep.3 b/lib/libc/string/strsep.3
index da9a3e998106..452f646d96d2 100644
--- a/lib/libc/string/strsep.3
+++ b/lib/libc/string/strsep.3
@@ -28,8 +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
-.\"
.Dd May 28, 2018
.Dt STRSEP 3
.Os
diff --git a/lib/libc/string/strsep.c b/lib/libc/string/strsep.c
index a3d64c92ff53..bc7510362f62 100644
--- a/lib/libc/string/strsep.c
+++ b/lib/libc/string/strsep.c
@@ -29,10 +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>
#include <string.h>
#include <stdio.h>
diff --git a/lib/libc/string/strsignal.c b/lib/libc/string/strsignal.c
index 5abe7b37ed99..b99da800cee9 100644
--- a/lib/libc/string/strsignal.c
+++ b/lib/libc/string/strsignal.c
@@ -29,10 +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>
#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 ce43693d0871..3c87afaed1d9 100644
--- a/lib/libc/string/strspn.3
+++ b/lib/libc/string/strspn.3
@@ -29,8 +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
-.\"
.Dd May 24, 2014
.Dt STRSPN 3
.Os
diff --git a/lib/libc/string/strspn.c b/lib/libc/string/strspn.c
index a9df4da92cbe..5f046cf4e66b 100644
--- a/lib/libc/string/strspn.c
+++ b/lib/libc/string/strspn.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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 7ff9ec8c54e1..8957388db535 100644
--- a/lib/libc/string/strstr.3
+++ b/lib/libc/string/strstr.3
@@ -30,8 +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
-.\"
.Dd October 11, 2001
.Dt STRSTR 3
.Os
diff --git a/lib/libc/string/strstr.c b/lib/libc/string/strstr.c
index f3658805996b..90f8bc701e0f 100644
--- a/lib/libc/string/strstr.c
+++ b/lib/libc/string/strstr.c
@@ -22,7 +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>
#include <stdint.h>
#include <string.h>
diff --git a/lib/libc/string/strtok.3 b/lib/libc/string/strtok.3
index c9bfd1988888..e905b655b024 100644
--- a/lib/libc/string/strtok.3
+++ b/lib/libc/string/strtok.3
@@ -41,8 +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
-.\"
.Dd January 22, 2016
.Dt STRTOK 3
.Os
diff --git a/lib/libc/string/strtok.c b/lib/libc/string/strtok.c
index 1ff7a3aa45fc..fb22913505ba 100644
--- a/lib/libc/string/strtok.c
+++ b/lib/libc/string/strtok.c
@@ -34,10 +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>
#include <stddef.h>
#ifdef DEBUG_STRTOK
#include <stdio.h>
diff --git a/lib/libc/string/strxfrm.3 b/lib/libc/string/strxfrm.3
index a28a4fb2ffa3..15964c72a04d 100644
--- a/lib/libc/string/strxfrm.3
+++ b/lib/libc/string/strxfrm.3
@@ -29,8 +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
-.\"
.Dd June 4, 1993
.Dt STRXFRM 3
.Os
diff --git a/lib/libc/string/strxfrm.c b/lib/libc/string/strxfrm.c
index d9f3d0a7b6d5..e327aaf1c2ff 100644
--- a/lib/libc/string/strxfrm.c
+++ b/lib/libc/string/strxfrm.c
@@ -33,7 +33,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
diff --git a/lib/libc/string/swab.3 b/lib/libc/string/swab.3
index 55b3acc6aad4..050cab6c4dd6 100644
--- a/lib/libc/string/swab.3
+++ b/lib/libc/string/swab.3
@@ -25,8 +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
-.\"
.Dd March 4, 2012
.Dt SWAB 3
.Os
diff --git a/lib/libc/string/swab.c b/lib/libc/string/swab.c
index c239808291f0..ed4436a49810 100644
--- a/lib/libc/string/swab.c
+++ b/lib/libc/string/swab.c
@@ -1,62 +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>
#include <unistd.h>
+#include <sys/endian.h>
void
swab(const void * __restrict from, void * __restrict to, ssize_t len)
{
- unsigned char temp;
- size_t n;
- const unsigned char *fp;
- unsigned char *tp;
+ const uint16_t *f __aligned(1) = from;
+ uint16_t *t __aligned(1) = to;
- if (len <= 0)
- return;
- n = (size_t)len >> 1;
- fp = (const unsigned char *)from;
- tp = (unsigned 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 d3a4ce004757..52c7be7410ef 100644
--- a/lib/libc/string/timingsafe_bcmp.3
+++ b/lib/libc/string/timingsafe_bcmp.3
@@ -87,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 145b02b74b09..c3a595a18695 100644
--- a/lib/libc/string/timingsafe_bcmp.c
+++ b/lib/libc/string/timingsafe_bcmp.c
@@ -15,7 +15,6 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/cdefs.h>
#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 446a8a6cb2c3..97a146e06a2b 100644
--- a/lib/libc/string/timingsafe_memcmp.c
+++ b/lib/libc/string/timingsafe_memcmp.c
@@ -15,7 +15,6 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/cdefs.h>
#include <limits.h>
#include <string.h>
diff --git a/lib/libc/string/wcpcpy.c b/lib/libc/string/wcpcpy.c
index 22c623bef320..2ae014b31d29 100644
--- a/lib/libc/string/wcpcpy.c
+++ b/lib/libc/string/wcpcpy.c
@@ -31,14 +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>
#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 4249f8bd24aa..e89facfeb642 100644
--- a/lib/libc/string/wcpncpy.c
+++ b/lib/libc/string/wcpncpy.c
@@ -26,11 +26,12 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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 50949ff38744..0132966fe0cf 100644
--- a/lib/libc/string/wcscasecmp.c
+++ b/lib/libc/string/wcscasecmp.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <wchar.h>
#include <wctype.h>
diff --git a/lib/libc/string/wcscat.c b/lib/libc/string/wcscat.c
index 3599e562e9b4..98e088100a87 100644
--- a/lib/libc/string/wcscat.c
+++ b/lib/libc/string/wcscat.c
@@ -35,9 +35,10 @@ __RCSID("$NetBSD: wcscat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
#endif /* LIBC_SCCS and not lint */
#endif
#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 24c150ad17b4..356f8025c317 100644
--- a/lib/libc/string/wcschr.c
+++ b/lib/libc/string/wcschr.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <wchar.h>
wchar_t *
diff --git a/lib/libc/string/wcscmp.c b/lib/libc/string/wcscmp.c
index ed02db771704..66e08ff782a7 100644
--- a/lib/libc/string/wcscmp.c
+++ b/lib/libc/string/wcscmp.c
@@ -32,13 +32,9 @@
* 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 */
+
+/* $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 9c0a8037e384..620787861f3a 100644
--- a/lib/libc/string/wcscoll.3
+++ b/lib/libc/string/wcscoll.3
@@ -28,8 +28,6 @@
.\" 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
.\"
.Dd October 4, 2002
diff --git a/lib/libc/string/wcscoll.c b/lib/libc/string/wcscoll.c
index b7720c4069d1..e9394a83f60c 100644
--- a/lib/libc/string/wcscoll.c
+++ b/lib/libc/string/wcscoll.c
@@ -32,7 +32,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
diff --git a/lib/libc/string/wcscpy.c b/lib/libc/string/wcscpy.c
index 622e4201f84b..d4aed8721bb8 100644
--- a/lib/libc/string/wcscpy.c
+++ b/lib/libc/string/wcscpy.c
@@ -35,9 +35,10 @@ __RCSID("$NetBSD: wcscpy.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
#endif /* LIBC_SCCS and not lint */
#endif
#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/wcsdup.c b/lib/libc/string/wcsdup.c
index 9aa088d3315f..517acfa7ec49 100644
--- a/lib/libc/string/wcsdup.c
+++ b/lib/libc/string/wcsdup.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <stdlib.h>
#include <wchar.h>
diff --git a/lib/libc/string/wcslcat.c b/lib/libc/string/wcslcat.c
index 336947e3cd23..f74ce520b6a7 100644
--- a/lib/libc/string/wcslcat.c
+++ b/lib/libc/string/wcslcat.c
@@ -37,6 +37,7 @@ __RCSID("$NetBSD: wcslcat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
#endif
#include <sys/types.h>
#include <wchar.h>
+#include <ssp/ssp.h>
/*
* Appends src to string dst of size siz (unlike wcsncat, siz is the
@@ -46,7 +47,7 @@ __RCSID("$NetBSD: wcslcat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
* 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 920425bb5efc..82269656b985 100644
--- a/lib/libc/string/wcslcpy.c
+++ b/lib/libc/string/wcslcpy.c
@@ -37,6 +37,7 @@ __RCSID("$NetBSD: wcslcpy.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
#endif
#include <sys/types.h>
#include <wchar.h>
+#include <ssp/ssp.h>
/*
* Copy src to string dst of size siz. At most siz-1 characters
@@ -44,7 +45,7 @@ __RCSID("$NetBSD: wcslcpy.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
* 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/wcsncasecmp.c b/lib/libc/string/wcsncasecmp.c
index 1b6772152f4a..0cd9f16796fa 100644
--- a/lib/libc/string/wcsncasecmp.c
+++ b/lib/libc/string/wcsncasecmp.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <wchar.h>
#include <wctype.h>
diff --git a/lib/libc/string/wcsncat.c b/lib/libc/string/wcsncat.c
index 004391423f53..5b36fd40bb4f 100644
--- a/lib/libc/string/wcsncat.c
+++ b/lib/libc/string/wcsncat.c
@@ -35,9 +35,11 @@ __RCSID("$NetBSD: wcsncat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
#endif /* LIBC_SCCS and not lint */
#endif
#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 a7b2189d5fb9..141e42c3087f 100644
--- a/lib/libc/string/wcsncmp.c
+++ b/lib/libc/string/wcsncmp.c
@@ -29,13 +29,8 @@
* 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
+/* $NetBSD: wcsncmp.c,v 1.3 2001/01/05 12:13:13 itojun Exp $ */
+
#include <wchar.h>
int
diff --git a/lib/libc/string/wcsncpy.c b/lib/libc/string/wcsncpy.c
index 16e3eb899b84..2491dadadfa4 100644
--- a/lib/libc/string/wcsncpy.c
+++ b/lib/libc/string/wcsncpy.c
@@ -32,20 +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>
#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 3c500855eb1f..1dfc2d5ef913 100644
--- a/lib/libc/string/wcsnlen.c
+++ b/lib/libc/string/wcsnlen.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <wchar.h>
size_t
diff --git a/lib/libc/string/wcsrchr.c b/lib/libc/string/wcsrchr.c
index 60f56551aaac..1679d808be2b 100644
--- a/lib/libc/string/wcsrchr.c
+++ b/lib/libc/string/wcsrchr.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <wchar.h>
wchar_t *
diff --git a/lib/libc/string/wcsstr.c b/lib/libc/string/wcsstr.c
index ff8739f1c75a..beb5e8931742 100644
--- a/lib/libc/string/wcsstr.c
+++ b/lib/libc/string/wcsstr.c
@@ -32,12 +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>
#include <wchar.h>
/*
diff --git a/lib/libc/string/wcstok.c b/lib/libc/string/wcstok.c
index 65312db85b56..839a650ce316 100644
--- a/lib/libc/string/wcstok.c
+++ b/lib/libc/string/wcstok.c
@@ -34,7 +34,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <wchar.h>
wchar_t *
diff --git a/lib/libc/string/wcswidth.c b/lib/libc/string/wcswidth.c
index 84e9af602801..b6f3abd761eb 100644
--- a/lib/libc/string/wcswidth.c
+++ b/lib/libc/string/wcswidth.c
@@ -42,7 +42,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <wchar.h>
#include "xlocale_private.h"
diff --git a/lib/libc/string/wcsxfrm.3 b/lib/libc/string/wcsxfrm.3
index 45e197ef8a83..8fca7c1b62df 100644
--- a/lib/libc/string/wcsxfrm.3
+++ b/lib/libc/string/wcsxfrm.3
@@ -28,8 +28,6 @@
.\" 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
.\"
.Dd October 4, 2002
diff --git a/lib/libc/string/wcsxfrm.c b/lib/libc/string/wcsxfrm.c
index 6e4d7534828b..8c6c542c9255 100644
--- a/lib/libc/string/wcsxfrm.c
+++ b/lib/libc/string/wcsxfrm.c
@@ -33,7 +33,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
diff --git a/lib/libc/string/wmemchr.3 b/lib/libc/string/wmemchr.3
index 4466a7e9b1b4..c1701facb7d5 100644
--- a/lib/libc/string/wmemchr.3
+++ b/lib/libc/string/wmemchr.3
@@ -31,9 +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
-.\"
-.Dd July 14, 2021
+.Dd March 21, 2024
.Dt WMEMCHR 3
.Os
.Sh NAME
@@ -82,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/wmemcpy.c b/lib/libc/string/wmemcpy.c
index f692a25fc95b..9db16fe77a69 100644
--- a/lib/libc/string/wmemcpy.c
+++ b/lib/libc/string/wmemcpy.c
@@ -36,9 +36,11 @@ __RCSID("$NetBSD: wmemcpy.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
#endif
#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 cbbdb4afdd6c..837dbe12dc7a 100644
--- a/lib/libc/string/wmemmove.c
+++ b/lib/libc/string/wmemmove.c
@@ -36,9 +36,10 @@ __RCSID("$NetBSD: wmemmove.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
#endif
#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 a21621de3977..152bb76c7e80 100644
--- a/lib/libc/string/wmempcpy.c
+++ b/lib/libc/string/wmempcpy.c
@@ -28,12 +28,13 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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 4276373399f9..60fb14b6a4af 100644
--- a/lib/libc/string/wmemset.c
+++ b/lib/libc/string/wmemset.c
@@ -35,9 +35,10 @@ __RCSID("$NetBSD: wmemset.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
#endif /* LIBC_SCCS and not lint */
#endif
#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;