aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/stdio
Commit message (Collapse)AuthorAgeFilesLines
* libc: Drop gets() from symbol mapDag-Erling Smørgrav3 days1-1/+0
| | | | | | | | We have an explicit __sym_compat() entry for the legacy implementation. Fixes: 7381dcc9eeb7 Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D51701
* lib: Fix calls that naively set F_SETFD.Ricardo Branco2025-07-172-7/+21
| | | | | | | | | | | With the recent inclusion of the FD_CLOFORK and FD_RESOLVE_BENEATH flags, we must avoid clearing them when setting only FD_CLOEXEC. Signed-off-by: Ricardo Branco <rbranco@suse.de> Reviewed by: kib, markj MFC after: 1 month Pull Request: https://github.com/freebsd/freebsd-src/pull/1766
* libc: mkostemp(3) should support O_CLOFORKRicardo Branco2025-07-082-4/+5
| | | | | | Reviewed by: kib, markj MFC after: 1 month Pull Request: https://github.com/freebsd/freebsd-src/pull/1758
* fgets.3: document gets_s() __STDC_WANT_LIB_EXT1__Graham Percival2024-12-061-1/+2
| | | | | | | | This matches the man page for qsort_s(). PR: 281828 Signed-off-by: Graham Percival <gperciva@tarsnap.com> Sponsored by: Tarsnap Backup Inc.
* libc/stdio: Increase BUF in vfprintf.c and vfwprintf.cAhmad Khalifa2024-11-292-12/+4
| | | | | | | | With the %b format specifier we need enough space to write a uintmax_t in binary. Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1400
* fileno(3): set errno when returning -1Konstantin Belousov2024-11-292-7/+38
| | | | | | | | | | | as required by IEEE Std 1003.1™-2024. PR: 283014 Reported by: Graham Percival <gperciva@tarsnap.com> Reviewed by: emaste, imp Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D47834
* stdio(3): correct summary information for fileno(3)Konstantin Belousov2024-11-291-1/+1
| | | | | | | Reviewed by: emaste, imp Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D47834
* libc: indicate existing functions that are POSIX 2024Ed Maste2024-11-152-1/+10
| | | | | | Reviewed by: brooks, imp Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D47581
* mktemp(3): bring the documentation up to date with best practiceWolfram Schneider2024-10-271-3/+3
| | | | | | | | | Using short temp filenames as /tmp/temp.XXXX (4 or 6 X) was probably ok 20 years ago, but not anymore. Best practice is to use 10 X. Given that our users often copy & paste examples from our manual pages we need to update the documentation. PR: 261437
* libc: fix access mode tests in fmemopen(3)Ed Maste2024-10-231-5/+5
| | | | | | | | | | | | | | Previously a stream opened as read-only could be written to. Add a test case for the fix. Also correct another incorrect access mode check that worked by accident, and improve the tests for that. PR: 281953 Reported by: Erkki Moorits, fuz Reviewed by: fuz, khng (earlier) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D47265
* stdio: Disable USE_XPRINTF envar.Dag-Erling Smørgrav2024-09-251-2/+0
| | | | | | | | | | As xprintf has not kept up with our standard printf(3) implementation, it is becoming increasingly dangerous to continue to allow it to take over if USE_XPRINTF is defined. Remove that code, while still allowing applications which know about xprintf to select it. Reviewed by: phk Differential Revision: https://reviews.freebsd.org/D46765
* printf(): Save errno earlier.Dag-Erling Smørgrav2024-09-207-27/+34
| | | | | | | | | | | | The manual page says %m is replaced with “the string representation of the error code stored in the errno variable at the beginning of the call”. However, we don't actually save `errno` until fairly late in `__vfprintf()`. Make sure it is saved before we do anything that might perturb `errno`. MFC after: 1 week Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D46718
* Remove residual blank line at start of MakefileWarner Losh2024-07-151-1/+0
| | | | | | | This is a residual of the $FreeBSD$ removal. MFC After: 3 days (though I'll just run the command on the branches) Sponsored by: Netflix
* include: ssp: round out fortification of current set of headersKyle Evans2024-07-133-3/+7
| | | | | | | | | | | | | | | | | | | | 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
* Prepare the system for _FORTIFY_SOURCEKyle Evans2024-05-135-0/+10
| | | | | | | | | | | | | | | Notably: - libc needs to #undef some of the macros from ssp/* for underlying implementations - ssp/* wants a __RENAME() macro (snatched more or less from NetBSD) There's some extra hinkiness included for read(), since libc spells it as "_read" while the rest of the world spells it "read." Reviewed by: imp, ngie Sponsored by: Stormshield Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D32307
* libc printf_render_errno(): do not use strerror()Konstantin Belousov2024-04-231-3/+4
| | | | | | | Reviewed by: imp Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D44916
* libc: minor style, wrap long linesKonstantin Belousov2024-04-231-2/+4
| | | | | | | Reviewed by: imp Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D44916
* __vprintf(): switch from strerror() to strerror_rl()Konstantin Belousov2024-04-231-1/+5
| | | | | | | | | | | | | | | This eliminates the use of non-thread-safe function in printf*() family, and make the call locale-aware. Also, it stops obliterating the strerror() static buffer, which aligns with the POSIX requirement that implementations must behave as if no standard-mandated functions call strerror(). PR: 278556 Reported by: Jonathan Gruber <jonathan.gruber.jg@gmail.com> Reviewed by: imp Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D44916
* libc: don't try to export __sFBrooks Davis2024-04-161-1/+0
| | | | | | This symbol has been static since 2008 (commit 1e98f88776fc). Differential Revision: https://reviews.freebsd.org/D44188
* fclose.3: remove a confusing sentenceMaxim Konovalov2024-02-161-4/+1
| | | | | PR: 277037 Reviewed by: oshogbo
* lib: Automated cleanup of cdefs and other formattingWarner Losh2023-11-272-4/+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-27101-269/+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 some obsolete VCS dataBrooks Davis2023-11-212-9/+0
| | | | | | | | | These wide char support files were copied from the previous versions with expanded $FreeBSD$ strings in #if 0 blocks. Remove them and the scssid definitions in the same #if 0 blocks. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D42688
* libc: Remove empty comments in Symbol.mapBrooks Davis2023-11-151-3/+0
| | | | | | | These were left over from $FreeBSD$ removal. Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D42612
* fflush: correct buffer handling in __sflushEd Maste2023-11-072-21/+4
| | | | | | | | | | | | | Two additional stdio changes followed 86a16ada1ea6 and need to be reverted as part of the fflush fix. This reverts commit 6e13794fbe6e82c21365d0fd66769bf8b19c0197. This reverts commit bafaa70b6f9098d83d074968c8e6747ecec1e118. Fixes: d09a3bf72c0b ("fflush: correct buffer handling in __sflush") Reviewed by: markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D42491
* libc: remove unused errno.h includeEd Maste2023-11-071-1/+0
| | | | | | | errno.h was added in 44cf1e5eb470, which has been reverted. Fixes: d09a3bf72c0b ("fflush: correct buffer handling in __sflush") Sponsored by: The FreeBSD Foundation
* fflush: correct buffer handling in __sflushDag-Erling Smørgrav2023-11-073-17/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes CVE-2014-8611 correctly. The commit that purported to fix CVE-2014-8611 (805288c2f062) only hid it behind another bug. Two later commits, 86a16ada1ea6 and 44cf1e5eb470, attempted to address this new bug but mostly just confused the issue. This commit rolls back the three previous changes and fixes CVE-2014-8611 correctly. The key to understanding the bug (and the fix) is that `_w` has different meanings for different stream modes. If the stream is unbuffered, it is always zero. If the stream is fully buffered, it is the amount of space remaining in the buffer (equal to the buffer size when the buffer is empty and zero when the buffer is full). If the stream is line-buffered, it is a negative number reflecting the amount of data in the buffer (zero when the buffer is empty and negative buffer size when the buffer is full). At the heart of `fflush()`, we call the stream's write function in a loop, where `t` represents the return value from the last call and `n` the amount of data that remains to be written. When the write function fails, we need to move the unwritten data to the top of the buffer (unless nothing was written) and adjust `_p` (which points to the next free location in the buffer) and `_w` accordingly. These variables have already been set to the values they should have after a successful flush, so instead of adjusting them down to reflect what was written, we're adjusting them up to reflect what remains. The bug was that while `_p` was always adjusted, we only adjusted `_w` if the stream was fully buffered. The fix is to also adjust `_w` for line-buffered streams. Everything else is just noise. Fixes: 805288c2f062 Fixes: 86a16ada1ea6 Fixes: 44cf1e5eb470 Sponsored by: Klara, Inc.
* fflush: Split a temporary variable in two.Dag-Erling Smørgrav2023-11-031-4/+4
| | | | | | | It is clearer to avoid reusing temporary variables for different purposes. Sponsored by: Klara, Inc.
* libc: Purge unneeded cdefs.hWarner Losh2023-11-01102-102/+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-33/+85
| | | | Differential Revision: https://reviews.freebsd.org/D42192
* libc: Implement N2680.Dag-Erling Smørgrav2023-09-077-2/+201
| | | | | | | This adds specific width length modifiers in the form of wN and wfN (where N is 8, 16, 32, or 64) which allow printing intN_t and int_fastN_t without resorting to casts or PRI macros. Reviewed by: imp, emaste Differential Revision: https://reviews.freebsd.org/D41725
* libc: Further nit in fopen(3) man page.Dag-Erling Smørgrav2023-09-011-2/+3
| | | | | | Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D41687
* libc: Fix fmemopen(3) prototype in fopen(3) man page.Dag-Erling Smørgrav2023-09-011-4/+6
| | | | | | | | While here, also update a mention of ANSI C. Sponsored by: Klara, Inc. Reviewed by: kevans, markj Differential Revision: https://reviews.freebsd.org/D41686
* libc: Fix fixed-width case in the new integer parser.Dag-Erling Smørgrav2023-08-282-2/+2
| | | | | Fixes: d9dc1603d6e4 Differential Revision: https://reviews.freebsd.org/D41622
* libc: Document support for binary integers.Dag-Erling Smørgrav2023-08-282-19/+44
| | | | | Reviewed by: debdrup, emaste Differential Revision: https://reviews.freebsd.org/D41522
* libc: Implement N2630.Dag-Erling Smørgrav2023-08-285-235/+335
| | | | | | | 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
* Remove $FreeBSD$: one-line nroff patternWarner Losh2023-08-1629-29/+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-16102-204/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* Remove $FreeBSD$: one-line .h patternWarner Losh2023-08-165-5/+0
| | | | Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-1611-22/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-1231-31/+31
| | | | | | | | | 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
* libc: Use secure_getenv(3) where appropriateMark Johnston2023-03-272-4/+2
| | | | | | | No functional change intended. Reviewed by: mjg, imp, kib Differential Revision: https://reviews.freebsd.org/D39278
* libc: Fix size range check in setvbufEd Maste2022-10-041-1/+2
| | | | | | | | From enh at google.com via openbsd-tech mailing list via pfg@: The existing test is wrong for LP64, where size_t has twice as many relevant bits as int, not just one. (Found by inspection by rprichard.)
* libc/stdio: only roll FILE state back on EINTRKonstantin Belousov2022-09-033-4/+6
| | | | | | | | | Reported by: JunT <takimoto-j@kba.biglobe.ne.jp> PR: 266171 Reviewed by: emaste, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D36427
* __swbuf(): styleKonstantin Belousov2022-09-031-2/+2
| | | | | | | Reviewed by: emaste, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D36427
* libc: drop "All rights reserved" from Foundation copyrightsEd Maste2022-08-0441-41/+41
| | | | | | | | | 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-055-5/+51
| | | | | | | | | | 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: Restore fp state upon flush error in fputcMark Johnston2022-03-281-2/+10
| | | | | | | | | This is akin to commit bafaa70b6f9098d83d074968c8e6747ecec1e118. Reported by: Guy Yur <guyyur@gmail.com> Fixes: 86a16ada1ea6 MFC after: 3 days Sponsored by: The FreeBSD Foundation