summaryrefslogtreecommitdiff
path: root/lib/libc/stdio
Commit message (Collapse)AuthorAgeFilesLines
* Follow up on r331936. gets_s(3) will also fail in the same way thatCy Schubert2018-10-281-0/+2
| | | | | | | | | | gets(3) does. This was missed in r331936. Reported by: emaste@ Approved by: re (kib@) Notes: svn path=/stable/12/; revision=339828
* Implement printf(3) family %m format string extension.Konstantin Belousov2018-05-222-1/+28
| | | | | | | | | Reviewed by: ed, dim (code only) Sponsored by: Mellanox Technologies MFC after: 1 week Notes: svn path=/head/; revision=334031
* Conform to Berne Convention.Cy Schubert2018-05-191-1/+1
| | | | | | | | Prompted by: Recent discussion MFC after: 3 days Notes: svn path=/head/; revision=333895
* Don't put multiple names on a single .Nm line. This fixes apropos(1)Edward Tomasz Napierala2018-04-171-2/+12
| | | | | | | | | | | | | | | | 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
* The correct symbol version for FreeBSD 12 is 1.5.Cy Schubert2018-04-031-1/+4
| | | | | | | | | | Reported by: kib@ MFC after: 2 weeks X-MFC with: r331936 Differential Revision: https://reviews.freebsd.org/D12785 Notes: svn path=/head/; revision=331947
* Correct the version number for gets_s(3).Cy Schubert2018-04-031-1/+1
| | | | | | | | | | Reported by: kib@ MFC after: 2 weeks X-MFC with: r331936 Differential Revision: https://reviews.freebsd.org/D12785 Notes: svn path=/head/; revision=331945
* Add gets_s(3) to the man page title (noticed by ed@).Cy Schubert2018-04-031-2/+3
| | | | | | | | | | | | While I'm at it correct the update date in the man page. Reported by: ed@ MFC after: 2 weeks X-MFC with: r331936 Differential Revision: https://reviews.freebsd.org/D12785 Notes: svn path=/head/; revision=331942
* Add new gets_s(3) stdio function.Cy Schubert2018-04-034-3/+129
| | | | | | | | | | | | | | This implements the gets_s(3) function as documented at http://en.cppreference.com/w/c/io/gets. It facilitates the optional removal of gets(3). Reviewed by: ed MFC after: 2 weeks Relnotes: yes Differential Revision: https://reviews.freebsd.org/D12785 Notes: svn path=/head/; revision=331936
* __printf_render_int(): small type change to match use.Pedro F. Giffuni2018-02-231-2/+2
| | | | | | | | | | | Variable l is consistently used as an int rather than a char. Sort names while here. Obtained from: Apple's Libc-1244.30.3 MFC after: 5 days Notes: svn path=/head/; revision=329848
* fsync(3): correctly document return valuesEitan Adler2017-12-251-5/+8
| | | | | | | | | | In r268924 the behavior of fflush was changed to return success on read only streams. Document this. Reported by: zrj@DragonFlyBSD.org Notes: svn path=/head/; revision=327181
* fopen.1: document truncationEitan Adler2017-12-231-1/+1
| | | | | | | | | | This documentation truncation similar to POSIX and glibc. PR: 202545 Reported by: intron@intron.ac Notes: svn path=/head/; revision=327099
* The function fwscanf() return value is wrong when encountering an earlyStephen J. Kiernan2017-12-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | matching failure. According to the Open Group documentation for fwscanf: "Upon successful completion, these functions shall return the number of successfully matched and assigned input items; this number can be zero in the event of an early matching failure." Without this change, fwscanf would return EOF in the case of an early matching failure, instead of the proper return value of 0. This change aligns fwscanf(3) with the implementation in fscanf(3). PR: 202240 Submitted by: rajendra.sy@gmail.com Reviewed by: jhb, cem Approved by: sjg (mentor) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D13288 Notes: svn path=/head/; revision=326635
* Truncate negative lengths to zeroPoul-Henning Kamp2017-11-271-1/+5
| | | | Notes: svn path=/head/; revision=326246
* libc: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-2533-2/+68
| | | | | | | | | | | | | | | 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-2082-4/+168
| | | | | | | | | | | | | | | | | 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
* While discussing the new gets_s.c in D12785, ed@ suggested puttingCy Schubert2017-11-031-2/+2
| | | | | | | | | | | | {}'s around the if (c == EOF) block to prevent potential 'trailing else' issues from being introduced when refactoring. As my gets_s() code is based on this, it makes sense to fix the same issue here first here and now, then do an svn copy again to capture this history). Suggested by: ed@ in D12785 Notes: svn path=/head/; revision=325357
* Revert r325031. This breaks the build due to __FBSDID.Cy Schubert2017-10-271-1/+1
| | | | | | | Pointy hat to: cy Notes: svn path=/head/; revision=325032
* Ensure all incude statements are kept together by moving theCy Schubert2017-10-271-1/+1
| | | | | | | | | | sys/cdefs.h include appropriately. MFC after: 1 week X-MFC with: r325030 Notes: svn path=/head/; revision=325031
* Remove redundant sys/cdefs.h include.Cy Schubert2017-10-271-1/+0
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=325030
* In the stdio cleanup push and pop wrappers, always call libc stubs forKonstantin Belousov2017-06-301-3/+3
| | | | | | | | | | | | | | | | | | __pthread_cleanup_push/pop_imp instead of symbols also exported from libthr. This prevents calls into libthr if libthr is not yet initialized. The situation occurs e.g. when an LD_PRELOADed object is not linked against libthr, but the main binary is. Reported and tested by: jbeich PR: 220381 Discussed with: vangyzen Sponsored by: The FreeBSD Foundation MFC after: 13 days Notes: svn path=/head/; revision=320509
* Fix typo in the r320472 change to fgetws(). Return proper value.Konstantin Belousov2017-06-301-1/+1
| | | | | | | | | | Reported by: Oleg Ginzburg <olevole@olevole.ru> Reviewed by: vangyzen Sponsored by: The FreeBSD Foundation MFC after: 13 days Notes: svn path=/head/; revision=320508
* Make stdio deferred cancel-safe.Konstantin Belousov2017-06-2938-138/+185
| | | | | | | | | | | | | | | | | | | | | | | If used with fopen(3)/fdopen(3)-ed FILEs, stdio accurately uses non-cancellable internal versions of the functions, i.e. it seems to be fine with regard to cancellation. But if the funopen(3) and f{r,w}open(3) functions were used to open the FILE, and corresponding user functions create cancellation points (they typically have no other choice), then stdio code at least leaks FILE' lock. The change installs cleanup handler which unlocks FILE. Some minimal restructuring of the code was required to make it use common return place to satisfy hand-rolled pthread_cleanup_pop() requirements. Noted by: eugen Reviewed by: eugen, vangyzen Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D11246 Notes: svn path=/head/; revision=320472
* fopencookie(3): declare function pointers in SYNOPSIS correctlyEnji Cooper2017-05-231-4/+4
| | | | | | | | | | | Add obligatory `*` in declarations. Reported by: make manlint MFC after: 2 weeks Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=318711
* fopen(3): make manlint fixesEnji Cooper2017-05-231-5/+10
| | | | | | | | | | | | - Break on new lines. - Use .Dv with NULL. - Rewrap lines as necessary/when possible. MFC after: 2 weeks Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=318705
* libc: provide some bounds-checking through reallocarray(3).Pedro F. Giffuni2017-03-123-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
* libc: small cleanup.Pedro F. Giffuni2017-03-121-1/+2
| | | | | | | | Initialize newsize in the code section so we avoids asigning the value if we exit early. Notes: svn path=/head/; revision=315104
* Renumber copyright clause 4Warner Losh2017-02-2834-34/+34
| | | | | | | | | | | | Renumber cluase 4 to 3, per what everybody else did when BSD granted them permission to remove clause 3. My insistance on keeping the same numbering for legal reasons is too pedantic, so give up on that point. Submitted by: Jan Schaumann <jschauma@stevens.edu> Pull Request: https://github.com/freebsd/freebsd/pull/96 Notes: svn path=/head/; revision=314436
* Revert r310138Enji Cooper2016-12-221-31/+0
| | | | | | | | | | | | | | | Adding %b support to vfprintf for parity with kernel space requires more discussion/review. In particular, many parties were concerned over introducing a non-standard format qualifier to *printf(3) which didn't already exist in other OSes, e.g. Linux, thus making code which used %b harder to port to other operating systems. Requested by: many Notes: svn path=/head/; revision=310433
* vfprintf(3): Add support for kernel %b formatConrad Meyer2016-12-161-0/+31
| | | | | | | | | | | | | | | This is a direct port of the kernel %b format. I'm unclear on if (more) non-portable printf extensions will be a problem. I think it's desirable to have userspace formats include all kernel formats, but there may be competing goals I'm not aware of. Reviewed by: no one, unfortunately Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D8426 Notes: svn path=/head/; revision=310138
* Detect integer overflow and limit the number of positionalRuslan Bukin2016-10-311-12/+33
| | | | | | | | | | | arguments in the string format. Sponsored by: DARPA, AFRL Sponsored by: HEIF5 Differential Revision: https://reviews.freebsd.org/D8286 Notes: svn path=/head/; revision=308145
* Fix error handling.Andrey A. Chernov2016-09-051-4/+10
| | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=305413
* Fix n == 1 case. Here should be no physical read (fill buffer) attemptAndrey A. Chernov2016-09-051-2/+6
| | | | | | | | | | (we read n - 1 chars with the room for NUL, see fgets()), and no NULL return. MFC after: 3 days Notes: svn path=/head/; revision=305412
* 1) Prevent out of bounds access to ws[-1] (passed buffer) which happensAndrey A. Chernov2016-09-051-2/+2
| | | | | | | | | | | | | when the first mb sequence is incomplete and there are not enougn chars in the read buffer. ws[-1] may lead to memory faults or false results, in case the memory here contains '\n'. 2) Fix EOF checking I mess in my previos r305406 commit. MFC after: 3 days Notes: svn path=/head/; revision=305409
* Fix errors handling.Andrey A. Chernov2016-09-051-6/+18
| | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=305406
* fgetwc(3) may set both __SEOF and __SERR at once (in case of incompleteAndrey A. Chernov2016-09-011-1/+11
| | | | | | | | | | | sequence near EOF), so we can't just check for (wc == WEOF && !__sfeof(fp)) and must relay on __sferror(fp) with __SERR clearing/restoring. MFC after: 7 days Notes: svn path=/head/; revision=305241
* If error happens, don't overwrite original errno comes from __mbrtowc()Andrey A. Chernov2016-09-011-5/+8
| | | | | | | | | and __srefill(). MFC after: 3 days Notes: svn path=/head/; revision=305219
* Original fgetln() from 44lite return sucess for line tail errors,Andrey A. Chernov2016-08-252-4/+6
| | | | | | | | | | | | | | i.e. partial line, but set __SERR and errno in the same time, which is inconsistent. Now both OpenBSD and NetBSD return failure, i.e. no line and set error indicators for such case, so make our fgetln() and fgetwln() (as its wide version) compatible with the rest of *BSD. PR: 212033 MFC after: 7 days Notes: svn path=/head/; revision=304819
* Remove "Fast path", it bypass __wcrtomb() and all its error checking.Andrey A. Chernov2016-08-251-13/+3
| | | | | | | | | One of affected encoding example: US-ASCII MFC after: 7 days Notes: svn path=/head/; revision=304811
* Don't check for __SERR which may stick from one of any previous stdioAndrey A. Chernov2016-08-253-2/+14
| | | | | | | | | | functions. __SERR is for user and the rest of stdio code do not check it for error sensing internally, only set it. In vf(w)printf.c here it is more easy to save __SERR, clear and restore it. Notes: svn path=/head/; revision=304810
* 1) Back out r304607 case 2). fgetwln() as its pair fgetln() supposed toAndrey A. Chernov2016-08-222-24/+7
| | | | | | | | | | | | | | return partial line on any errors. See the comment in fgetln.c. Add corresponding comment to fgetwln() too. 2) Rewrite r304607 case 1). 3) Remove "Fast path" from __fgetwc_mbs() since it can't detect encoding errors and ignores them all. PR: 212033 MFC after: 7 days Notes: svn path=/head/; revision=304641
* Fix error processing.Andrey A. Chernov2016-08-221-1/+13
| | | | | | | | | | | | | 1) Don't forget to set __SERR on __slbexpand() error. 2) Check for __fgetwc() errors using errno. Don't check for __SERR as PR suggested, it user-visible flag which can stick from previous functions and stdio code don't check it for this purpose. PR: 212033 MFC after: 3 days Notes: svn path=/head/; revision=304607
* Remove usage of _WITH_DPRINTFBaptiste Daroussin2016-07-301-1/+0
| | | | Notes: svn path=/head/; revision=303529
* Remove last traces of _WITH_GETLINEBaptiste Daroussin2016-07-301-1/+0
| | | | Notes: svn path=/head/; revision=303528
* Remove _WITH_GETLINE and _WITH_DPRINTF guardsBaptiste Daroussin2016-07-302-60/+2
| | | | | | | | | | | | | When adding getline(3) and dprintf(3) into libc, those guards were added to prevent breaking too many ports. 7 years later the ports tree have been fixed, it is time to remove this FreeBSDism While here remove the extra parenthesis surrounding dprintf(3) Notes: svn path=/head/; revision=303524
* 1) Eliminate possibility to call __*collate_range_cmp() with inclompleteAndrey A. Chernov2016-07-141-3/+3
| | | | | | | | | | | | | | | locale (which cause core dump) by removing whole 'table' argument by which it passed. 2) Restore __collate_range_cmp() in __sccl(). 3) Collating [a-z] range in regcomp() only for single bytes locales (we can't do it now for other ones). In previous state only first 256 wchars are considered and all others are just silently dropped from the range. Notes: svn path=/head/; revision=302824
* Back out non-collating [a-z] ranges.Andrey A. Chernov2016-07-141-5/+22
| | | | | | | | | | Instead of changing whole course to another POSIX-permitted way for consistency and uniformity I decide to completely ignore missing regex fucntionality and concentrace on fixing bugs in what we have now, too many small obstacles instead, counting ports. Notes: svn path=/head/; revision=302820
* Remove broken support for collation in [a-z] type ranges.Andrey A. Chernov2016-07-101-22/+5
| | | | | | | | | | | | | | | | | | | | | Only first 256 wide chars are considered currently, all other are just dropped from the range. Proper implementation require reverse tables database lookup, since objects are really big as max UTF-8 (1114112 code points), so just the same scanning as it was for 256 chars will slow things down. POSIX does not require collation for [a-z] type ranges and does not prohibit it for non-POSIX locales. POSIX require collation for ranges only for POSIX (or C) locale which is equal to ASCII and binary for other chars, so we already have it. No other *BSD implements collation for [a-z] type ranges. Restore ABI compatibility with unused now __collate_range_cmp() which is visible from outside (will be removed later). Notes: svn path=/head/; revision=302512
* Fix regression from r301461.Pedro F. Giffuni2016-06-101-3/+3
| | | | | | | | | | | | | | | The fix to the __collate_range_cmp() ABI breakage missed some replacements in libc's vfscanf(). Replace them with __wcollate_range_cmp() which does what is expected. This was breaking applications like xterm and pidgin when using wide characters. Reported by: Vitalij Satanivskij Approved by: re Notes: svn path=/head/; revision=301777
* libc: Actually export fopencookie(3)Conrad Meyer2016-05-121-0/+1
| | | | | | | | | A follow-up to r299456. Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=299572
* libc: Add fopencookie(3) wrapper around funopen(3)Conrad Meyer2016-05-114-3/+329
| | | | | | | | | Reviewed by: jhb, oshogbo Sponsored by: EMC / Isilon Storage Division Differential Revision: https://reviews.freebsd.org/D6282 Notes: svn path=/head/; revision=299456