summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
Commit message (Collapse)AuthorAgeFilesLines
...
* Various improvements to the qsort(3) usage example:Giorgos Keramidas2013-02-201-14/+8
| | | | | | | | | | | | | | | | | | - Remove unused #include. - Do not cast away const. - Use the canonical idiom to compare two numbers. - Use proper type for sizes, i.e. size_t instead of int. - Correct indentation. - Simplify printf("\n") to puts(""). - Use return instead of exit() in main(). Submitted by: Christoph Mallon, christoph.mallon at gmx.de Approved by: gjb (mentor) Reviewed by: stefanf MFC after: 1 week Notes: svn path=/head/; revision=247050
* Add a sample program that shows how a custom comparison function andGiorgos Keramidas2013-02-191-1/+47
| | | | | | | | | | | | qsort(3) can work together to sort an array of integers. PR: docs/176197 Submitted by: Fernando, fapesteguia at opensistemas.com Approved by: gjb (mentor) MFC after: 1 week Notes: svn path=/head/; revision=247014
* Remove undefined behavior from sranddev() andEitan Adler2012-10-092-4/+2
| | | | | | | | | | | | | | | srandomdev(). This doesn't actually work with any modern C compiler: In particular, both clang and modern gcc verisons silently elide any xor operation with 'junk'. Approved by: secteam MFC after: 3 days Notes: svn path=/head/; revision=241373
* Optimize prev. commit for speed.Andrey A. Chernov2012-10-031-3/+7
| | | | | | | | | | | | 1) Don't iterate the loop from the environment array beginning each time, iterate it under the last place we deactivate instead. 2) Call __rebuild_environ() not on each iteration but once, only at the end of whole loop (of course, only in case if something is changed). MFC after: 1 week Notes: svn path=/head/; revision=241154
* Using putenv() and later direct pointer contents modification it is possibeAndrey A. Chernov2012-10-021-1/+3
| | | | | | | | | | | | | | | to craft environment variables with similar names like that: a=1 a=2 ... unsetenv("a") should remove them all to make later getenv("a") impossible. Fix it to do so (this is GNU autoconf test #3 failure too). PR: 172273 MFC after: 1 week Notes: svn path=/head/; revision=241137
* libc: Use O_CLOEXEC for various internal file descriptors.Jilles Tjoelker2012-09-292-2/+2
| | | | | | | | | | | | This fixes a race condition where another thread may fork() before CLOEXEC is set, unintentionally passing the descriptor to the child process. This commit only adds O_CLOEXEC flags to open() or openat() calls where no fcntl(fd, F_SETFD, FD_CLOEXEC) follows. The separate fcntl() call still leaves a race window so it should be fixed later. Notes: svn path=/head/; revision=241046
* Slight stylification.Dag-Erling Smørgrav2012-09-281-18/+11
| | | | Notes: svn path=/head/; revision=241031
* According to a clarification at http://austingroupbugs.net/view.php?id=503Ed Maste2012-09-122-4/+3
| | | | | | | | | | ptsname may set errno, so avoid saving and restoring errno across the function. PR: standards/171572 Notes: svn path=/head/; revision=240412
* Avoid mapping ENOENT to ENOTDIR for non-existent path components.Ed Maste2012-09-121-2/+0
| | | | | | | | | | | | | | | | | | The ENOTDIR mapping was introduced in r235266 for kern/128933 based on an interpretation of the somewhat ambiguous language in the POSIX realpath specification. The interpretation is inconsistent with Solaris and Linux, a regression from 9.0, and does not appear to be permitted by the description of ENOTDIR: 20 ENOTDIR Not a directory. A component of the specified pathname existed, but it was not a directory, when a directory was expected. PR: standards/171577 MFC after: 3 days Notes: svn path=/head/; revision=240410
* Add the same warning to rand48(3) as to rand(3) and random(3).Dag-Erling Smørgrav2012-09-111-1/+0
| | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=240361
* Bump dates.Dag-Erling Smørgrav2012-09-042-2/+2
| | | | | | | Reminded by: bz@ Notes: svn path=/head/; revision=240111
* Add a prominent warning about these functions' unsuitability forDag-Erling Smørgrav2012-09-042-13/+17
| | | | | | | cryptographic purposes, and recommend using arc4random(3) instead. Notes: svn path=/head/; revision=240107
* Make 'junk' volatile so that compilers won't be tempted to optimizeKevin Lo2012-08-171-1/+1
| | | | | | | | Reviewed by: ache MFC after: 3 days Notes: svn path=/head/; revision=239345
* Update the 'C1x draft' reference to '.St -isoC-2011' mdoc macro.Sergey Kandaurov2012-07-262-2/+4
| | | | | | | | Reviewed by: theraven MFC after: 1 week Notes: svn path=/head/; revision=238802
* Remove end of line whitespace.Joel Dahl2012-06-261-1/+1
| | | | Notes: svn path=/head/; revision=237591
* Add more locale-specific functions to the relevant man pages andIsabell Long2012-06-252-1/+19
| | | | | | | | | | | | | Makefiles: - libc/stdtime/strftime.3 - libc/stdtime/strptime.3 - libc/stdlib/strfmon.3 Reviewed by: theraven Approved by: gabor (mentor) Notes: svn path=/head/; revision=237573
* Switch from 4-clause to 2-clause BSD license. (OpenBSD r1.22)Xin LI2012-06-111-8/+1
| | | | | | | | | No functional change. Obtained from: NetBSD via OpenBSD Notes: svn path=/head/; revision=236936
* 1) Although unpublished version of standardAndrey A. Chernov2012-06-051-17/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | http://austingroupbugs.net/view.php?id=385#c713 (Resolved state) recommend this way for the current standard (called "earlier" in the text) "However, earlier versions of this standard did not require this, and the same example had to be written as: // buf was obtained by malloc(buflen) ret = write(fd, buf, buflen); if (ret < 0) { int save = errno; free(buf); errno = save; return ret; } " from feedback I have for previous commit it seems that many people prefer to avoid mass code change needed for current standard compliance and prefer to track unpublished standard instead, which requires now that free() itself must save errno, not its usage code. So, I back out "save errno across free()" part of previous commit, and will fill PR for changing free() isntead. 2) Remove now unused serrno. MFC after: 1 week Notes: svn path=/head/; revision=236618
* 1) IEEE Std 1003.1-2008, "errno" section, is explicit thatAndrey A. Chernov2012-06-041-6/+16
| | | | | | | | | | | | | | | | | | | | "The setting of errno after a successful call to a function is unspecified unless the description of that function specifies that errno shall not be modified." However, free() in IEEE Std 1003.1-2008 does not mention its interaction with errno, so MAY modify it after successful call (it depends on particular free() implementation, OS-specific, etc.). So, save errno across free() calls to make code portable and POSIX-conformant. 2) Remove unused serrno assignment. MFC after: 1 week Notes: svn path=/head/; revision=236582
* General mdoc(7) and typo fixes.Glen Barber2012-05-112-3/+4
| | | | | | | | | PR: 167734 Submitted by: Nobuyuki Koganemaru (kogane!jp.freebsd.org) MFC after: 3 days Notes: svn path=/head/; revision=235286
* According to SUSv4, realpath(3) must fail ifKonstantin Belousov2012-05-112-12/+29
| | | | | | | | | | | | | | | | | | | | [ENOENT] A component of file_name does not name an existing file or file_name points to an empty string. [ENOTDIR] A component of the path prefix is not a directory, or the file_name argument contains at least one non- <slash> character and ends with one or more trailing <slash> characters and the last pathname component names an existing file that is neither a directory nor a symbolic link to a directory. Add checks for the listed conditions, and set errno accordingly. Update the realpath(3) manpage to mention SUS behaviour. Remove the requirement to include sys/param.h before stdlib.h. PR: 128933 MFC after: 3 weeks Notes: svn path=/head/; revision=235266
* Import jemalloc 9ef7f5dc34ff02f50d401e41c8d9a4a928e7c2aa (dev branch,Jason Evans2012-04-1711-8241/+167
| | | | | | | | | | | prior to 3.0.0 release) as contrib/jemalloc, and integrate it into libc. The code being imported by this commit diverged from lib/libc/stdlib/malloc.c in March 2010, which means that a portion of the jemalloc 1.0.0 ChangeLog entries are relevant, as are the entries for all subsequent releases. Notes: svn path=/head/; revision=234370
* Remove trailing whitespace per mdoc lint warningEitan Adler2012-03-292-7/+7
| | | | | | | | | | Disussed with: gavin No objection from: doc Approved by: joel MFC after: 3 days Notes: svn path=/head/; revision=233648
* Add aligned_alloc(3).Ed Schouten2012-01-094-9/+55
| | | | | | | | | | | | The C11 folks reinvented the wheel by introducing an aligned version of malloc(3) called aligned_alloc(3), instead of posix_memalign(3). Instead of returning the allocation by reference, it returns the address, just like malloc(3). Reviewed by: jasone@ Notes: svn path=/head/; revision=229848
* Properly sort functions by name.Ed Schouten2012-01-081-3/+3
| | | | Notes: svn path=/head/; revision=229808
* Add missing opening and closing brackets in getopt_long.3 and getsubopt.3Glen Barber2011-12-262-3/+6
| | | | | | | | | | to make the examples reflect reality more closely. MFC after: 1 week X-MFC-After: 9.0-RELEASE Notes: svn path=/head/; revision=228885
* Since clang does not support the tls_model attribute used in malloc.cDimitry Andric2011-12-151-2/+10
| | | | | | | | | | yet (see LLVM PR 9788), and warns about it, rub it out for now. When clang grows support for this attribute, I will revert this again. MFC after: 1 week Notes: svn path=/head/; revision=228540
* Small style(9) improvements.David Chisnall2011-12-151-2/+4
| | | | | | | Approved by: dim (mentor) Notes: svn path=/head/; revision=228528
* Some fixes to the man pages for [at_]quick_exit(3)David Chisnall2011-12-072-12/+17
| | | | | | | | Reviewed by: pluknet Approved by: dim (mentor) Notes: svn path=/head/; revision=228329
* style(9) cleanups.David Chisnall2011-12-071-10/+7
| | | | | | | Approved by: brooks (mentor) Notes: svn path=/head/; revision=228323
* Implement quick_exit() / at_quick_exit() from C++11 / C1x. Also add aDavid Chisnall2011-12-077-3/+204
| | | | | | | | | | | | | | | | | | | __noreturn macro and modify the other exiting functions to use it. The __noreturn macro, unlike __dead2, must be used BEFORE the function. This is in line with the C and C++ specifications that place _Noreturn (c1x) and [[noreturn]] (C++11) in front of the functions. As with __dead2, this macro falls back to using the GCC attribute. Unfortunately, clang currently sets the same value for the C version macro in C99 and C1x modes, so these functions are hidden by default. At some point before 10.0, I need to go through the headers and clean up the C1x / C++11 visibility. Reviewed by: brooks (mentor) Notes: svn path=/head/; revision=228322
* Implement xlocale APIs from Darwin, mainly for use by libc++. This adds aDavid Chisnall2011-11-2012-20/+203
| | | | | | | | | | | | | | | load of _l suffixed versions of various standard library functions that use the global locale, making them take an explicit locale parameter. Also adds support for per-thread locales. This work was funded by the FreeBSD Foundation. Please test any code you have that uses the C standard locale functions! Reviewed by: das (gdtoa changes) Approved by: dim (mentor) Notes: svn path=/head/; revision=227753
* Fix a warning emitted by Clang.Ed Schouten2011-11-041-1/+2
| | | | | | | | | The size passed to strlcat() must depend on the input length, not the output length. Because the input and output buffers are equal in size, the resulting binary does not change at all. Notes: svn path=/head/; revision=227090
* Fix building of 32-bit compat libraries on amd64 with clang, and usingDimitry Andric2011-07-181-4/+0
| | | | | | | | | | | | | | | | | -g, by reverting r219139. The LLVM PR referenced in that revision was fixed in the mean time, and we imported a clang snapshot soon afterwards, so the temporary workaround of disabling clang's integrated assembler is no longer needed. In this particular case, using e.g. DEBUG_FLAGS=-g causes clang to output certain directives into assembly that our version of GNU as chokes on. Reported by: dougb Approved by: re (kib) Notes: svn path=/head/; revision=224201
* Fix whitespace inconsistencies in libc in files copyrighted by me.Ed Schouten2011-06-261-1/+1
| | | | Notes: svn path=/head/; revision=223576
* Change sparc64 to use the initial exec TLS model, too. This avoids randomMarius Strobl2011-06-211-1/+1
| | | | | | | assertion failures in _malloc_thread_cleanup(). Notes: svn path=/head/; revision=223369
* Don't add sigwait.c to MISRCS here when sigwait.c lives under ../sys andMarcel Moolenaar2011-03-171-1/+1
| | | | | | | it's already added to SRCS there. Notes: svn path=/head/; revision=219709
* Now that TLS generally is available on sparc64 since r219534 turn onMarius Strobl2011-03-111-1/+1
| | | | | | | | | support for it. Note that while sparc64 also supports the static TLS model and thus tls_model("initial-exec"), using the default model turned out to yield slightly better buildstone performance. Notes: svn path=/head/; revision=219535
* Correct a typo in the malloc(3) manpage. Malloc options are set in theRyan Stone2011-03-071-2/+2
| | | | | | | | | | MALLOC_OPTIONS environment variable, not JEMALLOC_OPTIONS. Reviewed by: jasone Approved by: emaste (mentor) Notes: svn path=/head/; revision=219377
* Put in a temporary workaround for ctfmerge hanging on processingDimitry Andric2011-03-011-0/+4
| | | | | | | | | | | | | | | | | | | kernel.debug (or possibly other files), when WITH_CTF is active. This is caused by a bug in clang's integrated assembler, causing malloc to sometimes hang during initialization in statically linked executables that use threading, such as the copy of ctfmerge that is built during the bootstrap stage of buildworld. The bug has been submitted upstream: http://llvm.org/bugs/show_bug.cgi?id=9352 Note that you might have to rebuild and install libc first, to get your kernel build to finish, because the ctfmerge binary built during bootstrap is linked with your base system's copy of libc.a, which might already contain a bad copy of malloc.o. Notes: svn path=/head/; revision=219139
* Fix some style(9) issues.Konstantin Belousov2011-01-081-4/+5
| | | | | | | | | | Do not use strlcpy() where simple assignment is enough. Noted by: bde (long time ago) MFC after: 1 week Notes: svn path=/head/; revision=217144
* Revert to r214147, errno is not clobbered as originallyBenedict Reuschling2010-10-221-2/+0
| | | | | | | thought. Notes: svn path=/head/; revision=214200
* Document strtonum()s behavior of setting errno to 0 when no error is found.Benedict Reuschling2010-10-211-0/+2
| | | | | | | | | | PR: docs/143330 Submitted by: Efstratios Karatzas (gpf dot kira at gmail dot com) Discussed with: ru@ MFC after: 7 days Notes: svn path=/head/; revision=214148
* Sync with OpenBSD rev. 1.13:Benedict Reuschling2010-10-211-2/+1
| | | | | | | | | | | strtonum does not require limits.h Obtained from: OpenBSD Discussed with: ru@ MFC after: 5 days Notes: svn path=/head/; revision=214147
* mdoc: drop redundant .Pp and .LP callsUlrich Spörlein2010-10-082-2/+0
| | | | | | | They have no effect when coming in pairs, or before .Bl/.Bd Notes: svn path=/head/; revision=213573
* Missed space.Konstantin Belousov2010-10-061-1/+1
| | | | | | | | Submitted by: brueffer MFC after: 1 week Notes: svn path=/head/; revision=213477
* Add cross-references to lrand48(3) and arc4random(3) from rand(3)Konstantin Belousov2010-10-062-1/+11
| | | | | | | | | | and random(3). Submitted by: Valentin Nechayev <netch netch kiev ua> MFC after: 1 week Notes: svn path=/head/; revision=213476
* Revert changes of 'assure' to 'ensure' made in r211936.Rebecca Cran2010-09-111-2/+2
| | | | | | | Approved by: rrs (mentor) Notes: svn path=/head/; revision=212463
* Because POSIX does not allow EINTR to be returned from sigwait(),David Xu2010-09-101-1/+1
| | | | | | | | | | | add a wrapper for it in libc and rework the code in libthr, the system call still can return EINTR, we keep this feature. Discussed on: thread Reviewed by: jilles Notes: svn path=/head/; revision=212405
* Fix incorrect usage of 'assure' and 'insure'.Rebecca Cran2010-08-281-2/+2
| | | | | | | Approved by: rrs (mentor) Notes: svn path=/head/; revision=211936