aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/string
Commit message (Collapse)AuthorAgeFilesLines
* libc/string: add strdupa(3) and strndupa(3)Konstantin Belousov2025-12-162-2/+36
| | | | (cherry picked from commit a98e5d78500193dc7aa352e1f60ac2c6529e2c38)
* ffs.3: Fix an accidentally committed merge left overGordon Bergling2025-10-301-3/+0
| | | | | | Fix an accidentally committed merge left over. Fixes: 38a172d3c6b7 ("ffs.3: Add a STANDARDS section to the manual page")
* ffs.3: Add a STANDARDS section to the manual pageGordon Bergling2025-10-301-1/+13
| | | | | | | | | | The ffs() function conforms to IEEE Std 1003.1-2008 ("POSIX.1"). The ffsl() and ffsll() functions conform to IEEE Std 1003.1-2024 ("POSIX.1"). Reviewed by: ziaee Differential Revision: https://reviews.freebsd.org/D53352 (cherry picked from commit f1cb4e9962d715ec85ba26d7019ab83adea1ffb7)
* memcmp.3: Clarify return valueEd Maste2025-07-291-18/+25
| | | | | | | | | | | | The return value is not required to be the difference between the differing bytes, only less than zero, zero, or greater than zero. Reviewed by: fuz Event: Kitchener-Waterloo Hackathon 202406 Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D47683 (cherry picked from commit 5cc53d79655bf7f67b1a794c088d896aa6475c2e)
* memchr.3: mention the len argument in the functions descriptionKonstantin Belousov2025-07-251-5/+11
| | | | (cherry picked from commit 441995e161a2564d37947d054a2f1219754deb5f)
* manuals: Align our tree with upstream C23 macroAlexander Ziaee2025-07-141-1/+1
| | | | | | | | | Switch all instances of the -isoC-2024 macro to -isoC-2023 selected by upstream. Keep -isoC-2024 defined, but deprecated, for backwards compat. MFC after: 3 days (resolved merge conflicts w/ cdefs and memccpy.3) (cherry picked from commit 1b6936e125382523509901a4fc5b2932ed0e742d)
* contrib/mandoc: add -isoC-2024 and -svid1 to mdoc(7)Robert Clausecker2025-07-141-4/+2
| | | | | | | | | | C23 (ISO/IEC 9899:2024) is not out yet, but will be shortly. SVID1 is needed for the history section of memccpy(3). Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D47284 (cherry picked from commit 7ed159c6cc00adf6f75f9a43024f23509f5b8e5e)
* libc: indicate existing functions that are POSIX 2024Ed Maste2024-11-211-3/+3
| | | | | | | | Reviewed by: brooks, imp Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D47581 (cherry picked from commit dfa0ac74c2fbc1cde3e8cdb1ab9fe5cbb90a9b16)
* manuals: Fix "unusual .Xr" warnings with a scriptGraham Percival2024-11-041-1/+0
| | | | | | | | | | | | | | | These were reported by `mandoc -T lint ...` as warnings: - unusual Xr order - unusual Xr punctuation Fixes made by script in https://github.com/Tarsnap/freebsd-doc-scripts Signed-off-by: Graham Percival <gperciva@tarsnap.com> Reviewed by: mhorne, Alexander Ziaee <concussious.bugzilla@runbox.com> Sponsored by: Tarsnap Backup Inc. Pull Request: https://github.com/freebsd/freebsd-src/pull/1464 (cherry picked from commit 6e1fc0118033f42b7c0d3623c8f67a89ebecabb2)
* libc: make strerror_rl() usable for libcKonstantin Belousov2024-04-301-5/+5
| | | | (cherry picked from commit 92771bc00ad0f567b27876c34450bef7a0ee61d0)
* wmemchr(3): fix prototypes for wcpcpy() and wcpncpy()Konstantin Belousov2024-03-241-3/+3
| | | | | | PR: 277855 (cherry picked from commit 69d5783ae81b74295118950d01b6dddb3e504a56)
* lib/libc/string: document restrict qualification of memccpy() argumentsRobert Clausecker2024-01-243-6/+39
| | | | | | | | | | | | | | | POSIX.1-2004 and the upcoming C23 agree that memccpy()'s arguments are restrict qualified and must not overlap. In 2002, restrict qualifiers were added to <string.h>'s declaration of the function. Make things official and document that the arguments must not overlap. See also: 61b60edfd3fff20f884419f8097870c7045315c9 Approved by: kib MFC after: 1 month MFC to: stable/14 (cherry picked from commit e0d4f419ac41aa91b862f3ceadc32a86abf08572)
* libc: Remove empty comments in Symbol.mapBrooks Davis2023-12-131-3/+0
| | | | | | | | | These were left over from $FreeBSD$ removal. Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D42612 (cherry picked from commit 1ca63a8219b88b752b064d19bd3428c61dbcf1f9)
* libc: Purge unneeded cdefs.hWarner Losh2023-11-2767-67/+0
| | | | | | | | | | | These sys/cdefs.h are not needed. Purge them. They are mostly left-over from the $FreeBSD$ removal. A few in libc are still required for macros that cdefs.h defines. Keep those. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D42385 (cherry picked from commit 559a218c9b257775fb249b67945fe4a05b7a6b9f)
* Add a HISTORY section for memcpy(3) and mempcpy(3)Gordon Bergling2023-11-251-2/+13
| | | | | | | | | | | The memcpy() function first appeared in AT&T System V UNIX and was reimplemented for 4.3BSD-Tahoe. The mempcpy() function first appeared in FreeBSD 13.1. PR: 272227 Differential Revision: https://reviews.freebsd.org/D42630 (cherry picked from commit 8c8ffe541eabb23e21ddffb534ecda7ac6d7e04a)
* */string.3,arch.7,environ.7: add cross-references to simd(7)Robert Clausecker2023-09-081-2/+3
| | | | | | | | | | | | | With the new simd-dispatch framework documented in simd(7), add cross-references to the new man pages to appropriate places. Sponsored by: The FreeBSD Foundation Approved by: emaste MFC to: stable/14 MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D41697 (cherry picked from commit d41afb814612ce005d93d2f8d127dcf6ea751cc4)
* libc: fix history for strverscmp(3) and versionsort(3)Mina Galić2023-09-031-2/+2
| | | | | | | PR: 273401 Approved by: re (gjb) (cherry picked from commit 09ec5e67a7a6605e5a58a2e3e82dab243a90609a)
* Document strnstr()'s history.David E. O'Brien2023-08-221-0/+6
|
* Remove $FreeBSD$: one-line nroff patternWarner Losh2023-08-1632-32/+0
| | | | Remove /^\.\\"\s*\$FreeBSD\$$\n/
* Remove $FreeBSD$: two-line nroff patternWarner Losh2023-08-166-12/+0
| | | | Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-161-1/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-1683-166/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* Remove $FreeBSD$: one-line .h patternWarner Losh2023-08-161-1/+0
| | | | Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-161-2/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* lib/libc/string/bcmp.c: fix integer overflow bugRobert Clausecker2023-07-161-2/+2
| | | | | | | | | | | | | | | | | bcmp() returned the number of remaining bytes when the main loop exits. In case of a match, this is zero, else a positive integer. On systems where SIZE_MAX > INT_MAX, the implicit conversion from size_t to int in the return value may cause the number of remaining bytes to overflow, becoming zero and falsely indicating a successful comparison. Fix the bug by always returning 0 on equality, 1 otherwise. PR: 272474 Approved by: emaste Reviewed by: imp MFC After: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D41011
* lib/libc/string/ffs*.c: work around gcc warningRobert Clausecker2023-07-143-3/+3
| | | | | | | | | | | | | | | Gcc warns of infinite recursion if we use __builtin_ffs*() to implement ffs*(). This is because gcc uses ffs() to implement these on some platforms. Sidestep the warning by using __builtin_ctz*() for these. Sponsored by: FreeBSD Foundation Reported by: jlduran@gmail.com, jhb Fixes: ee8b0c43 (D40730) Reviewed by: jhb, mhorne Approved by: jhb MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D40966
* lib/libc/string: replace ffs/fls implementations with clang builtinsRobert Clausecker2023-07-036-42/+34
| | | | | | | | | | | | | | Most architectures we support (except for riscv64) have instructions to compute these functions very quickly. Replace old code with the ffs and clz builtin functions, allowing clang to generate good code for all architectures. As a consequence, toss out arm and i386 ffs() implementations. Sponsored by: FreeBSD Foundation Approved by: mhorne MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D40730
* Correctly spell illumos (all lowercase) in man pagesYuri Pankov2023-06-291-2/+2
| | | | | | From illumos FAQ: "illumos (pronounced i-llu-MOS and written in lowercase)"
* Correct man page URI formatting.David E. O'Brien2023-06-101-2/+1
| | | | | Don't format URL's embedding a ',' where one doesn't exist; so that one may copy-n-paste the displayed URL into a browser.
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-1219-19/+19
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* memmem: add a note about other systems which have memmemEd Maste2023-03-301-2/+3
| | | | | | | | memmem started as a GNU extension but is now widely available. Reviewed by: mhorne (slightly earlier version) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D39337
* Fix truncation when ssize_t is larger than MAX_INTAlfonso2023-02-051-6/+7
| | | | | | | | | | | | | | Casting to int truncates size on some platforms, resulting swab not copying all the data. Cast len to size_t to avoid right shifting a signed value: we know here it's > 0, so we can safely cast it w/o losing precision. In addition, be more careful with signedness of char pointers and temporaries. Downgrade tmp from unsigned long to unsigned char since we're only reading and writing characters. Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/516
* libc: Fix build with WITHOUT_MACHDEP_OPTIMIZATIONS=YES set.Gleb Popov2023-01-101-1/+6
| | | | | | | | | | Test Plan: `make buildword WITHOUT_MACHDEP_OPTIMIZATIONS=YES` on 14-CURRENT and 13-STABLE Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D38017 PR: 266900
* libc: Add strverscmp(3) and versionsort(3)Aymeric Wibo2022-08-254-2/+150
| | | | | | | | | | | | | | | Add a strverscmp(3) function to libc, a GNU extension I implemented by reading its glibc manual page. It orders strings following a much more natural ordering (e.g. "ent1 < ent2 < ent10" as opposed to "ent1 < ent10 < ent2" with strcmp(3)'s lexicographic ordering). Also add versionsort(3) for use as scandir(3)'s compar argument. Update manual page for scandir(3) and add one for strverscmp(3). Reviewed by: pstef, gbe, kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D35807
* libc: drop "All rights reserved" from Foundation copyrightsEd Maste2022-08-049-9/+7
| | | | | | | | | This has already been done for most files that have the Foundation as the only listed copyright holder. Do it now for files that list multiple copyright holders, but have the Foundation copyright in its own section. Sponsored by: The FreeBSD Foundation
* libc: Add HISTORY sections to the manual pagesGordon Bergling2022-05-053-3/+29
| | | | | | | | | | There are some sections which could be improved and work to do so is on going. The work will be covered via 'X-MFC-WITH' commits. Obtained from: OpenBSD MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D34759
* libc: correct SPDX tag on strstr.cEd Maste2022-01-161-1/+1
| | | | | | | It was obtained from musl, and is MIT licensed. MFC after: 3 days Sponsored by: The FreeBSD Foundation
* libc: fix misleading comment in strstrEd Maste2022-01-161-1/+1
| | | | Obtained from: musl c53e9b239418
* memcpy.3: remove BUGS section allowing overlapping stringsEd Maste2021-08-241-16/+0
| | | | | | | | | | | | | | | The removed text claimed that memcpy is implemented using bcopy and thus strings may overlap. Use of bcopy is an implementation detail that is no longer true, even if the implementation (on some archs) does allow overlap. In any case behaviour is undefined per the C standard if memcpy is called with overlapping objects, and this man page already claimed that src and dst may not overlap. Reviewed by: kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D31192
* libc: Disable ASAN for certain string functionsAlex Richardson2021-08-021-0/+9
| | | | | | | | | | They deliberately read out-of-bounds values to avoid byte-by-byte loads and check multiple bytes at once. While this will work on x86, it is flagged as an out-of-bounds read with ASAN, so we have to disable instrumentation here. This also causes bounds errors for CHERI, so in CheriBSD we use implementations that avoid OOB reads. Differential Revision: https://reviews.freebsd.org/D31045
* libc: add mempcpy(3) and wmempcpy(3)Konstantin Belousov2021-07-156-9/+114
| | | | | | | Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D31180
* Change strmode argument type to mode_tAlfonso Gregory2021-06-291-1/+1
| | | | | | | | Finally, we have the correct function definition for strmode. NetBSD/OpenBSD did this many years ago. This code is weird sign extension safe. Reviewed by: imp@ Pull Request: https://github.com/freebsd/freebsd-src/pull/493
* libc/string/memset.c: Use unsigned long for storesAlex Richardson2021-04-201-8/+11
| | | | | | | | | | While most 64-bit architectures have an assembly implementation of this file, RISC-V does not. As we now store 8 bytes instead of 4 it should speed up RISC-V. Reviewed By: kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D29536
* libc/string/bcopy.c: Use intptr_t as the copy typeAlex Richardson2021-04-201-7/+5
| | | | | | | | | | | | | While most 64-bit architectures have an assembly implementation of this file RISC-V does not. As we now copy 8 bytes instead of 4 it should speed up RISC-V. Using intptr_t instead of int also allows using this file for CHERI pure-capability code since trying to copy pointers using integer loads/stores will invalidate pointers. Reviewed By: kib Obtained from: CheriBSD (partially) MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D29535
* libc: Use musl's optimized strchr and strchrnulEd Maste2021-03-022-73/+67
| | | | | | | | | | | | Parentheses added to HASZERO macro to avoid a GCC warning, and formatted with clang-format as we have adopted these and don't consider them 'contrib' code. Obtained from: musl (snapshot at commit 4d0a82170a25) Reviewed by: kib (libc integration), mjg (both earlier) MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D17630
* Remove __NO_TLS.Konstantin Belousov2021-02-231-5/+0
| | | | | | | | | All supported platforms support thread-local vars and __thread. Reviewed by: emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D28796
* Restore the augmented strlen commentaryMateusz Guzik2021-02-081-11/+4
| | | | ... lost in revert
* Revert "Reimplement strlen"Mateusz Guzik2021-02-031-28/+54
| | | | | | | | | This reverts commit 710e45c4b8539d028877769f1a4ec088c48fb5f1. It breaks for some corner cases on big endian ppc64. Given the stage of the release process it is best to revert for now. Reported by: jhibbits
* Reimplement strlenMateusz Guzik2021-01-291-54/+28
| | | | | | | | | | | | | | | | | | | | | | | The previous code neglected to use primitives which can find the end of the string without having to branch on every character. While here augment the somewhat misleading commentary -- strlen as implemented here leaves performance on the table, especially so for userspace. Every arch should get a dedicated variant instead. In the meantime this commit lessens the problem. Tested with glibc test suite. Naive test just calling strlen in a loop on Haswell (ops/s): $(perl -e "print 'A' x 3"): before: 211198039 after: 338626619 $(perl -e "print 'A' x 100"): before: 83151997 after: 98285919
* strerror.3: Fix whitespace issue introduced in r368714Jessica Clarke2020-12-181-1/+1
| | | | | | | MFC with: 368714 Notes: svn path=/head/; revision=368770