summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
Commit message (Collapse)AuthorAgeFilesLines
* Provide set_constraint_handler_s(3) man page.Konstantin Belousov2018-08-192-2/+154
| | | | | | | | | | | | Mention abort_handler_s(3) and ignore_handler_s(3), provide cross-reference from memset(3). Submitted by: Yuri Pankov <yuripv@yuripv.net> MFC after: 3 days Differential revision: https://reviews.freebsd.org/D16797 Notes: svn path=/head/; revision=338051
* Use tab for indent.Konstantin Belousov2018-08-191-1/+1
| | | | | | | | Submitted by: Yuri Pankov <yuripv@yuripv.net> MFC after: 3 days Notes: svn path=/head/; revision=338048
* getopt_long(3): Document behavior of leading characters in optstringKyle Evans2018-08-121-2/+43
| | | | | | | | | | | | | | | | | | Leading '+', '-', and ':' in optstring have special meaning. We briefly mention that the first two have special meaning in that we say POSIXLY_CORRECT turns them off, but we don't actually document their meaning. Add a paragraph to RETURN VALUES explaining how they control the treatment of non-option arguments. A leading ':' has no mention; add a note that it suppresses warnings about missing arguments. Reviewed by: jilles MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D14142 Notes: svn path=/head/; revision=337666
* atoi.3: bump .DdEitan Adler2018-06-131-1/+1
| | | | | | | I touched the man page. Bump Dd by just over 15 years. Notes: svn path=/head/; revision=335044
* libc: remove explicit cast NULL in atoiEitan Adler2018-06-132-3/+3
| | | | | | | | | | There isn't any reason to cast NULL so just remove it. Noticed when cleaning up top. Reviewed by: pstef Notes: svn path=/head/; revision=335041
* libc qsort(3): stop aliasing.Konstantin Belousov2018-06-101-44/+17
| | | | | | | | | | | | | | | | | | | Qsort swap code aliases the sorted array elements to ints and longs in order to do swap by machine words. Unfortunately this breaks with the full code optimization, e.g. LTO. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83201 which seems to reference code directly copied from libc/stdlib/qsort.c. PR: 228780 Reported by: mliska@suse.cz Reviewed by: brooks Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D15714 Notes: svn path=/head/; revision=334928
* Bump the date on man pages in r334306Eric van Gyzen2018-05-292-2/+2
| | | | | | | | | | | | | It seems a shame to ruin the patina of the June 4, 1993 date on abort.3, especially since it still matched the date of the SCCS ID, but those are the rules. Reported by: araujo MFC after: 3 days Sponsored by: Dell EMC Notes: svn path=/head/; revision=334308
* Cross-reference abort2(2) from a few man pagesEric van Gyzen2018-05-292-0/+2
| | | | | | | | | | | I didn't know abort2 existed until it was mentioned on a mailing list. Mention it in related pages so others can find it easily. MFC after: 3 days Sponsored by: Dell EMC Notes: svn path=/head/; revision=334306
* Update jemalloc to version 5.1.0.Jason Evans2018-05-111-4/+4
| | | | Notes: svn path=/head/; revision=333477
* Don't put multiple names on a single .Nm line. This fixes apropos(1)Edward Tomasz Napierala2018-04-171-1/+7
| | | | | | | | | | | | | | | | output, from this: strnlen, strlen, strlen,(3) - find length of string │······· ... to this: strlen, strnlen(3) - find length of string PR: 223525 MFC after: 2 weeks Notes: svn path=/head/; revision=332642
* Use standard 2-clause license where copyright is held by the FreeBSD FoundationEd Maste2018-02-021-9/+7
| | | | Notes: svn path=/head/; revision=328785
* Move strtold wrapper from strtol.c to its own strtold.c. This codeWarner Losh2018-01-313-7/+46
| | | | | | | | was written by theraven@ (David Chisnall) entirely, there's no original Berkeley code left here so just copy his copyright over. Notes: svn path=/head/; revision=328612
* libc: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-2511-1/+23
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using mis-identified many licenses so this was mostly a manual - error prone - task. 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. Notes: svn path=/head/; revision=326193
* General further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-2030-12/+72
| | | | | | | | | | | | | | | | | 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=326025
* C++17 requires quick_exit(3) to be async-signal safe.Konstantin Belousov2017-11-042-2/+18
| | | | | | | | | | Make it safe, and update man page with the useful information. Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=325389
* Improve standard compliance for memset_s() and abort_handler_s().Konstantin Belousov2017-08-121-2/+8
| | | | | | | | | | | | | | | | | | | | abort_handler_s() currently simply calls abort(), though the standard specifies more: "Writes an implementation-defined message to stderr which must include the string pointed to by msg and calls abort()." memset_s() is missing error condition "n > smax", and does not invoke the constraint handler after filling the buffer: "following errors are detected at runtime and call the currently installed constraint handler function after storing ch in every location of the destination range [dest, dest+destsz) if dest and destsz are themselves valid", one of the errors is "n > smax" itself. Submitted by: Yuri Pankov <yuripv@gmx.com> MFC after: 1 week Differential revision: https://reviews.freebsd.org/D11991 Notes: svn path=/head/; revision=322427
* Pick 'Remove external linkage for spin_adaptive' from upstream jemallocRyan Libby2017-08-091-1/+1
| | | | | | | | | | | | | Apply the changes from upstream jemalloc 048c6679. This is actually not quite a cherry pick due to makefile difference and because FreeBSD does not carry the msvc project files which were also modified in that commit. Approved by: jasone (maintainer), markj (mentor) Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=322332
* Follow up to r320992, properly escape the backslash so it renders properly.Brad Davis2017-07-141-2/+2
| | | | | | | | | MFC after: 1 week Forgotten by: brd X-MFC-With: r320992 Notes: svn path=/head/; revision=320993
* Add a complete example to tsearch(3)Brad Davis2017-07-141-1/+59
| | | | | | | | | Reviewed by: wblock, sevan, bruffer MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D11053 Notes: svn path=/head/; revision=320992
* Update jemalloc to 5.0.0.Jason Evans2017-06-151-4/+4
| | | | Notes: svn path=/head/; revision=319971
* quick_exit(3): delete trailing whitespace in licensing tortEnji Cooper2017-05-231-3/+3
| | | | | | | | | Reported by: make manlint MFC after: 2 weeks Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=318710
* The current qsort(3) implementation ignores the sizes of partitions, andXin LI2017-05-191-15/+38
| | | | | | | | | | | | | | always perform recursion on the left partition, then use a tail call to handle the right partition. In the worst case this could require O(N) levels of recursions. Reduce the possible recursion level to log2(N) by always recursing on the smaller partition instead. Obtained from: PostgreSQL 9d6077abf9d6efd992a59f05ef5aba981ea32096 Notes: svn path=/head/; revision=318515
* Use size_t.Xin LI2017-05-191-3/+3
| | | | | | | Inspired by: OpenBSD src/lib/libc/stdlib/qsort.c,v 1.11 Notes: svn path=/head/; revision=318514
* Style.Konstantin Belousov2017-05-151-9/+7
| | | | | | | | Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Notes: svn path=/head/; revision=318303
* Simplify cleanup on failure in realpath(3).Konstantin Belousov2017-05-151-44/+31
| | | | | | | | | | | | | | | | | | If realpath() allocated memory for result and failed, the memory is freed in each place where return is performed. More, the function needs to track the allocation status, to not free user-supplied buffer. Consolidate the memory handling in the wrapper, freeing the buffer if the actual worker failed. Reviewed by: emaste (previous version) Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D10670 Notes: svn path=/head/; revision=318299
* Fix several buffer overflows in realpath(3).Konstantin Belousov2017-05-151-19/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - The statement "left_len -= s - left;" does not take the slash into account if one was found. This results in the invariant "left[left_len] == '\0'" being violated (and possible buffer overflows). The patch replaces the variable "s" with a size_t "next_token_len" for more clarity. - "slen" from readlink(2) can be 0 when encountering empty symlinks. Then, further down, "symlink[slen - 1]" underflows the buffer. When slen == 0, realpath(3) should probably return ENOENT (http://austingroupbugs.net/view.php?id=825, https://lwn.net/Articles/551224/). Some other minor issues: - The condition "resolved_len >= PATH_MAX" cannot be true. - Similarly, "s - left >= sizeof(next_token)" cannot be true, as long as "sizeof(next_token) >= sizeof(left)". - Return ENAMETOOLONG when a resolved symlink from readlink(2) is too long for the symlink buffer (instead of just truncating it). - "resolved_len > 1" below the call to readlink(2) is always true as "strlcat(resolved, next_token, PATH_MAX);" always results in a string of length > 1. Also, "resolved[resolved_len - 1] = '\0';" is not needed; there can never be a trailing slash here. - The truncation check for "strlcat(symlink, left, sizeof(symlink));" should be against "sizeof(symlink)" (the third argument to strlcat) instead of "sizeof(left)". Submitted by: Jan Kokemц╪ller <jan.kokemueller@gmail.com> PR: 219154 MFC after: 2 weeks Notes: svn path=/head/; revision=318298
* Implement the memset_s(3) function as specified by the C11 ISO/IECKonstantin Belousov2017-03-303-2/+100
| | | | | | | | | | | | | | | | | 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
* Minor libc cleanup: let calloc(3) do the multiplication.Pedro F. Giffuni2017-03-131-1/+1
| | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=315187
* libc: provide some bounds-checking through reallocarray(3).Pedro F. Giffuni2017-03-121-4/+4
| | | | | | | | | | | | reallocarray(3) is a non portable extension that originated in OpenBSD. Given that it is already in FreeBSD's libc it is useful for the cases where reallocation involves a multiplication. MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D9955 Notes: svn path=/head/; revision=315162
* hcreate(3): fix the ERRORS section and bump .DdEnji Cooper2017-02-071-4/+4
| | | | | | | | | | | | - Add missing comma between functions that trigger ENOMEM error. - Fix the description for ESRCH. The action that triggers this error is FIND, not SEARCH (SEARCH does not exist). MFC after: 1 week Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=313374
* Replace dot-dot relative pathing with SRCTOP-relative paths where possibleEnji Cooper2017-01-201-3/+3
| | | | | | | | | | | | | | | | | | | | This reduces build output, need for recalculating paths, and makes it clearer which paths are relative to what areas in the source tree. The change in performance over a locally mounted UFS filesystem was negligible in my testing, but this may more positively impact other filesystems like NFS. LIBC_SRCTOP was left alone so Juniper (and other users) can continue to manipulate lib/libc/Makefile (and other Makefile.inc's under lib/libc) as include Makefiles with custom options. Discussed with: marcel, sjg MFC after: 1 week Reviewed by: emaste Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D9207 Notes: svn path=/head/; revision=312451
* Export __cxa_thread_atexit_impl as an alias for __cxa_thread_atexit.Konstantin Belousov2017-01-074-106/+162
| | | | | | | | | | | | | | | | | | | | | | | | | | libstdc++ before gcc r244057 expected that libc provided __cxa_thread_atexit_impl, and libstdc++ implemented __cxa_thread_atexit, by forwarding the calls to _impl. Mentioned gcc revision checks for __cxa_thread_atexit in libc and does not provide the symbol from libstdc++ if found. This change helps older gcc, in particular, all released versions which implement thread_local, by consolidating the implementation into libc. For that versions, if configured with the current libc, the __cxa_thread_atexit is exported from libstdc++ as a trivial wrapper around libc::__cxa_thread_atexit_impl. The __cxa_thread_atexit implementation is put into separate source file to allow for static linking with older libstdc++.a. gcc bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78968 Reported by: Hannes Hauswedell <h2+fbsdports@fsfe.org> PR: 215709 Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Notes: svn path=/head/; revision=311651
* Update jemalloc to 4.3.1.Jason Evans2016-11-091-2/+2
| | | | Notes: svn path=/head/; revision=308473
* Improve phrasing of the STANDARDS section.Ed Schouten2016-10-151-2/+2
| | | | | | | | | Reported by: wblock MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D8205 Notes: svn path=/head/; revision=307343
* Improve typing of POSIX search tree functions.Ed Schouten2016-10-135-52/+54
| | | | | | | | | | | | | | | | | | | | | | | | | | Back in 2015 when I reimplemented these functions to use an AVL tree, I was annoyed by the weakness of the typing of these functions. Both tree nodes and keys are represented by 'void *', meaning that things like the documentation for these functions are an absolute train wreck. To make things worse, users of these functions need to cast the return value of tfind()/tsearch() from 'void *' to 'type_of_key **' in order to access the key. Technically speaking such casts violate aliasing rules. I've observed actual breakages as a result of this by enabling features like LTO. I've filed a bug report at the Austin Group. Looking at the way the bug got resolved, they made a pretty good step in the right direction. A new type 'posix_tnode' has been added to correspond to tree nodes. It is still defined as 'void' for source-level compatibility, but in the very far future it could be replaced by a proper structure type containing a key pointer. MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D8205 Notes: svn path=/head/; revision=307227
* Add comment on use of abort() in libcEd Maste2016-10-121-1/+8
| | | | | | | Suggested by: jonathan (in review D8133) Notes: svn path=/head/; revision=307148
* abort in srandomdev if kern.arandom sysctl failsEd Maste2016-10-051-4/+5
| | | | | | | | | | | | | | | | | | | The sysctl cannot fail. If it does fail on some FreeBSD derivative or after some future change, just abort() so that the problem will be found and fixed. While abort() is not normally suitable for a library, it makes sense here. This is akin to r306636 for arc4random. Reviewed by: ed MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D8077 Notes: svn path=/head/; revision=306708
* When MAKEOBJDIRPREFIX points to a case-insensitive file system, theMarcel Moolenaar2016-09-161-1/+8
| | | | | | | | | | | | | | build can break when different source files create the same object files (case-insensitivity speaking). This is the case for _Exit.c and _exit.s. Compile _Exit.c as C99_Exit.c Reviewed by: sjg@ MFC after: completion Sponsored by: Bracket Computing Differential Revision: https://reviews.freebsd.org/D7893 Notes: svn path=/head/; revision=305855
* Add __cxa_thread_atexit(3) API implementation.Konstantin Belousov2016-08-064-1/+152
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is the backing feature to implement C++11 thread storage duration specified by the thread_local keyword. A destructor for given thread-local object is registered to be executed at the thread termination time using __cxa_thread_atexit(). Libc calls the __cxa_thread_calls_dtors() during exit(3), before finalizers and atexit functions, and libthr calls the function at the thread termination time, after the stack unwinding and thread-specific key destruction. There are several uncertainties in the API which lacks a formal specification. Among them: - is it allowed to register destructors during destructing; we allow, but limiting the nesting level. If too many iterations detected, a diagnostic is issued to stderr and thread forcibly terminates for now. - how to handle destructors which belong to an unloading dso; for now, we ignore destructor calls for such entries, and issue a diagnostic. Linux does prevent dso unload until all threads with destructors from the dso terminated. It is supposed that the diagnostics allow to detect real-world applications relying on the above details and possibly adjust our implementation. Right now the choices were to provide the slim API (but that rarely stands the practice test). Tests are added to check generic functionality and to specify some of the above implementation choices. Submitted by: Mahdi Mokhtari <mokhi64_gmail.com> Reviewed by: theraven Discussed with: dim (detection of -std=c++11 supoort for tests) Sponsored by: The FreeBSD Foundation (my involvement) MFC after: 2 weeks Differential revisions: https://reviews.freebsd.org/D7224, https://reviews.freebsd.org/D7427 Notes: svn path=/head/; revision=303795
* Fix typing of srandom() and initstate().Ed Schouten2016-07-262-5/+5
| | | | | | | | | | | | | | | | POSIX requires that these functions have an unsigned int for their first argument; not an unsigned long. My reasoning is that we can safely change these functions without breaking the ABI. As far as I know, our supported architectures either use registers for passing function arguments that are at least as big as long (e.g., amd64), or int and long are of the same size (e.g., i386). Reviewed by: ache Differential Revision: https://reviews.freebsd.org/D6644 Notes: svn path=/head/; revision=303342
* Reflect error indication according to POSIX and what those functionsAndrey A. Chernov2016-06-051-2/+2
| | | | | | | currently do. Notes: svn path=/head/; revision=301448
* Don't use fixup for C99 and up, the compiler result is already correct.Andrey A. Chernov2016-06-014-0/+8
| | | | | | | | | Suggested by: bde MFC after: 1 week Notes: svn path=/head/; revision=301115
* Micro optimize: C standard guarantees that right shift for unsigned valueAndrey A. Chernov2016-05-291-1/+1
| | | | | | | | | | fills left bits with zero, and we have exact 32bit unsigned value (uint32_t), so there is no reason to add "& 0x7fffffff" here. MFC after: 1 week Notes: svn path=/head/; revision=300965
* 1) Unifdef USE_WEAK_SEEDING since it is too obsolete to support and makesAndrey A. Chernov2016-05-291-41/+11
| | | | | | | | | | | | | | | | reading hard. 2) Instead of doing range transformation in each and every function here, do it single time directly in do_rand(). One "mod" operation overhead is not a big deal, but the code looks nicer and possible future functions additions or PRNG change do not miss range transformations neither have unneeded ones. 3) Use POSIX argument types for visible functions (cosmetic). MFC after: 1 week Notes: svn path=/head/; revision=300956
* 1) Unifdef USE_WEAK_SEEDING it is too obsolete to support and makes readingAndrey A. Chernov2016-05-291-46/+14
| | | | | | | | | | | | | | | | harder. 2) ACM paper require seed to be in [1, 2^31-2] range, so use the same range shifting as already done for rand(3). Also protect srandomdev() + TYPE_0 case (non default) from negative seeds. 3) Don't check for valid "type" range in setstate(), it is always valid as calculated. Instead add a check that rear pointer not exceeed end pointer. MFC after: 1 week Notes: svn path=/head/; revision=300953
* Let l64a() properly null terminate its result.Ed Schouten2016-05-261-22/+14
| | | | | | | | | | | | | | | | | Though the buffer used by l64a() is initialized with null bytes, repetetive calls may end up having trailing garbage of previous invocations because we don't end up terminating the string. Instead of importing NetBSD's fix, use this opportunity to simplify this function dramatically, for example by just storing the Base64 character set in a string. There is also no need to do the bitmasking, as we can just use the proper integer type from <stdint.h>. MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D6511 Notes: svn path=/head/; revision=300775
* 1) POSIX prohibits printing errors to stderr here and requireAndrey A. Chernov2016-05-221-15/+10
| | | | | | | | | | | | | | | | | | returning NULL: "Upon successful completion, initstate() and setstate() shall return a pointer to the previous state array; otherwise, a null pointer shall be returned. Although some implementations of random() have written messages to standard error, such implementations do not conform to POSIX.1-2008." 2) Move error detections earlier to prevent state modifying. MFC after: 1 week Notes: svn path=/head/; revision=300397
* Update jemalloc to 4.2.0.Jason Evans2016-05-131-1/+1
| | | | Notes: svn path=/head/; revision=299587
* libc: spelling fixes.Pedro F. Giffuni2016-04-302-3/+3
| | | | | | | Mostly on comments. Notes: svn path=/head/; revision=298830
* libc: do not include <sys/types.h> where <sys/param.h> was already includedAndriy Voskoboinyk2016-04-181-1/+0
| | | | | | | | | According to style(9): > normally, include <sys/types.h> OR <sys/param.h>, but not both. (<sys/param.h> already includes <sys/types.h> when LOCORE is not defined). Notes: svn path=/head/; revision=298226