summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio
Commit message (Collapse)AuthorAgeFilesLines
...
* - Remove underscores from the internal structure name, as it doesn't collidegahr2013-01-312-32/+118
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | with the user's namespace. - Correct size and position variables type from long to size_t. - Do not set errno to ENOMEM on malloc failure, as malloc already does so. - Implement the concept of "buffer data length", which mandates what SEEK_END refers to and the allowed extent for a read. - Use NULL as read-callback if the buffer is opened in write-only mode. Conversely, use NULL as write-callback when opened in read-only mode. - Implement the handling of the ``b'' character in the mode argument. A binary buffer differs from a text buffer (default mode if ``b'' is omitted) in that NULL bytes are never appended to writes and that the "buffer data length" equals to the size of the buffer. - Remove shall from the man page. Use indicative instead. Also, specify that the ``b'' flag does not conform with POSIX but is supported by glibc. - Update the regression test so that the ``b'' functionality and the "buffer data length" concepts are tested. - Minor style(9) corrections. Suggested by: jilles Reviewed by: cognet Approved by: cognet
* Add fmemopen(3), an interface to get a FILE * from a buffer in memory, alonggahr2013-01-304-7/+224
| | | | | | | | with the respective regression test. See http://pubs.opengroup.org/onlinepubs/9699919799/functions/fmemopen.html Reviewed by: cognet Approved by: cognet
* The getline function returns the number of characters read, noteadler2012-12-011-2/+2
| | | | | | | | | written. Use clearer text for this. PR: docs/174023 Submitted by: Paul Procacci <pprocacci@gmail.com> Approved by: bcr (mentor) MFC after: 1 week
* libc: Allow setting close-on-exec in fopen/freopen/fdopen.jilles2012-11-304-2/+33
| | | | | | | | | | | | | | | | | | | This commit adds a new mode option 'e' that must follow any 'b', '+' and/or 'x' options. C11 is clear about the 'x' needing to follow 'b' and/or '+' and that is what we implement; therefore, require a strict position for 'e' as well. For freopen() with a non-NULL path argument and fopen(), the close-on-exec flag is set iff the 'e' mode option is specified. For freopen() with a NULL path argument and fdopen(), the close-on-exec flag is turned on if the 'e' mode option is specified and remains unchanged otherwise. Although the same behaviour for fopen() can be obtained by open(O_CLOEXEC) and fdopen(), this needlessly complicates the calling code. Apart from the ordering requirement, the new option matches glibc. PR: kern/169320
* Clarify that the ' flag is an apostrophe.grog2012-11-081-1/+1
| | | | MFC after: 2 weeks
* fopen(3): Mention that the "x" mode option is from C11.jilles2012-11-011-1/+5
| | | | MFC after: 1 week
* Correct double "the the"eadler2012-09-141-1/+1
| | | | | Approved by: cperciva MFC after: 3 days
* The register_printf_render_std() function expects regular string.pjd2012-07-041-1/+1
| | | | | | Change argument type from 'const unsigned char *' to 'const char *'. MFC after: 2 weeks
* Only set _w to 0 when the file stream is not currently reading. Withouteadler2012-05-301-1/+1
| | | | | | | | | | this fflush may fail to write data in the buffer. PR: kern/137819 Submitted by: Eric Blake <ebb9@byu.net> Reviewed by: theraven Approved by: cperciva MFC after: 2 weeks
* Add two new locale-specific man pages:issyl02012-05-233-1/+157
| | | | | | | | | - libc/stdio/scanf_l.3 - libc/stdio/printf_l.3 Reviewed by: theraven Approved by: gabor (mentor) MFC after: 5 days
* Minor mdoc nits.joel2012-05-122-4/+4
|
* Remove reference to non-existent FreeBSD Security Architectureeadler2012-05-091-3/+1
| | | | | Approved by: cperciva MFC after: 3 days
* Remove incorrect __restrict qualifier on several pointersdumbbell2012-04-302-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The typical case was: static __inline int convert_ccl(FILE *fp, char * __restrict p, [...]) { [...] if (p == SUPPRESS_PTR) { [...] } else { [...] } [...] } This qualifier says that the pointer is the only one at that time pointing to the resource. Here, clang considers that "p" will never match "SUPPRESS_PTR" and optimize the if{} block out. This leads to segfaults in programs calling vfscanf(3) and vfwscanf(3) with just the format string (no arguments following it). The following softwares were reported to abort with segmentation fault and this patch fixes it: o cmake o smartd o devel/ORBit2 dim@ opened an LLVM PR to discuss this clang optimization: http://llvm.org/bugs/show_bug.cgi?id=12656 Tested by: bsam@
* Fix a bug in *wscanf's handling of non-wide %s, %c, and %[das2012-04-301-44/+9
| | | | | | | | | | | | | conversions. Both the specification and the documentation say the width is interpreted as the max number of wide characters to read, but the implementation was interpreting it as the number of bytes to convert. (See also r105317.) This change has security implications for any applications that depend on the buggy behavior, but the impact in practice is probably nil. Any such application would already be buggy on other platforms that get the semantics right. Also, these conversions are rarely used; %ls, %lc, and %l[ are more appropriate.
* Previously, vfscanf()'s wide character processing functions weredas2012-04-293-150/+83
| | | | | | | | | | | | | | | reading wide characters manually. With this change, they now use fgetwc(). To make this work, we use an internal version of fgetwc() with a few extensions: it takes an mbstate * because non-wide streams don't have a built-in mbstate, and it indicates the number of bytes read. vfscanf() now resembles vfwscanf() more closely. Minor functional improvements include working xlocale support in vfscanf(), setting the stream error indicator on encoding errors, and proper handling of shift-based encodings. (Actually, making shift-based encodings work with non-wide streams is hopeless, but the implementation now matches the broken specification.)
* Fix small documentation mistakes.jlh2012-04-281-1/+1
| | | | | Submitted by: brueffer Approved by: kib (mentor)
* Import stdbuf(1) and the shared library it relies on.jlh2012-04-281-0/+4
| | | | | | | | | | | | | | This tool changes the default buffering behaviour of standard stdio streams. It only works on dynamic binaries. To make it work for static ones it would require cluttering stdio because there no single entry point. PR: 166660 Reviewed by: current@, jhb Approved by: kib (mentor) MFC after: 1 week
* Take the spinlock around clearing of the fp->_flags in fclose(3), whichkib2012-04-242-9/+21
| | | | | | | | | indicates the avaliability of FILE, to prevent possible reordering of the writes as seen by other CPUs. Reported by: Fengwei yin <yfw.bsd gmail com> Reviewed by: jhb MFC after: 1 week
* Bugfix: Include whitespace characters in the count of the number ofdas2012-04-221-1/+1
| | | | characters read.
* Bugfix: Correctly count the number of characters read for %l[ conversions.das2012-04-221-7/+4
|
* Bugfix: %n doesn't count as a conversion, sodas2012-04-222-2/+0
| | | | sscanf("abc", "ab%ncd", &i) returns EOF, not 0.
* Refactor scanf to improve modularity. Conversions are now performeddas2012-04-222-668/+843
| | | | | | by separate conversion functions. This will hopefully make bugs more noticeable (I noticed several already) and provide opportunities to reduce code duplication.
* As noted by Peter Jeremy, r234528 only partially fixed the infinitedas2012-04-211-1/+1
| | | | | | | loop bug introduced in r187302. This completes the fix. PR: 167039 MFC after: 3 days
* If the size passed to {,v}s{w,n}printf is larger than INT_MAX+1das2012-04-215-6/+29
| | | | | | | | | | | | | | | | | (i.e., the return value would overflow), set errno to EOVERFLOW and return an error. This improves the chances that buggy applications -- for instance, ones that pass in a negative integer as the size due to a bogus calculation -- will fail in safe ways. Returning an error in these situations is specified by POSIX, but POSIX appears to have an off-by-one error that isn't duplicated in this change. Previously, some of these functions would silently cap the size at INT_MAX+1, and others would exit with an error after writing more than INT_MAX characters. PR: 39256 MFC after: 2 weeks
* - Fix the claim that the output is always null-terminated. This isn'tdas2012-04-211-17/+29
| | | | | | | | | | | true if the size is zero. - Fix a claim that sprintf() is the same as snprintf() with an infinite size. It's equivalent to snprintf() with a size of INT_MAX + 1. - Document the return values in the return values section. - Document the possible errno value of EOVERFLOW. MFC after: 2 weeks
* Ensure that the {,v}swprintf functions always null-terminate thedas2012-04-211-0/+3
| | | | output string, even if an encoding error or malloc failure occurs.
* Fix a bug introduced in r187302 that was causing fputws() to enter andas2012-04-211-1/+1
| | | | | | | | | infinite loop pretty much unconditionally. It's remarkable that the patch that introduced the bug was never tested, but even more remarkable that nobody noticed for over two years. PR: 167039 MFC after: 3 days
* Remove trailing whitespace per mdoc lint warningeadler2012-03-291-1/+1
| | | | | | | Disussed with: gavin No objection from: doc Approved by: joel MFC after: 3 days
* Remove outdated comment of seven yearseadler2012-03-041-7/+0
| | | | | | PR: docs/116116 Approved by: cperciva MFC after: 1 week
* Remove reference to gcc's non-standard -fwritable-strings, whicheadler2012-03-041-7/+1
| | | | | | | | | doesn't exist in recent releases (and is bad advice anyway) PR: docs/163119 Submitted by: Yuri Pankov <yuri.pankov@gmail.com> Approved by: cperciva MFC after: 1 week
* Implement xlocale APIs from Darwin, mainly for use by libc++. This adds atheraven2011-11-2042-182/+805
| | | | | | | | | | | | 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)
* Add support for the 'x' mode option in fopen() as specified in the C1Xdas2011-10-212-49/+60
| | | | | | draft standard. The option is equivalent to O_EXCL. MFC after: 1 month
* Because we call __printf_out() with a on-stack buffer, also callpjd2011-03-061-2/+4
| | | | | | __printf_flush() so we are sure it won't be referenced after we return. MFC after: 2 weeks
* Fix various issues in how %#T is handled:pjd2011-03-061-7/+11
| | | | | | | | | | - If precision is 0, don't print period followed by no digits. - If precision is 0 stop printing units as soon as possible (eg. if we have three years and five days and precision is 0 print only 3y5d). - If precision is not 0, print all units (eg. 3y0d0h0m0s.00). MFC after: 2 weeks
* When reopening a stream backed by an open file descriptor, do not closejhb2010-12-091-12/+9
| | | | | | | | | | | | | the existing file descriptor. Instead, let dup2() atomically close the old file descriptor when assigning the newly opened file to the same descriptor. This closes a race in a multithreaded application where a concurrent open() could allocate the existing file descriptor in between the calls to close() and dup2(). PR: threads/79887 Submitted by: Dmitrij Tejblum tejblum of yandex-team.ru Reviewed by: davidxu MFC after: 1 week
* Remove two unused variables, left over from the refactoring in r180104.gavin2010-12-021-6/+0
| | | | | | PR: bin/152551 Submitted by: Henning Petersen <henning.petersen t-online.de> MFC after: 2 weeks
* Update the documentation to reflect changes to the implementation indas2010-11-301-14/+14
| | | | | | | r197752, which is related to handling of null buffer pointers. Also make a few minor wording changes. Reported by: jh@
* Revert changes of 'assure' to 'ensure' made in r211936.brucec2010-09-111-1/+1
| | | | Approved by: rrs (mentor)
* Fix incorrect usage of 'assure' and 'insure'.brucec2010-08-281-1/+1
| | | | Approved by: rrs (mentor)
* mdoc: move CAVEATS, BUGS and SECURITY CONSIDERATIONS sections to theuqs2010-05-134-98/+98
| | | | | | | | | | | bottom of the manpages and order them consistently. GNU groff doesn't care about the ordering, and doesn't even mention CAVEATS and SECURITY CONSIDERATIONS as common sections and where to put them. Found by: mdocml lint run Reviewed by: ru
* mdoc: fix parenthesisuqs2010-05-111-2/+2
| | | | Reviewed by: brueffer
* mdoc: use macro for +- that is understood by mdocmluqs2010-05-112-4/+4
| | | | Reviewed by: brueffer
* I feel this wording of the history is more clear.obrien2010-04-052-9/+6
| | | | ANSIfy vasprintf() while I'm here.
* - Use an initializer macro to initialize fields in 'fake' FILE objects usedjhb2010-03-1112-39/+22
| | | | | | | | | | | | by *sprintf(), etc. - Explicitly initialize _fl_mutex to PTHREAD_MUTEX_INITIALIZER for all FILE objects. This is currently a nop on FreeBSD, but is import for other platforms (or in the future) where PTHREAD_MUTEX_INITIALIZER is not simply zero. PR: threads/141198 Reported by: Jeremy Huddleston @ Apple MFC after: 2 weeks
* In _gettemp(), check that the length of the path doesn't exceedjh2010-02-281-0/+4
| | | | | | | | MAXPATHLEN. Otherwise the path name (or part of it) may not fit to carrybuf causing a buffer overflow. PR: bin/140228 Suggested by: jilles
* %U was macroized in mdoc(7), escape.ru2010-02-161-1/+1
|
* Give a less silly response to a silly request.cperciva2010-01-102-3/+40
| | | | | | | | | | | | | | | | | | | | | | | | | Prior to this commit, fread/fwrite calls with size * nmemb > SIZE_MAX were handled by reading or writing (size_t)(size * nmemb) bytes; for example, on 32-bit platforms, fread(ptr, 641, 6700417, f) would read 1 byte and indicate that the requested 6700417 blocks had been read. This commit adds a check for such integer overflows, and treats them as if an overly large request was passed to read/write; i.e., it sets errno to EINVAL, sets the error indicator on the file, and returns a short object count (0, to be specific). The overflow check involves an integer division, so as a performance optimization we check first to see if both size and nmemb are less than 2^16; if they are, no overflow is possible and we avoid the division. We assume here that size_t is at least 32 bits; this appears to be true on all platforms FreeBSD supports. Although this commit fixes an integer overflow, it is not likely to have any security implications, since any program which would be affected by this bug fix is quite clearly already very confused. Reviewed by: kib MFC after: 1 month
* Remove unnecessary quoting and markup, add missing punctuation.brueffer2010-01-081-3/+2
| | | | | | PR: 140494 Submitted by: Jeremy Huddleston <jeremyhu@apple.com>, bde MFC after: 1 week
* Use vsprintf instead of rolling our own.delphij2009-12-211-9/+1
| | | | | | PR: bin/140496 Submitted by: Jeremy Huddleston <jeremyhu apple.com> MFC after: 1 month
* Use vsscanf instead of rolling our own.delphij2009-12-211-24/+1
| | | | | | PR: bin/140530 Submitted by: Jeremy Huddleston <jeremyhu apple.com> MFC after: 1 month
OpenPOWER on IntegriCloud