aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
Commit message (Collapse)AuthorAgeFilesLines
...
* libc: actually build bsearch_bBrooks Davis2024-03-051-1/+1
| | | | | | | Fixes: 46cdc14062f7 Add support for some block functions ... Reviewed by: theraven Differential Revision: https://reviews.freebsd.org/D44189
* system(3): fix typo santized -> sanitizedSteve Kargl2024-01-121-2/+2
| | | | | PR: 276262 Reviewed by: imp
* strfmon.c: Use the restrict keyword directlyKonstantin Belousov2023-12-101-3/+3
| | | | | | | | libc sources assume C99 or even C11 compiler already, unlike headers. There is no reason to obfuscate the basic C constructs. Sponsored by: The FreeBSD Foundation MFC after: 1 week
* strfmon: style fixesJose Luis Duran2023-12-101-98/+99
| | | | | | | Check style(9) with checkstyle9.pl and clang-format. No functional change intended. MFC after: 1 week
* strfmon: Silence scan-build warningJose Luis Duran2023-12-091-1/+0
| | | | | | | The value stored to 'value' is never read. Reported by: Jenkins (scan-build) MFC after: 1 week
* strfmon.3: Cleanup example codeJose Luis Duran2023-12-091-3/+5
| | | | | | | | | - xlocale.h would have been required if using strfmon_l(). Here, setlocale() just requires locale.h. - ANSIfy function declaration. - Add a final return(). MFC after: 1 week
* lib: Automated cleanup of cdefs and other formattingWarner Losh2023-11-272-5/+0
| | | | | | | | | | | | | | | | Apply the following automated changes to try to eliminate no-longer-needed sys/cdefs.h includes as well as now-empty blank lines in a row. Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/ Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/ Remove /\n+#if.*\n#endif.*\n+/ Remove /^#if.*\n#endif.*\n/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/ Sponsored by: Netflix
* lib: Remove ancient SCCS tags.Warner Losh2023-11-2759-147/+0
| | | | | | | | 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
* libc: Remove empty comments in Symbol.mapBrooks Davis2023-11-152-6/+0
| | | | | | | These were left over from $FreeBSD$ removal. Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D42612
* libc: Purge unneeded cdefs.hWarner Losh2023-11-0154-54/+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
* libc: Fix missing or misspelled MLINKS.Dag-Erling Smørgrav2023-10-181-13/+37
| | | | Differential Revision: https://reviews.freebsd.org/D42192
* memory(3): Mention more functions.Dag-Erling Smørgrav2023-10-181-14/+43
| | | | Differential Revision: https://reviews.freebsd.org/D42191
* ptsname.3: accommodate upcoming POSIX Issue 8 ptsname_rEd Maste2023-10-141-2/+15
| | | | | | | | | | | | | | POSIX has accepted a proposal[1] to add glibc-compatible ptsname_r. It indicates an error by returning the error number, rather than returning -1 and setting errno. Update RETURN VALUES in ptsname_r's man page now to encourage folks to test that the return value != 0 rather than == -1. [1] https://www.austingroupbugs.net/bug_view_page.php?bug_id=508 Reported by: Collin Funk Reviewed by: kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D42204
* libc: Rewrite quick_exit() and at_quick_exit() using C11 atomics.Dag-Erling Smørgrav2023-09-261-24/+16
| | | | | | | | | | | | | Compiler memory barriers do not prevent the CPU from executing the code out of order. Switch to C11 atomics. This also lets us get rid of the mutex; instead, loop until the compare_exchange succeeds. While here, change the return value of at_quick_exit() on failure to the more traditional -1, matching atexit(). Sponsored by: Klara, Inc. Reviewed by: Olivier Certner, kevans, kib Differential Revision: https://reviews.freebsd.org/D41936
* libc: add LIBC_MALLOC optionBrooks Davis2023-09-011-1/+1
| | | | | | | | | | This will enable alternative mallocs to be included in the tree and selected by setting LIBC_MALLOC. As there is only one today (jemalloc) this option does nothing, but we expect to add other implementations in the future. This will also reduce diffs to CheriBSD. Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D41660
* libc: Document support for binary integers.Dag-Erling Smørgrav2023-08-282-2/+6
| | | | | Reviewed by: debdrup, emaste Differential Revision: https://reviews.freebsd.org/D41522
* libc: Implement N2630.Dag-Erling Smørgrav2023-08-286-2/+45
| | | | | | | This adds formatted input/output of binary integer numbers to the printf(), scanf(), and strtol() families, including their wide-character counterparts. Reviewed by: imp, emaste Differential Revision: https://reviews.freebsd.org/D41511
* libc: regoranize malloc buildBrooks Davis2023-08-164-3/+4
| | | | | | | | | | | | | Create a stdlib/malloc to hold the definition of the malloc interface (e.g., the Symbol.map file) and make jemalloc a subdirectory. This will make it easier to integrate alternative allocators such as snmalloc while making it clear that the current jemalloc symbols are the FreeBSD API/ABI (for better or worse). Suggested by: jrtc27 Reviewed by: jrtc27, emaste Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D41457
* jemalloc: drop unused .PATHBrooks Davis2023-08-161-3/+0
| | | | | | | | | All jemalloc sources are in contrib so don't look for them in the jemalloc subdirectory. Reviewed by: jrtc27, emaste Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D41481
* libc: include malloc via stdlib/Makefile.incBrooks Davis2023-08-161-0/+2
| | | | | | | | | | There's a hierarchy here and we should use it. Improves: cbeacb7c46f3a3650e5dbefa9a1a18bc9943a8cc Reviewed by: jrtc27, jhb, emaste Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D41456
* Remove $FreeBSD$: one-line nroff patternWarner Losh2023-08-1629-29/+0
| | | | Remove /^\.\\"\s*\$FreeBSD\$$\n/
* Remove $FreeBSD$: two-line nroff patternWarner Losh2023-08-1614-28/+0
| | | | Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-162-2/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-1658-116/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* Remove $FreeBSD$: one-line .h patternWarner Losh2023-08-163-3/+0
| | | | Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-1611-22/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* libc: unsplit log message to to make it greppable in srcEd Maste2023-08-051-2/+3
| | | | | | | | | Also use __func__ rather than hardcoding the function name. This code now fits in 80 columns without splitting the log message. Reviewed by: zlei Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D39619
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-1211-11/+11
| | | | | | | | | 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
* Revert "libc: Implement bsort(3) a bitonic type of sorting algorithm."Hans Petter Selasky2023-04-206-505/+1
| | | | | | | | | | | | | | | | | | | | | | | | Some points for the future: - libc is not the right place for sorting algorithms. Probably libutil is better suited for this purpose or a dedicated libsort. Should move all sorting algorithms away from libc eventually. - CheriBSD uses capabilities for memory access, and could benefit from a standard memswap() function. - Do something about qsort() in FreeBSD's libc like: - Mark it deprecated on FreeBSD, as a first step, due to missing limits on CPU time. - Audit the use of qsort() in the FreeBSD base system and consider swapping to other existing sorting algorithms. Discussed with: brooks@ Differential Revision: https://reviews.freebsd.org/D36493 This reverts commit a7469c9c0a504a5e6e9b89e148cd78df5e67ff7f. This reverts commit 7d65a450cdcc7cc743f2ecd114ba3428a21c0033. This reverts commit 8dcf3a82c54cb216df3213a013047907636a01da.
* libc: Sorting is not needed when there are less than two elementsHans Petter Selasky2023-04-191-1/+2
| | | | | | | | | | If there are less than two elements avoid executing the first sorting loop. No functional change intended. Reviewed by: kib@ MFC after: 1 week Sponsored by: NVIDIA Networking Differential Revision: https://reviews.freebsd.org/D39691
* libc: Add missing object size check to qsort_s(3)Hans Petter Selasky2023-04-192-3/+11
| | | | | | | | | | | | | When sorting, both the C11 standard (ISO/IEC 9899:2011, K.3.6.3.2) and the ISO/IEC JTC1 SC22 WG14 N1172 standard, does not define objects of zero size as undefined behaviour. However Microsoft's cpp-docs does. Add proper checks for this. Found while working on bsort(3). Reviewed by: kib@ and emaste@ MFC after: 1 week Sponsored by: NVIDIA Networking Differential Revision: https://reviews.freebsd.org/D39687
* bsort.3: Fix warnings as reported by mandoc -W warningHans Petter Selasky2023-04-191-6/+4
| | | | | | Reported by: Yuri <yuri@aetern.org> MFC after: 1 week Sponsored by: NVIDIA Networking
* libc: Implement bsort(3) a bitonic type of sorting algorithm.Hans Petter Selasky2023-04-196-1/+507
| | | | | | | | | | | | | | | | | | | | | | | | | The bsort(3) algorithm works by swapping objects, similarly to qsort(3), and does not require any significant amount of additional memory. The bsort(3) algorithm doesn't suffer from the processing time issues known the plague the qsort(3) family of algorithms, and is bounded by a complexity of O(log2(N) * log2(N) * N), where N is the number of elements in the sorting array. The additional complexity compared to mergesort(3) is a fair tradeoff in situations where no memory may be allocated. The bsort(3) APIs are identical to those of qsort(3), allowing for easy drop-in and testing. The design of the bsort(3) algorithm allows for future parallell CPU execution when sorting arrays. The current version of the bsort(3) algorithm is single threaded. This is possible because fixed areas of the sorting data is compared at a time, and can easily be divided among different CPU's to sort large arrays faster. Reviewed by: gbe@, delphij@, pauamma_gundo.com (manpages) Sponsored by: NVIDIA Networking Differential Revision: https://reviews.freebsd.org/D36493
* secure_getenv: Improve documentation wordingWarner Losh2023-03-251-14/+16
| | | | | | | | Improve the documentation wording to be more consistent with FreeBSD manual pages. Suggested by: mjg (though reworded) Sponsored by: Netflix
* secure_getenv: Add () around return valuesWarner Losh2023-03-251-2/+2
| | | | | | Style only change, no functional change intended. Sponsored by: Netflix
* Add GNU glibc compatible secure_getenvlucy2023-03-144-3/+40
| | | | | | | | | | | | Add mostly glibc and msl compatible secure_getenv. Return NULL if issetugid() indicates the process is tainted, otherwise getenv(x). The rational behind this is the fact that many Linux applications use this function instead of getenv() as it's widely consider a, "best practice". Reviewed by: imp, mjg (feedback) Pull Request: https://github.com/freebsd/freebsd-src/pull/686 Signed-off-by: Lucy Marsh <seafork@disroot.org>
* libc: move declaration of 'char **environ' to common private headerKonstantin Belousov2023-03-111-2/+1
| | | | | | | | | Suggested by: imp Reviewed by: markj Tested by: markj (aarch64) Sponsored by: The FreeBSD Foundation MFC after: 3 weeks Differential revision: https://reviews.freebsd.org/D37220
* xlocale: garbage collect references to strtoq_l/strtouq_lVal Packett2023-03-021-2/+0
| | | | | | | | | | | | | These were explicitly never implemented (see lib/libc/locale/DESIGN.xlocale), but were referenced in the manpage and the symbol map. Fixes: 3c87aa1d3dc ("Implement xlocale APIs from Darwin") Reported by: ld.lld 16 being --no-undefined-version by default Reviewed by: theraven, emaste Sponsored by: https://www.patreon.com/valpackett Pull Request: https://github.com/freebsd/freebsd-src/pull/679 Differential Revision: https://reviews.freebsd.org/D38408
* getopt_long(3): note an inconsistency with getopt(3) in BUGSKyle Evans2023-02-111-1/+17
| | | | | | | | | | | getopt_long(3) will not allow an `optind` setting of 0 to be bug-for-bug compatible with the GNU implementation, as some software does rely on it. Document it as a BUG, since it affects previous declarations of compatibility with getopt(3). Reviewed by: pauamma (markup) Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D37867
* strfmon(3): Match the return typeJose Luis Duran2023-01-251-2/+2
| | | | | Reviewed by: kib MFC after: 1 week
* strfmon(3): Wording improvementsJose Luis Duran2023-01-251-12/+11
| | | | | | | Use the same terminology as the other `_l` xlocale(3) functions. Reviewed by: kib MFC after: 1 week
* strfmon(3): Add an EXAMPLES sectionJose Luis Duran2023-01-251-0/+25
| | | | | Reviewed by: kib MFC after: 1 week
* strfmon: Remove XXX marksJose Luis Duran2022-10-291-3/+3
| | | | | | | | | | | | phantom@'s HDD crashed with the final version of strfmon.c, as explained in 9d430a5991d3f64a75fee951a1efab3593207832. Now there are tests in place that cover these code paths. Reviewed by: kib PR: 267410 Github PR: #620 MFC after: 1 week
* strfmon_l: Use specified locale for number formattingJose Luis Duran2022-10-291-24/+23
| | | | | | | | | | | | | strfmon_l does not take fully into consideration the explicitly passed locale to perform the formatting. Parallel universe bug report: https://sourceware.org/bugzilla/show_bug.cgi?id=19633 Obtained from: Darwin Reviewed by: kib PR: 267410 Github PR: #620 MFC after: 1 week
* strfmon_l(3): Add name to the man pageJose Luis Duran2022-10-291-3/+5
| | | | | | | Reviewed by: kib PR: 267410 Github PR: #620 MFC after: 1 week
* strfmon(3): Fix # explanationJose Luis Duran2022-10-251-2/+8
| | | | | | | | | | | | | | There's only one value that specifies the number of digits after the decimal point (oh, sorry, the "radix character") the other specifies the number before... While here, add a little more info on the effects of using the #n value. Obtained from: https://github.com/NetBSD/src/commit/d1dd1a086400ae719bde1f2c45938d9bc1d29e8b Reviewed by: kib PR: 267282 Github PR: #619 MFC after: 1 week
* strfmon(3): Remove repeated wordsJose Luis Duran2022-10-251-1/+1
| | | | | | | Reviewed by: kib PR: 267282 Github PR: #619 MFC after: 1 week
* strfmon: Fix formatting of a second fixed-width valueJose Luis Duran2022-10-251-1/+1
| | | | | | | | | | | | | | There is a bug when formatting two consecutive values using fixed-widths and the values need padding. This was because the value of pad_size was zeroed only every other time. Format Before After [%8n] [%8n] [ $123.45] [ $123.45] [ $123.45] [ $123.45] Reviewed by: kib PR: 267282 Github PR: #619 MFC after: 1 week
* strfmon: Fix an edge case when sep_by_space is 2Jose Luis Duran2022-10-251-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix an edge case by printing the required space when, the currency symbol succeeds the value, a space separates the sign from the value and the sign position precedes the quantity and the currency symbol. In other words: n_cs_precedes = 0 n_sep_by_space = 2 n_sign_posn = 1 From The Open Group's localeconv[1]: > When {p,n,int_p,int_n}_sep_by_space is 2: > If the currency symbol and sign string are adjacent, a space separates > them; otherwise, a space separates the sign string from the value. Format Before After [%n] [-123.45¤] [- 123.45¤] [1]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/localeconv.html Obtained from: Darwin Reviewed by: kib PR: 267282 Github PR: #619 MFC after: 1 week
* strfmon: Fix alignment when enclosed by parenthesesJose Luis Duran2022-10-251-2/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | Take into consideration the possibility of quantities enclosed by parentheses when aligning. Matches the examples from The Open Group's: Format Before After %(#5n [$ 123.45] [ $ 123.45 ] Use an alternative pos/neg style [($ 123.45)] [($ 123.45)] [$ 3,456.78] [ $ 3,456.78 ] %!(#5n [ 123.45] [ 123.45 ] Disable the currency symbol [( 123.45)] [( 123.45)] [ 3,456.78] [ 3,456.78 ] https://pubs.opengroup.org/onlinepubs/9699919799/functions/strfmon.html SD5-XSH-ERN-29 is applied, updating the examples for %(#5n and %!(#5n. Obtained from: Darwin Reviewed by: kib PR: 267282 Github PR: #619 MFC after: 1 week