summaryrefslogtreecommitdiff
path: root/include/string.h
AgeCommit message (Collapse)Author
2025-12-09libc/string: add strdupa(3) and strndupa(3)Konstantin Belousov
Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54066
2025-03-20Revert Make newly POSIX functions visibleStephen Hurd
Summary: This reverts commit d7efac1be1441c122f7fb9de51a409172f21326c. This reverts commit 9d0eea9422d075c8a6924b33161d2d5abfb4072a. Some ports (specifically Python) define __BSD_VISIBLE themselves, so the change from __BSD_VISIBLE to __POSIX_VISIBLE >= 202405 makes them fail. Reported by: jrtc27, cperciva
2025-03-19Make newly POSIX functions visibleStephen Hurd
Some of the POSIX 202405L functions are already in the system, make them visible when appropriate. Reviewed by: imp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D47859
2024-12-01Expose POSIX functions incorporated into C23Stephen Hurd
C23 has incoporated a small number of POSIX functions, so these should be exposed for C23, regardless of POSIX. Reviewed by: imp, emaste Differential Revision: https://reviews.freebsd.org/D47856
2024-11-14lib/libc/string: add memset_explicit() for compliance with C23Robert Clausecker
Patterned after explicit_bzero, visible from C23 onwards. Reviewed by: emaste, kevans Differential Revision: https://reviews.freebsd.org/D47286
2024-07-16include: ssp: don't shadow the mempcpy builtinKyle Evans
GCC emits a warning about shadowing a builtin with our mempcpy declaration, so switch it to using the same model as memcpy() and use the apparently-existing __builtin___mempcpy_chk(). Reviewed by: kib (earlier version), markj Sponsored by: Klara, Inc. Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D45976
2024-07-13include: ssp: round out fortification of current set of headersKyle Evans
ssp/ssp.h needed some improvements: - `len` isn't always a size_t, it may need casted - In some cases we may want to use a len that isn't specified as a parameter (e.g., L_ctermid), so __ssp_redirect() should be more flexible. - In other cases we may want additional checking, so pull all of the declaration bits out of __ssp_redirect_raw() so that some functions can implement the body themselves. strlcat/strlcpy should be the last of the fortified functions that get their own __*_chk symbols, and these cases are only done to be consistent with the rest of the str*() set. Reviewed by: markj Sponsored by: Klara, Inc. Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D45679
2024-05-14ssp: appease -Wgnu-statement-expression-from-macro-expansionKyle Evans
It's a stupid warning, but some ports enable it by default and were already defining _FORTIFY_SOURCE, thus exposing the new macros immediately. This at least fixes the libfido2 build, perhaps others as well. While we're here, fix a fresh build of stand w/ FORTIFY_SOURCE enabled by not pulling in the ssp headers if _STANDALONE is defined. We do not have runtime support in libsa as of the time of writing. Reported by: netchild Sponsored by: Stormshield Sponsored by: Klara, Inc.
2024-05-13Add a build knob for _FORTIFY_SOURCEKyle Evans
In the future, we will Default to _FORTIFY_SOURCE=2 if SSP is enabled, otherwise default to _FORTIFY_SOURCE=0. For now we default it to 0 unconditionally to ease bisect across older versions without the new symbols, and we'll put out a call for testing. include/*.h include their ssp/*.h equivalents as needed based on the knob. Programs and users are allowed to override FORTIFY_SOURCE in their Makefiles or src.conf/make.conf to force it off. Reviewed by: des, markj Relnotes: yes Sponsored by: Stormshield Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D32308
2023-11-26include: Remove ancient SCCS tags.Warner Losh
Remove ancient SCCS tags from the tree, automated scripting, with two minor fixup to keep things compiling. All the common forms in the tree were removed with a perl script. Sponsored by: Netflix
2023-08-16Remove $FreeBSD$: one-line .h patternWarner Losh
Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
2022-08-25libc: Add strverscmp(3) and versionsort(3)Aymeric Wibo
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
2021-07-15libc: add mempcpy(3) and wmempcpy(3)Konstantin Belousov
Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D31180
2021-06-29Change strmode argument type to mode_tAlfonso Gregory
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
2020-12-17Change POSIX compliance level for visibility of strerror_l(3).Konstantin Belousov
Third-party code tests for strerror_l(3) without specifying _POSIX_SOURCE, and then expects that the function is prototyped with _POSIX_SOURCE set to 200112. Reported and tested by: antoine Sponsored by: The FreeBSD Foundation MFC after: 13 days Notes: svn path=/head/; revision=368723
2017-11-20include: further adoption of SPDX licensing ID tags.Pedro F. Giffuni
Mainly focus on files that use BSD 3-Clause license. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point. Notes: svn path=/head/; revision=326024
2017-03-30Implement the memset_s(3) function as specified by the C11 ISO/IECKonstantin Belousov
9899:2011 Appendix K 3.7.4.1. Other needed supporting types, defines and constraint_handler infrastructure is added as specified in the C11 spec. Submitted by: Tom Rix <trix@juniper.net> Sponsored by: Juniper Networks Discussed with: ed MFC after: 3 weeks Differential revision: https://reviews.freebsd.org/D9903 Differential revision: https://reviews.freebsd.org/D10161 Notes: svn path=/head/; revision=316213
2016-08-14Add timingsafe_bcmp and timingsafe_memcmp.Xin LI
Obtained from: OpenBSD Reviewed by: trasz MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D7280 Notes: svn path=/head/; revision=304106
2014-05-11include: Remove checks for __BSD_VISIBLE where redundant with __XSI_VISIBLEJilles Tjoelker
or __POSIX_VISIBLE. Whenever <sys/cdefs.h> sets __BSD_VISIBLE to non-zero, it also sets __POSIX_VISIBLE and __XSI_VISIBLE to the newest version supported. No functional change is intended. Notes: svn path=/head/; revision=265878
2013-02-14FreeBSD uses #if __BSD_VISIBLE to hide non-standard functions, fix this.Niclas Zeising
Noticed by: kib Approved by: kib Notes: svn path=/head/; revision=246803
2013-02-13Add strchrnul(), a GNU function similar to strchr(), except that it returnsNiclas Zeising
a pointer to the end of the string, rather than NULL, if the character was not found. Approved by: theraven Notes: svn path=/head/; revision=246766
2012-03-28Correctly expose xlocale functions if people include the headers in the wrongDavid Chisnall
order (as some ports apparently do). Approved by: dim (mentor) Notes: svn path=/head/; revision=233600
2012-03-04Reapply 227753 (xlocale cleanup), plus some fixes so that it passes buildDavid Chisnall
universe with gcc. Approved by: dim (mentor) Notes: svn path=/head/; revision=232498
2012-02-14Revert r231673 and r231682 for now, until we can run a full makeDimitry Andric
universe with them. Sorry for the breakage. Pointy hat to: me and brooks Notes: svn path=/head/; revision=231714
2012-02-14Cleanup of xlocale:David Chisnall
- Address performance regressions encountered by das@ by caching per-thread data in TLS where available. - Add a __NO_TLS flag to cdefs.h to indicate where not available. - Reorganise the xlocale.h definitions into xlocale/*.h so that they can be included from multiple places. - Export the POSIX2008 subset of xlocale when POSIX2008 says it should be exported, independently of whether xlocale.h is included. - Fix the bug where programs using ctype functions always assumed ASCII unless recompiled. - Fix some style(9) violations. Reviewed by: brooks (mentor) Approved by: dim (mentor) Notes: svn path=/head/; revision=231673
2010-02-16Remove the Berkeley clause 3's.Warner Losh
Add a few $FreeBSD$ Notes: svn path=/head/; revision=203964
2009-03-14Namespace: memccpy() and memchr() are XSI, and memrchr() is a BSD extension.David Schultz
Notes: svn path=/head/; revision=189809
2009-02-28- Add getdelim(), getline(), stpncpy(), strnlen(), wcsnlen(),David Schultz
wcscasecmp(), and wcsncasecmp(). - Make some previously non-standard extensions visible if POSIX_VISIBLE >= 200809. - Use restrict qualifiers in stpcpy(). - Declare off_t and size_t in stdio.h. - Bump __FreeBSD_version in case the new symbols (particularly getline()) cause issues with ports. Reviewed by: standards@ Notes: svn path=/head/; revision=189136
2009-02-28Add restrict qualifiers to the parameters to strlcpy() and strlcat().David Schultz
The annotation mainly just serves as a hint that they're not intended for use with overlapping strings. Notes: svn path=/head/; revision=189133
2009-02-28Mark memmem() __pure.David Schultz
Notes: svn path=/head/; revision=189132
2009-01-31Add a function attribute called `__malloc_like', which informs gccDavid Schultz
that the annotated function returns a pointer that doesn't alias any extant pointer. This results in a 50%+ speedup in microbenchmarks such as the following: char *cp = malloc(1), *buf = malloc(BUF); for (i = 0; i < BUF; i++) buf[i] = *cp; In real programs, your mileage will vary. Note that gcc already performs this optimization automatically for any function called `malloc', `calloc', `strdup', or `strndup' unless -fno-builtins is used. Notes: svn path=/head/; revision=187961
2008-12-08Add strndup(3) prototype to string.h.Konstantin Belousov
This change was erronously ommitted from the r185690, and attempt to simply add the prototype to string.h has revealed that several contributed programs defined local prototypes for strndup(), controlled by autoconfed config.h. So, manually change #undef HAVE_STRNDUP to #define HAVE_STRNDUP 1. Next import of the corresponding program would regenerate config.h, overriding the changes in this commit. No objections from: kan Notes: svn path=/head/; revision=185777
2008-04-10Add memrchr(3).Xin LI
Obtained from: OpenBSD Notes: svn path=/head/; revision=178051
2005-11-24Revert last revision, strmode() should be moved to <unistd.h> to beRuslan Ermilov
properly fixed. Notes: svn path=/head/; revision=152754
2005-11-24Fix prototype of strmode() to match the code and documentation.Ruslan Ermilov
Notes: svn path=/head/; revision=152747
2005-08-25Appropriate namespace protection for memmem(3).Andre Oppermann
Submitted by: wollman MFC after: 3 days Notes: svn path=/head/; revision=149469
2005-08-25Add the function memmem(3) as found in glibc and others.Andre Oppermann
It is the binary equivalent to strstr(3). void *memmem(const void *big, size_t big_len, const void *little, size_t little_len); Submitted by: Pascal Gloor <pascal.gloor at spale.com> MFC after: 3 days Notes: svn path=/head/; revision=149466
2004-12-10According to the information on:Tom Rhodes
http://www.opengroup.org/onlinepubs/009695399/functions/swab.html the prototype for swab() should be in <unistd.h> and not in <string.h>. Move it, and update to match SUS. Leave the prototype in string.h for now, for backwards compat. PR: 74751 Submitted by: Craig Rodrigues <rodrigc@crodrigues.org> Discussed with: das Notes: svn path=/head/; revision=138659
2004-07-23Mark functions pure where applicable. A notable exclusion is strcoll(),Tim J. Robbins
which is not strictly pure because it calls malloc()/free() in some cases. Notes: svn path=/head/; revision=132564
2003-12-07Change the definition of NULL on ia64 (for LP64 compilations) fromMarcel Moolenaar
an int constant to a long constant. This change improves consistency in the following two ways: 1. The first 8 arguments are always passed in registers on ia64, which by virtue of the generated code implicitly widens ints to longs and allows the use of an 32-bit integral type for 64-bit arguments. Subsequent arguments are passed onto the memory stack, which does not exhibit the same behaviour and consequently do not allow this. In practice this means that variadic functions taking pointers and given NULL (without cast) work as long as the NULL is passed in one of the first 8 arguments. A SIGSEGV is more likely the result if such would be done for stack-based arguments. This is due to the fact that the upper 4 bytes remain undefined. 2. All 64-bit platforms that FreeBSD supports, with the obvious exception of ia64, allow 32-bit integral types (specifically NULL) when 64-bit pointers are expected in variadic functions by way of how the compiler generates code. As such, code that works correctly (whether rightfully so or not) on any platform other than ia64, may fail on ia64. To more easily allow tweaking of the definition of NULL, this commit removes the 12 definitions in the various headers and puts it in a new header that can be included whenever NULL is to be made visible. This commit fixes GNOME, emacs, xemacs and a whole bunch of ports that I don't particularly care about at this time... Notes: svn path=/head/; revision=123257
2002-10-14Correct visibility conditionals for memccpy(), strdup(), andMike Barcroft
strtok_r(). Merge conditional prototypes into the regular block. Notes: svn path=/head/; revision=105128
2002-10-05Make stpcpy() only visiable w/in __BSD_VISIBLE.David E. O'Brien
Notes: svn path=/head/; revision=104544
2002-10-03Add stpcpy(3).David E. O'Brien
Notes: svn path=/head/; revision=104420
2002-08-21o Merge <machine/ansi.h> and <machine/types.h> into a new headerMike Barcroft
called <machine/_types.h>. o <machine/ansi.h> will continue to live so it can define MD clock macros, which are only MD because of gratuitous differences between architectures. o Change all headers to make use of this. This mainly involves changing: #ifdef _BSD_FOO_T_ typedef _BSD_FOO_T_ foo_t; #undef _BSD_FOO_T_ #endif to: #ifndef _FOO_T_DECLARED typedef __foo_t foo_t; #define _FOO_T_DECLARED #endif Concept by: bde Reviewed by: jake, obrien Notes: svn path=/head/; revision=102227
2002-04-15Add support for X/Open.Mike Barcroft
PR: 37078 Notes: svn path=/head/; revision=94721
2002-04-04o Move some function prototypes from <string.h> to the newly rewrittenMike Barcroft
<strings.h>, based on POSIX.1-2001's requirements. o Add 'restrict' qualifier (spelled '__restrict') to functions in <string.h>, as per C99 and POSIX.1-2001. o Properly expose new POSIX.1-2001 functions in <string.h>. Notes: svn path=/head/; revision=93747
2002-03-23Breath deep and take __P out of the system include files.Warner Losh
# This appears to not break X11, but I'm having problems compiling the # glide part of the server with or without this patch, so I can't tell # for sure. Notes: svn path=/head/; revision=93032
2001-11-28Fixed namespace pollution in previous commit. The C99 functionBruce Evans
sterror_r() must not be declared in the C90/POSIX.1-1990 section. Put it in the nonstandard section for now. Notes: svn path=/head/; revision=87069
2001-11-27Add strerror_r function per Posix prototype.Wes Peters
Reviewed by: Mike Barcroft <mike@FreeBSD.org> MFC after: 2 weeks Notes: svn path=/head/; revision=86944
2001-10-10Fixed some style bugs:Bruce Evans
- rev.1.6: corrupt tab before strlcpy. - rev.1.7: "From: " in vendor id. - rev.1.8: unsorted prototype for strccasestr. Notes: svn path=/head/; revision=84747