summaryrefslogtreecommitdiff
path: root/lib/libc/stdio/stdio.c
Commit message (Collapse)AuthorAgeFilesLines
* General further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-201-0/+2
| | | | | | | | | | | | | | | | | 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
* Make stdio deferred cancel-safe.Konstantin Belousov2017-06-291-0/+8
| | | | | | | | | | | | | | | | | | | | | | | 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
* Add _flags2 per jhb@ suggestion since no room left in _flags.Andrey A. Chernov2015-10-281-2/+1
| | | | | | | | | Rewrite O_APPEND flag checking using new __S2OAP flag. MFC after: 3 weeks Notes: svn path=/head/; revision=290110
* Since no room left in the _flags, reuse __SALC for O_APPEND.Andrey A. Chernov2015-10-241-1/+2
| | | | | | | | | | It helps to remove _fcntl() call from _ftello() and optimize seek position calculation in _swrite(). MFC after: 3 weeks Notes: svn path=/head/; revision=289863
* Convert libc/stdio from K&R to ANSI CEd Maste2013-04-231-26/+7
| | | | | | | And add '__restrict' where it appeared in the header prototypes Notes: svn path=/head/; revision=249810
* Renumber clauses to reduce diffs to other versionsEd Maste2013-04-231-1/+1
| | | | | | | | | | NetBSD, OpenBSD, and Android's Bionic all number the clauses 1 through 3, so follow suit to make comparison easier. Acked-by: imp@ Notes: svn path=/head/; revision=249808
* Retire the __fgetcookie(), __fgetpendout(), and __fsetfileno() accessorsJohn Baldwin2008-05-051-21/+0
| | | | | | | as we aren't hiding FILE's internals anymore. Notes: svn path=/head/; revision=178782
* Unbreak build: gnu sort has been configured to grope inside structMarcel Moolenaar2008-05-031-0/+7
| | | | | | | | | | __sFILE. It's opaque now, so add a function that returns the pending output bytes. Pointy hat: jhb Notes: svn path=/head/; revision=178755
* Unbreak build: libftpio gropes inside struct __sFILE. ImplementMarcel Moolenaar2008-05-031-0/+14
| | | | | | | | | | | accessor functions for its benefit now thaat FILE is opaque. I'm sure there's a better way. I leave that for people to work on in a src tree that isn't broken. Pointy hat: jhb Notes: svn path=/head/; revision=178747
* Per Regents of the University of Calfornia letter, remove advertisingWarner Losh2007-01-091-4/+0
| | | | | | | | | clause. # If I've done so improperly on a file, please let me know. Notes: svn path=/head/; revision=165903
* #include <stdlib.h> for free()'s prototype.Tim J. Robbins2003-01-071-0/+1
| | | | Notes: svn path=/head/; revision=108866
* Fix the style of the SCM ID's.David E. O'Brien2002-03-221-4/+2
| | | | | | | I believe have made all of libc .c's as consistent as possible. Notes: svn path=/head/; revision=92986
* Remove 'register' keyword.David E. O'Brien2002-03-211-3/+3
| | | | Notes: svn path=/head/; revision=92889
* Help to recover from bad seek (i.e. negative or too big) happens beyondAndrey A. Chernov2001-10-241-0/+7
| | | | | | | | our pre-check control. Do the same way as refill.c does when it set __SERR, i.e. clear read and ungetc buffers. Clear EOF flag too. Notes: svn path=/head/; revision=85418
* Back out read buffer invalidating via __SMOD.Andrey A. Chernov2001-10-231-5/+0
| | | | | | | | It was correct, but not needed because internal buffer cleared on each seek outside of it. Notes: svn path=/head/; revision=85396
* Disallow fseek() optimization in internal read buffer, if pointer is moved byAndrey A. Chernov2001-10-231-0/+5
| | | | | | | | seek. It means that beginning of read buffer becomes not the same as current file position. Notes: svn path=/head/; revision=85391
* 1) If __SAPP stream is not seekable, remove __SAPP flag on first call insteadAndrey A. Chernov2001-09-071-3/+10
| | | | | | | | | | | | of repeating unsuccessful lseek call on each write (original stdio bug). 2) Save errno accross _sseek call in _swrite to not touch it in case write success (original stdio bug). 3) Add _sseek error checking back, but only for __SOPT mode now. Notes: svn path=/head/; revision=83211
* For now just back out seek error checking in __SAPP case, it cause problemsAndrey A. Chernov2001-09-071-2/+2
| | | | | | | | | with non-seekable streams. Now here is what here was originally, but it is ugly, producing unneded seek syscall on each non-seekable stream write. I'll think about proper solution later. Notes: svn path=/head/; revision=83177
* Re-arrange my funopen(3) fix to minimize differences with original stdio code,Andrey A. Chernov2001-09-031-0/+83
| | | | | | | | | no functional changes. Add fp->_offset optimization in _SAPP+_SOPT case Notes: svn path=/head/; revision=82838
* Move all stdio internal flags processing and setting out of __sread(),Andrey A. Chernov2001-09-021-47/+2
| | | | | | | | | | | | | __swrite() and __sseek() to higher level. According to funopen(3) they all are just wrappers to something like standard read(2), write(2) and lseek(2), i.e. must not touch stdio internals because they are replaceable with any other functions knows nothing about stdio internals. See example of funopen(3) usage in sendmail sources f.e. NOTE: this is original stdio bug, not result of my range checkin added. Notes: svn path=/head/; revision=82807
* If lseek to wrong value sucessfully happens despite all pre-checks, set __SERRAndrey A. Chernov2001-09-011-1/+3
| | | | | | | to indicate that stream becomes inconsistent. Notes: svn path=/head/; revision=82735
* Detect fp->_offset overflow on readAndrey A. Chernov2001-08-311-9/+23
| | | | | | | Use errno to catch negative seek with -1 offset Notes: svn path=/head/; revision=82653
* Remove extra check, already done in upper level caller, i.e. inAndrey A. Chernov2001-08-171-5/+1
| | | | | | | _fseeko() Notes: svn path=/head/; revision=81821
* 1) Disallow negative seek as POSIX require for fseek{o} (but not for lseek):Andrey A. Chernov2001-08-151-2/+17
| | | | | | | | | | | | | | | "[EINVAL] ... The resulting file-position indicator would be set to a negative value." Moreover, in real life negative seek in stdio cause EOF indicator cleared and not set again forever even if EOF returned. 2) Catch few possible off_t overflows. Reviewed by: arch discussion Notes: svn path=/head/; revision=81666
* Remove _THREAD_SAFE and make libc thread-safe by default byDaniel Eischen2001-01-241-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | adding (weak definitions to) stubs for some of the pthread functions. If the threads library is linked in, the real pthread functions will pulled in. Use the following convention for system calls wrapped by the threads library: __sys_foo - actual system call _foo - weak definition to __sys_foo foo - weak definition to __sys_foo Change all libc uses of system calls wrapped by the threads library from foo to _foo. In order to define the prototypes for _foo(), we introduce namespace.h and un-namespace.h (suggested by bde). All files that need to reference these system calls, should include namespace.h before any standard includes, then include un-namespace.h after the standard includes and before any local includes. <db.h> is an exception and shouldn't be included in between namespace.h and un-namespace.h namespace.h will define foo to _foo, and un-namespace.h will undefine foo. Try to eliminate some of the recursive calls to MT-safe functions in libc/stdio in preparation for adding a mutex to FILE. We have recursive mutexes, but would like to avoid using them if possible. Remove uneeded includes of <errno.h> from a few files. Add $FreeBSD$ to a few files in order to pass commitprep. Approved by: -arch Notes: svn path=/head/; revision=71579
* Simplify sytem call renaming. Instead of _foo() <-- _libc_foo <-- foo(),Jason Evans2000-01-271-3/+3
| | | | | | | | | | | | | | | | | | | | just use _foo() <-- foo(). In the case of a libpthread that doesn't do call conversion (such as linuxthreads and our upcoming libpthread), this is adequate. In the case of libc_r, we still need three names, which are now _thread_sys_foo() <-- _foo() <-- foo(). Convert all internal libc usage of: aio_suspend(), close(), fsync(), msync(), nanosleep(), open(), fcntl(), read(), and write() to _foo() instead of foo(). Remove all internal libc usage of: creat(), pause(), sleep(), system(), tcdrain(), wait(), and waitpid(). Make thread cancellation fully POSIX-compliant. Suggested by: deischen Notes: svn path=/head/; revision=56698
* Add three-tier symbol naming in support of POSIX thread cancellationJason Evans2000-01-121-3/+3
| | | | | | | | | points. For library functions, the pattern is __sleep() <-- _libc_sleep() <-- sleep(). The arrows represent weak aliases. For system calls, the pattern is _read() <-- _libc_read() <-- read(). Notes: svn path=/head/; revision=55837
* $Id$ -> $FreeBSD$Peter Wemm1999-08-281-1/+1
| | | | Notes: svn path=/head/; revision=50476
* Revert $FreeBSD$ to $Id$Peter Wemm1997-02-221-1/+1
| | | | Notes: svn path=/head/; revision=22993
* Make the long-awaited change from $Id$ to $FreeBSD$Jordan K. Hubbard1997-01-141-1/+1
| | | | | | | | | | | This will make a number of things easier in the future, as well as (finally!) avoiding the Id-smashing problem which has plagued developers for so long. Boy, I'm glad we're not using sup anymore. This update would have been insane otherwise. Notes: svn path=/head/; revision=21673
* Suggested by: Bruce Evans, Jeffrey Hsu, Gary PalmerJames Raynard1996-06-221-6/+13
| | | | | | | | | | | | | | | | | | | | | | | | Added $Id$'s to files that were lacking them (gpalmer), made some cosmetic changes to conform to style guidelines (bde) and checked against NetBSD and Lite2 to remove unnecessary divergences (hsu, bde) One last code cleanup:- Removed spurious casts in fseek.c and stdio.c. Added missing function argument in fwalk.c. Added missing header include in flags.c and rget.c. Put in casts where int's were being passed as size_t's. Put in missing prototypes for static functions. Changed second args of __sflags() inflags.c and writehook() in vasprintf.c from char * to const char * to conform to prototypes. This directory now compiles with no warnings with -Wall under gcc-2.6.3 and with considerably less warnings than before with the ultra-pedantic script I used for testing. (Most of the remaining ones are due to const poisoning). Notes: svn path=/head/; revision=16586
* Code cleanup:-James Raynard1996-06-121-3/+3
| | | | | | | | | | The usual stuff, adding missing function prototypes, argument types, return values, etc. This directory now compiles with no warnings with -Wall on gcc2.6.3! Notes: svn path=/head/; revision=16337
* Remove trailing whitespace.Rodney W. Grimes1995-05-301-2/+2
| | | | Notes: svn path=/head/; revision=8870
* BSD 4.4 Lite Lib SourcesRodney W. Grimes1994-05-271-0/+104
Notes: svn path=/cvs2svn/branches/unlabeled-1.1.1/; revision=1573