Home | History | Annotate | only in /src/lib/libc/stdio
History log of /src/lib/libc/stdio
RevisionDateAuthorComments
 1.51 07-Jul-2025  rillig jemalloc, stdio: skip lint warning 207

It has been disabled a few minutes ago and will be removed in a few
minutes.
 1.50 09-Dec-2024  maya PR lib/58850: add man page link for snprintf_ss
 1.49 20-Jan-2024  christos branches: 1.49.2;
Catch up with all the lint warnings since exit on warning was disabled.
Disable 'missing header declaration' and 'nested extern' warnings for now.
 1.48 04-Apr-2023  christos PR/57250: Martin Husemann: dtoa mishandles infinite doubles on 32bit big
endian machines. When long double support was added, the old code was kept
for the regular double code. This code was never used because WIDE_DOUBLE
was always defined in the Makefile. Remove that old code, and conditionalize
the WIDE_DOUBLE code based on if long doubles are different than doubles on
the specific platform.
 1.47 29-Dec-2015  christos branches: 1.47.18; 1.47.26;
Add printf/scanf man pages from FreeBSD
 1.46 13-Oct-2014  christos PR/49279: Justin Cormack: add open_memstream
 1.45 18-Jun-2014  christos more man pages links
 1.44 18-Jun-2014  christos add mkostemp, mkostemps, mkstemps from FreeBSD.
 1.43 16-Jan-2014  christos branches: 1.43.2;
"soon" is "now". Remove all __indr_reference crap.
 1.42 19-Apr-2013  joerg Add explicit locale versions for the printf family. Replace asprintf,
snprintf and sprintf with simple wrappers around the corresponding
va_list functions to reduce code duplication.
 1.41 27-Mar-2012  christos branches: 1.41.2;
- widen the internal read and write calls to match the syscalls
- add funopen2() which provides access to flush() and the wider calls.
- make use of the new flush call in fmemopen()
 1.40 22-Dec-2010  christos branches: 1.40.6;
document vsnprintf_ss
 1.39 24-Sep-2010  christos add man page as promised.
 1.38 24-Sep-2010  tnozaki add fmemopen(3) derrived from POSIX:2008.
libc minor bump.
 1.37 06-Sep-2010  christos add dprintf and vdprintf
 1.36 13-Jul-2009  roy Add implementations for getdelim(3) and getline(3).
 1.35 03-Feb-2007  christos enable wide doubles.
 1.34 27-Oct-2006  christos branches: 1.34.2;
Add signal-safe versions of snprintf and vsnprintf
 1.33 16-Feb-2006  christos - s/notyet/WIDE_DOUBLE/
- Add a little more glue for WIDE_DOUBLE; not done yet.
- s/def FLOATING_POINT/ndef NO_FLOATING_POINT/ to reduce diffs with FreeBSD.
- fix memory leak where each double formatted leaked 24 by calling __freedtoa()
appropriately. the new gdtoa keeps a list of memory chunks allocated by
malloc(), and it must maintained properly by calling __freedtoa() on the
results of __dtoa() Hi Klaus!
- in vfwprintf() make cvt return char * and convert it using __mbsconv(),
instead of having it return wchar_t *.

This should fix the memory leaks people have been reporting (eg. in top etc.)
 1.32 28-Jul-2005  christos PR/30845: Luke Mewburn: strerror_r(3) missing
- Merge 4.4BSD strerror.3 man page changes that summarize information
for all the error printing functions. This makes the perror(3) page
obsolete.
- Implement all error functions in terms of strerror_r(), including
__strerror() which is not used internally. Can it be removed?
- Bump version for strerror_r
 1.31 12-Jun-2005  lukem vfwprintf.c and vfwscanf.c now compile with -Wuninitialized
 1.30 01-Jun-2005  lukem Compile the following files with -Wno-uninitialized:
vfprintf.c See rev 1.46 for why we can't fix this.
vfwprintf.c Needs some effort
vfwscanf.c Needs some effort
 1.29 14-May-2005  christos Add the missing wide char support functions from freebsd.
XXX: long double support is missing until we get gdtoa, and add the
necessary wide functions.
 1.28 10-May-2004  drochner remove the fgetstr manpage
 1.27 09-May-2004  kleink We now need an internal name for fileno(), since when buildling libc
_REENTRANT we can no longer use the macro version from <stdio.h>.
 1.26 21-Apr-2004  christos Add a generalized version of fgetln that can stop at an arbitrary delimiter,
and implement fgetln on top of that.
 1.25 07-Mar-2003  tshiozak branches: 1.25.2;
add fgetws() and fputws() (lib/20576).

Note: fgetws.c, fgetws.3, fputws.c and fputws.3 are obtained from FreeBSD,
and fitted by sigsegv@infoseek.jp and me.
 1.24 28-Jan-2003  kleink Add a manual page for flockfile(3) etc.; while here, also add *_unlocked()
to stdio(3) overview documentation. Fixes PR lib/20096 from Jason Thorpe.
 1.23 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.22 30-Nov-2002  lukem - Migrate fparseln(3) from libutil to libc, where it should have been in
the first place...
- Bump libutil major (to 7.0) and libc minor (to 12.91).
 1.21 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.20 25-Apr-2001  kleink Document getc_unlocked(3), getchar_unlocked(3), putc_unlocked(3) and
putchar_unlocked(3); fixes PR lib/11340.
 1.19 08-Jul-2000  kleink branches: 1.19.2;
XCU5: Add fseeko() and ftello() functions which provide the functionality of
fseek() and ftell(), respectively, but operate on file offsets of type off_t.
 1.18 30-Aug-1998  perry make sure asprintf and vasprintf get MLINKS to printf.3
 1.17 28-Aug-1998  perry add asprintf and vasprintf, originally written by Todd Miller for OpenBSD
 1.16 27-Jul-1998  mycroft Document mkdtemp(3).
 1.15 27-Jul-1998  mycroft Actually, FreeBSD calls this mkdtemp(). No point in creating a new name.
 1.14 27-Jul-1998  mycroft Add a mktempdir(), like mkstemp(), but it creates a directory.
 1.13 27-Jul-1998  mycroft If AUDIT, do not compile certain functions.
 1.12 22-Oct-1997  lukem - use CPPFLAGS instead of CFLAGS
- use ${COMPILE.C} ... instead of ${CC} ${CFLAGS} -c ...
 1.11 02-Apr-1997  kleink branches: 1.11.2;
RCSid police
 1.10 25-Feb-1995  cgd mktemp.c belongs here, not gen/Makefile.inc
 1.9 02-Feb-1995  jtc revert
 1.7 22-Dec-1994  cgd specify man pages the new way.
 1.6 19-Sep-1994  mycroft Move FLOATING_POINT definition into Makefile.inc.
 1.5 04-Jan-1994  cgd rename fgetline() and sharpen axe for bostic...
 1.4 18-Oct-1993  cgd don't compiler strerror.c source here, and clean up.
 1.3 07-Oct-1993  jtc Moved strerror.[c3] from libc/stdio to libc/string.
Since perror is not permitted to change strerror()'s static buffer, I have
changed both functions to pass their own buffers to the new library-internal
function _strerror() that actually does the error message string look up.
Split strerror manpage into strerror and perror manpages.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11.2.1 09-Nov-1997  lukem sync with trunk (approved by thorpej)
 1.19.2.4 10-Dec-2002  thorpej Sync with HEAD.
 1.19.2.3 06-Feb-2002  nathanw Implement flockfile(), ftrylockfile(), and funlockfile().
(Ewwww. Recursive mutexes.)
 1.19.2.2 28-Jan-2002  nathanw Catch up to -current.
 1.19.2.1 08-Oct-2001  nathanw Catch up to -current.
 1.25.2.1 11-May-2004  tron Pull up revision 1.27 (requested by kleink in ticket #311):
We now need an internal name for fileno(), since when buildling libc
_REENTRANT we can no longer use the macro version from <stdio.h>.
 1.34.2.1 07-May-2007  pavel Pull up following revision(s) (requested by manu in ticket #607):
lib/libc/arch/i386/gen/isnanl.c: revision 1.6
lib/libc/gdtoa/gdtoa.c: revision 1.2-1.3
lib/libc/arch/x86_64/gen/isnanl.c: revision 1.6
lib/libc/gdtoa/gdtoaimp.h: revision 1.6
sys/arch/m68k/include/ieee.h: revision 1.13
usr.bin/xlint/lint1/scan.l: revision 1.36-1.37
lib/libc/stdio/snprintf_ss.c: revision 1.4
lib/libc/arch/i386/gen/isfinitel.c: revision 1.2
lib/libc/stdio/vfscanf.c: revision 1.38
sys/arch/sparc/include/ieee.h: revision 1.11-1.12
lib/libc/gdtoa/dtoa.c: revision 1.4
lib/libc/stdio/Makefile.inc: revision 1.35
lib/libc/stdio/fvwrite.c: revision 1.17
lib/libc/arch/m68k/gen/fpclassifyl.c: revision 1.2
lib/libc/arch/i386/gen/isinfl.c: revision 1.6
lib/libc/arch/x86_64/gen/isinfl.c: revision 1.6
lib/libc/arch/x86_64/gen/isfinitel.c: revision 1.2
lib/libc/stdio/vfprintf.c: revision 1.55-1.57
lib/libc/stdio/vsnprintf_ss.c: revision 1.3
lib/libc/stdio/vfwprintf.c: revision 1.10
sys/arch/x86/include/ieee.h: revision 1.10
lib/libc/gdtoa/dmisc.c: revision 1.3
lib/libc/gdtoa/Makefile.inc: revision 1.5
sys/arch/hppa/include/ieee.h: revision 1.10
lib/libc/arch/x86_64/gen/fpclassifyl.c: revision 1.3
lib/libc/arch/i386/gen/fpclassifyl.c: revision 1.2
sys/sys/ieee754.h: revision 1.7
lib/libc/gdtoa/gdtoa.h: revision 1.7
include/stdio.h: revision 1.67-1.68
lib/libc/gdtoa/hdtoa.c: revision 1.1-1.4
lib/libc/gdtoa/ldtoa.c: revision 1.1-1.4
defined(_NETBSD_SOURCE) is equivalent to (!defined(_ANSI_SOURCE) &&
!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)), so there's no
need to check both of them.
Fix for issue reported in PR lib/35401 as well as related overflow bugs.
deal with hex doubles.
Instead of abusing stdio to get a signal-safe version of sprintf, provide one.
remove __SAFE
add long double and hex double support from freebsd.
make this compile.
add new prototypes.
add the new files to the build. Note I am not bumping libc now, because
these are not used yet.
Merge the int bit with the high fraction bit. Add constants/macros
needed by gdtoa.
add constants used by gdtoa
since the int bit is merged, do the explicit math.
ext_int bit is no more.
ext_int bit is no more.
- merge change from freebsd
- add support for building as vfprintf.c
- XXX: we strdup to simplify the freeing logic. This should be fixed for
efficiency in the vfprintf case.
use vfwprintf.c
enable wide doubles.
some int -> size_t
deal with sparc64 that has 112 bits of mantissa.
make extended precision gdtoa friendly.
int/size_t changes
make this gdtoa friendly.
remove dup definition
use dtoa() instead of returning empty when we don't have extended precision
information.
Fix previous, add forgotten pointer dereference in the call to dtoa().
Add a cheesy workaround marked XXX for the situation where the
strtod() implementation available in the environment does not
handle hex floats.
Discussed with and suggested by christos
From Christos: gdtoa fixes for m68k. M68k ports should build now, but
printing extended precision is a little off.
vax does not have <machine/ieee.h> or long double
It would be nice if the compiler provided something like __IEEE_MATH__
bring in FreeBSD's vfscanf() to gain multi-byte/collation support.
Unfortunately it is too difficult to make vfwscanf and this share
the same code like I did with printf, because for string parsing
the code is too different.
 1.40.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.40.6.1 17-Apr-2012  yamt sync with head
 1.41.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.41.2.1 23-Jun-2013  tls resync from head
 1.43.2.1 10-Aug-2014  tls Rebase.
 1.47.26.1 17-Apr-2023  martin Pull up following revision(s) (requested by he in ticket #137):

lib/libc/stdio/Makefile.inc: revision 1.48
lib/libc/stdio/vfwprintf.c: revision 1.40
lib/libc/include/extern.h: revision 1.27

PR/57250: Martin Husemann: dtoa mishandles infinite doubles on 32bit big
endian machines. When long double support was added, the old code was kept
for the regular double code. This code was never used because WIDE_DOUBLE
was always defined in the Makefile. Remove that old code, and conditionalize
the WIDE_DOUBLE code based on if long doubles are different than doubles on
the specific platform.
 1.47.18.1 22-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1865):

lib/libc/stdio/Makefile.inc: revision 1.48
tests/lib/libc/stdio/t_printf.c: revision 1.9
lib/libc/stdio/vfwprintf.c: revision 1.40
lib/libc/include/extern.h: revision 1.27
tests/lib/libc/stdio/t_printf.c: revision 1.10

PR/57250: Martin Husemann: dtoa mishandles infinite doubles on 32bit big
endian machines. When long double support was added, the old code was kept
for the regular double code. This code was never used because WIDE_DOUBLE
was always defined in the Makefile. Remove that old code, and conditionalize
the WIDE_DOUBLE code based on if long doubles are different than doubles on
the specific platform.

Add a test for PR/57250 from Havard Eidnes

Fix the test for "inf" output, also include newline in printf format...
 1.49.2.1 02-Aug-2025  perseant Sync with HEAD
 1.6 16-Jan-2014  christos "soon" is "now". Remove all __indr_reference crap.
 1.5 21-Oct-2009  snj branches: 1.5.6; 1.5.12;
Remove 3rd and 4th clauses in christos' license. OK christos.
 1.4 13-Sep-2005  christos compat core reorg.
 1.3 30-Jul-2005  christos - Fix the remaining indr_references so that they define lint symbols.
- Add an internal symbol for strerror_r (thanks klaus for noticing)
- Remove internal __strerror
 1.2 12-Jun-2005  lukem Add missing __RCSID()
 1.1 09-May-2004  kleink branches: 1.1.2;
We now need an internal name for fileno(), since when buildling libc
_REENTRANT we can no longer use the macro version from <stdio.h>.
 1.1.2.2 11-May-2004  tron Pull up revision 1.1 (requested by kleink in ticket #311):
We now need an internal name for fileno(), since when buildling libc
_REENTRANT we can no longer use the macro version from <stdio.h>.
 1.1.2.1 09-May-2004  tron file _fileno.c was added on branch netbsd-2-0 on 2004-05-11 15:48:13 +0000
 1.5.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6 16-Jan-2014  christos "soon" is "now". Remove all __indr_reference crap.
 1.5 21-Oct-2009  snj branches: 1.5.6; 1.5.12;
Remove 3rd and 4th clauses in christos' license. OK christos.
 1.4 13-Sep-2005  christos compat core reorg.
 1.3 30-Jul-2005  christos - Fix the remaining indr_references so that they define lint symbols.
- Add an internal symbol for strerror_r (thanks klaus for noticing)
- Remove internal __strerror
 1.2 12-Jun-2005  lukem Add missing __RCSID()
 1.1 08-Jul-2000  kleink XCU5: Add fseeko() and ftello() functions which provide the functionality of
fseek() and ftell(), respectively, but operate on file offsets of type off_t.
 1.5.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6 16-Jan-2014  christos "soon" is "now". Remove all __indr_reference crap.
 1.5 21-Oct-2009  snj branches: 1.5.6; 1.5.12;
Remove 3rd and 4th clauses in christos' license. OK christos.
 1.4 13-Sep-2005  christos compat core reorg.
 1.3 30-Jul-2005  christos - Fix the remaining indr_references so that they define lint symbols.
- Add an internal symbol for strerror_r (thanks klaus for noticing)
- Remove internal __strerror
 1.2 12-Jun-2005  lukem Add missing __RCSID()
 1.1 08-Jul-2000  kleink XCU5: Add fseeko() and ftello() functions which provide the functionality of
fseek() and ftell(), respectively, but operate on file offsets of type off_t.
 1.5.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.20 19-Apr-2013  joerg Add explicit locale versions for the printf family. Replace asprintf,
snprintf and sprintf with simple wrappers around the corresponding
va_list functions to reduce code duplication.
 1.19 15-Mar-2012  christos branches: 1.19.2;
- ansify, knf.
- no functional changes
 1.18 25-Oct-2009  christos branches: 1.18.6;
revert some of dsl's changes to make things build on i386; he can undo what
he wants when he comes back.
 1.17 25-Oct-2009  dsl Lint is differentially far too picky...
Remove some warnings that only appear on i386 (not on amd64) and that
for some reason best known to others are deemed fatal for i386.
Making this code 'pass lint' does absolutely nothing for its readability (etc).
 1.16 24-Oct-2009  dsl Remove a load of pointless casts - one that even lint doesn't bleat about.
 1.15 26-Jan-2007  cbiere * Consider all negative return values as error, not just -1.
* Corrected cast because (size_t) (INT_MAX + 1) is bogus.
 1.14 09-Feb-2005  kleink A little libc namespace housekeeping exercise:
* Make vfprintf_unlocked() an internal function, c.f. __svfscanf_unlocked().
* Add internal names for arc4random(), endnetpath(), fhstatvfs(),
fstatvfs(), mkstemp(), shquote(), statvfs(), taddr2uaddr(), uaddr2taddr(),
uuid_create_nil(), uuid_is_nil(), and wcwidth().
* Include namespace.h where supposed to.
 1.13 09-Jan-2005  christos add a cast and remove another.
 1.12 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.11 26-May-2002  wiz __STDC__ is always defined on NetBSD.
 1.10 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.9 24-Sep-2001  wiz va_{start,end} audit:
Make sure that each va_start has one and only one matching va_end,
especially in error cases.
If the va_list is used multiple times, do multiple va_starts/va_ends.
If a function gets va_list as argument, don't let it use va_end (since
it's the callers responsibility).

Improved by comments from enami and christos -- thanks!

Heimdal/krb4/KAME changes already fed back, rest to follow.

Inspired by, but not not based on, OpenBSD.
 1.8 13-Apr-2001  kleink Need an internal name for asprintf(3).
 1.7 21-Jan-2000  mycroft branches: 1.7.6;
Initialize f._file for locking primitives.
 1.6 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.5 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.4 15-Nov-1998  christos delint
 1.3 15-Oct-1998  mycroft Make sure we free the buffer in all error cases.
Do the final realloc(3) to the size of the string, not the size of the buffer
allocated for the string (which is a noop).
 1.2 08-Sep-1998  kleink s/NULL/NUL/ where appropriate.
 1.1 28-Aug-1998  perry add asprintf and vasprintf, originally written by Todd Miller for OpenBSD
 1.7.6.5 21-Jun-2002  nathanw Catch up to -current.
 1.7.6.4 02-May-2002  nathanw Call the _unlocked versions of vfprintf() and __svfscanf(); there's no point
in locking and unlocking a FILE object that only exists in the local scope.
This also has the nice side effect of making sprintf() usable for debugging
threaded code.
 1.7.6.3 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.7.6.2 28-Jan-2002  nathanw Catch up to -current.
 1.7.6.1 08-Oct-2001  nathanw Catch up to -current.
 1.18.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.18.6.1 17-Apr-2012  yamt sync with head
 1.19.2.1 23-Jun-2013  tls resync from head
 1.11 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.10 07-Aug-2003  agc branches: 1.10.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.9 18-Jul-2003  nathanw #include "local.h" to get __flockfile_internal() prototype.
 1.8 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.7 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.6 19-Jan-1998  jtc Use FLOCKFILE() and FUNLOCKFILE() macros from reentrant.h so that stdio
can be made thread-safe.
 1.5 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.10.56.1 17-Apr-2012  yamt sync with head
 1.2 19-Apr-2013  joerg Add explicit locale versions for the printf family. Replace asprintf,
snprintf and sprintf with simple wrappers around the corresponding
va_list functions to reduce code duplication.
 1.1 06-Sep-2010  christos branches: 1.1.6; 1.1.12;
add dprintf and vdprintf
 1.1.12.1 23-Jun-2013  tls resync from head
 1.1.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.9 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.8 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.7 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.6 07-Feb-2002  ross Generate <>& symbolically.
 1.5 05-Feb-1998  perry branches: 1.5.12;
add LIBRARY section to man page
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 29-Nov-1993  jtc Use "Er" for argument to -width in the lists in the ERROR sections so that
formatting is consistant.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.12.2 22-Mar-2002  nathanw Catch up to -current.
 1.5.12.1 08-Mar-2002  nathanw Catch up to -current.
 1.18 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.17 11-Jan-2010  joerg branches: 1.17.6;
Use a proper char */size_t pair in __sfileext to keep track of the line
buffer for fgetln and fgetwln. Simplifies code by dropping the INT_MAX
related logic. Drop conditionals around FREELB, free(NULL) is valid.
 1.16 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.15 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.14 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.13 21-Jan-2000  mycroft branches: 1.13.6;
Do the lock *after* checking that the fp is valid.
 1.12 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.11 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.10 18-Oct-1998  dbj Backed out previous fclose(NULL) change.
 1.9 18-Oct-1998  dbj Fix pr lib/6322
fclose(NULL) used to segfault. Now it returns EOF and sets errno to EBADF.
 1.8 03-Feb-1998  perry remove obsolete register declarations
 1.7 19-Jan-1998  jtc Use FLOCKFILE() and FUNLOCKFILE() macros from reentrant.h so that stdio
can be made thread-safe.
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 31-Dec-1993  jtc Add explicit return types to function definitions.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.13.6.2 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.13.6.1 28-Jan-2002  nathanw Catch up to -current.
 1.17.6.1 17-Apr-2012  yamt sync with head
 1.18 09-Nov-2017  christos Add O_REGULAR to enforce opening of only regular files
(like we have O_DIRECTORY for directories).
This is better than open(, O_NONBLOCK), fstat()+S_ISREG() because opening
devices can have side effects.
 1.17 10-Jan-2017  christos branches: 1.17.6;
Need <sys/stat.h>
 1.16 15-Mar-2012  christos branches: 1.16.14;
- ansify, knf.
- no functional changes
 1.15 13-Mar-2008  christos branches: 1.15.6;
Since _file is a short, check that the fd fits in it, otherwise bail with
EMFILE. We treat _file as an unsigned short to double our range, with a
special case for -1 (closed). Make a note of what we should do about stdio
if we ever bump libc. We could change _file in the future compatibly to an
int by putting it in the extension space but for now we don't bother.
 1.14 07-Aug-2003  agc branches: 1.14.22; 1.14.28;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.13 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.12 29-Nov-2000  christos branches: 1.12.2;
This is for completeness only (to make fdopen symmetric with fopen and freopen)
and to match the documentation. Return an error if "f" was specified and the
file descriptor does not refer to a plain file.
 1.11 22-Jan-2000  mycroft Delint.
Remove trailing ; from uses of __weak_alias(). The macro inserts this if
needed.
 1.10 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.9 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.8 13-Oct-1998  kleink Need an internal name for fdopen().
 1.7 03-Feb-1998  perry remove obsolete register declarations
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 02-Feb-1995  jtc branches: 1.5.2;
Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 30-Dec-1994  mycroft Remove useless invocation of the evil getdtablesize(3).
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.2.1 02-Mar-1995  jtc #include "namespace.h"
 1.12.2.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.14.28.1 24-Mar-2008  keiichi sync with head.
 1.14.22.1 23-Mar-2008  matt sync with HEAD
 1.15.6.1 17-Apr-2012  yamt sync with head
 1.16.14.1 20-Mar-2017  pgoyette Sync with HEAD
 1.17.6.1 12-Apr-2018  msaitoh Pull up following revision(s) (requested by christos in ticket #741):
lib/libc/stdio/flags.c: revision 1.19
lib/libc/stdio/fdopen.c: revision 1.18
sys/kern/vfs_vnops.c: revision 1.196
lib/libc/stdio/freopen.c: revision 1.20
lib/libc/stdio/fopen.c: revision 1.17
external/bsd/nvi/dist/common/recover.c: revision 1.10
external/bsd/nvi/dist/common/recover.c: revision 1.11
lib/libc/sys/open.2: revision 1.58
sys/sys/fcntl.h: revision 1.49
make the checkok test stricter to avoid races, and use O_REGULAR.
Instead of opening the file and using popen(3), pass the file descriptor
to sendmail directory. Idea and code from Todd Miller.
Add O_REGULAR to enforce opening of only regular files
(like we have O_DIRECTORY for directories).
This is better than open(, O_NONBLOCK), fstat()+S_ISREG() because opening
devices can have side effects.
 1.12 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.11 07-Aug-2003  agc branches: 1.11.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.10 18-Jul-2003  nathanw #include "local.h" to get __flockfile_internal() prototype.
 1.9 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.8 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.7 20-Nov-1998  kleink Deploy stdio stream locking.
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 31-Dec-1993  jtc Add explicit return types to function definitions.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11.56.1 17-Apr-2012  yamt sync with head
 1.14 08-May-2010  wiz Wording.
 1.13 06-May-2010  jruoho Note that EBADF is optional for fileno() in POSIX.
 1.12 06-May-2010  jruoho Correct the discussion about return values: fileno() may fail and return -1.
Note that in such cases the NetBSD implementation does not set errno to
EBADF, hence diverging from the standard in this small detail.
 1.11 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.10 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.9 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.8 07-Feb-2002  ross Generate <>& symbolically.
 1.7 16-Sep-2001  wiz Boring whitespace fixes.
 1.6 05-Feb-1998  perry branches: 1.6.12;
add LIBRARY section to man page
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 11-Jan-1994  jtc Fix spelling errors.
 1.3 04-Oct-1993  jtc Note that fileno() conforms to 1003.1-90.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.6.12.3 22-Mar-2002  nathanw Catch up to -current.
 1.6.12.2 08-Mar-2002  nathanw Catch up to -current.
 1.6.12.1 08-Oct-2001  nathanw Catch up to -current.
 1.12 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.11 07-Aug-2003  agc branches: 1.11.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.10 18-Jul-2003  nathanw #include "local.h" to get __flockfile_internal() prototype.
 1.9 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.8 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.7 20-Nov-1998  kleink Deploy stdio stream locking.
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 31-Dec-1993  jtc Add explicit return types to function definitions.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11.56.1 17-Apr-2012  yamt sync with head
 1.13 07-Sep-2019  sevan Document history
 1.12 07-Aug-2003  agc branches: 1.12.98;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.11 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.10 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.9 07-Feb-2002  ross Generate <>& symbolically.
 1.8 16-Sep-2001  wiz Mainly sort SEE ALSO, but also sort sections, and some punctuation and
paragraph fixes.
 1.7 29-Aug-1998  lukem branches: 1.7.12;
first pass at fixing up capitalization of function names and
arguments; ensure that each is correct with respect to the
implementation, rather than being correct as per english.
 1.6 28-Apr-1998  fair fix mdoc references and other mistakes
 1.5 05-Feb-1998  perry add LIBRARY section to man page
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 29-Nov-1993  jtc Use "Er" for argument to -width in the lists in the ERROR sections so that
formatting is consistant.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7.12.3 22-Mar-2002  nathanw Catch up to -current.
 1.7.12.2 08-Mar-2002  nathanw Catch up to -current.
 1.7.12.1 08-Oct-2001  nathanw Catch up to -current.
 1.12.98.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.24 22-Jul-2021  christos revert changes to fflush.c (1.18) and fvwrite.c (1.25) until we investigate
collateral damage. Breaks h_intr.c test. Requested by RVP.
 1.23 09-Jul-2021  christos Don't adjust the buffers when write returns 0. This happens with fmemopen
and other synthetic write functions. This fixes the unit-tests for fmemopen,
but adjusting should be the right behavior for all cases?
 1.22 08-Jul-2021  christos Include the 0 return from write. Although the real write system call does
not return 0, the synthetic writes from funopen/fmemopen could. This avoids
infinite loops in >= test19 in fmemopen, but the tests still fail, perhaps
because they assume the previous behavior, where flush does not adjust the
stdio pointers on error.
 1.21 08-Jul-2021  christos Obey EINTR and return immediately adjusting for unwritten. From RVP
 1.20 06-Jul-2021  christos Handle EINTR, from RVP.
 1.19 05-Jul-2021  christos Account for partial writes when interrupted (from FreeBSD).
 1.18 27-Mar-2012  christos - widen the internal read and write calls to match the syscalls
- add funopen2() which provides access to flush() and the wider calls.
- make use of the new flush call in fmemopen()
 1.17 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.16 13-Mar-2012  christos PR/45989: Martin Husemann: lint invocation does include -w only on i386

- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
builds)

approved by core@
 1.15 07-Aug-2003  agc branches: 1.15.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.14 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.13 20-Sep-1999  lukem branches: 1.13.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.12 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.11 03-Feb-1998  perry remove obsolete register declarations
 1.10 22-Jan-1998  jtc Use rwlocks as appropriate.
 1.9 19-Jan-1998  jtc Use FLOCKFILE() and FUNLOCKFILE() macros from reentrant.h so that stdio
can be made thread-safe.
 1.8 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.7 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.6 31-Dec-1993  jtc Add explicit return types to function definitions.
 1.5 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.4 02-Aug-1993  mycroft Nuke remaining patchkit headers.
 1.3 01-Aug-1993  mycroft Add RCS identifiers.
 1.2 21-Mar-1993  cgd after 0.2.2 "stable" patches applied
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.13.10.2 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.13.10.1 08-Aug-2001  nathanw _REENT -> _REENTRANT
 1.15.56.1 17-Apr-2012  yamt sync with head
 1.12 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.11 07-Aug-2003  agc branches: 1.11.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.10 18-Jul-2003  nathanw #include "local.h" to get __flockfile_internal() prototype.
 1.9 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.8 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.7 19-Jan-1998  jtc Use FLOCKFILE() and FUNLOCKFILE() macros from reentrant.h so that stdio
can be made thread-safe.
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 31-Dec-1993  jtc Add explicit return types to function definitions.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11.56.1 17-Apr-2012  yamt sync with head
 1.5 04-Jan-1994  mycroft Clean up deleted files.
 1.4 22-Dec-1993  cgd don't squish newline at end of fgetline()... from bostic
 1.3 29-Nov-1993  jtc Use "Er" for argument to -width in the lists in the ERROR sections so that
formatting is consistant.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.6 04-Jan-1994  mycroft Clean up deleted files.
 1.5 31-Dec-1993  jtc Add explicit return types to function definitions.
 1.4 22-Dec-1993  cgd don't squish newline at end of fgetline()... from bostic
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.16 04-Jul-2018  msaitoh Indent.
 1.15 19-Jun-2014  christos branches: 1.15.22; 1.15.24;
Fix incorrect example (what happens when len == 0?)
 1.14 10-May-2004  drochner branches: 1.14.56; 1.14.68;
put back the CAVEATS section
pointed out by wiz
 1.13 21-Apr-2004  wiz Bump date for previous.
 1.12 21-Apr-2004  christos Add a generalized version of fgetln that can stop at an arbitrary delimiter,
and implement fgetln on top of that.
 1.11 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.10 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.9 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.8 10-Jul-2002  yamt import CAVEATS sections from OpenBSD.
with little tweak by me.
 1.7 07-Feb-2002  ross Generate <>& symbolically.
 1.6 29-Dec-2000  kleink branches: 1.6.2;
Sprinkle some __restrict into stdio.
 1.5 05-Feb-1998  perry add LIBRARY section to man page
 1.4 03-Feb-1998  perry .Bx'ize
 1.3 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.2 11-Jan-1994  jtc Fix spelling errors.
 1.1 04-Jan-1994  cgd branches: 1.1.1;
rename fgetline() and sharpen axe for bostic...
 1.1.1.1 02-Feb-1995  jtc imported from 44lite
 1.6.2.3 01-Aug-2002  nathanw Catch up to -current.
 1.6.2.2 22-Mar-2002  nathanw Catch up to -current.
 1.6.2.1 08-Mar-2002  nathanw Catch up to -current.
 1.14.68.1 10-Aug-2014  tls Rebase.
 1.14.56.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.15.24.1 10-Jun-2019  christos Sync with HEAD
 1.15.22.1 28-Jul-2018  pgoyette Sync with HEAD
 1.17 08-Jun-2017  uwe Don't use "NULL" to talk about null-terminated strings.

The C standard seems to be inconsistent about dash vs. space. Old
text uses dash, Annex K uses space. I'll let wizd(8) to sort that
out.
 1.16 02-Dec-2009  roy Reinstate __getdelim which does no locking.
Callers are now required to FLOCKFILE so they can operate on fp as well.
 1.15 24-Sep-2009  roy __getdelim works on strings up to SIZE_MAX - 2 and returns 0 on EOF.
getdelim works on strings up to SSIZE_MAX and returns -1 on EOF.
__fgetstr is now just a wrapper around __getdelim and ensures that
the buffer doesn't overflow the one provided by FILE.
__slbexpand is now static in fgetwln as it is the only consumer of that func.
 1.14 10-May-2004  drochner After discussion with christos, turn fgetstr() into an internal function.
Its API in inherently non-threadsafe (and it depends on certain properties
of the underlying stdio implementation), so it shouldn't be a first-class
function for general use, polluting the application namespace.
Also remove the FLOCKFILE() code from it - this is under control of the
calling function now.
(XXX I'm not sure whether the FLOCKFILE() should be kept in fgetln(),
this function cannot be used in multiple threads anyway. It doesn't
hurt much, and it might prevent corruption of internal FILE structures.)
 1.13 21-Apr-2004  christos Add a generalized version of fgetln that can stop at an arbitrary delimiter,
and implement fgetln on top of that.
 1.12 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.11 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.10 22-Jan-2000  mycroft branches: 1.10.6;
Delint.
Remove trailing ; from uses of __weak_alias(). The macro inserts this if
needed.
 1.9 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.8 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.7 15-Nov-1998  christos delint
 1.6 16-Oct-1998  kleink Need an internal name for fgetln().
 1.5 03-Feb-1998  perry remove obsolete register declarations
 1.4 19-Jan-1998  jtc Use FLOCKFILE() and FUNLOCKFILE() macros from reentrant.h so that stdio
can be made thread-safe.
 1.3 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.2 02-Feb-1995  jtc branches: 1.2.6;
Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.1 04-Jan-1994  cgd branches: 1.1.1;
rename fgetline() and sharpen axe for bostic...
 1.1.1.1 02-Feb-1995  jtc imported from 44lite
 1.2.6.1 20-Sep-1996  jtc snapshot namespace cleanup: net, etc.
 1.10.6.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.12 22-Jan-2012  christos From tnozaki@: make fpos_t a complex object that keeps track of the parse
state of the stream. Change argument of the seek function to funopen() from
fpos_t to off_t. Make f{g,s}etpos() use the new fpos_t struct, while providing
backwards compatible entry points. Approved by releng@
 1.11 07-Aug-2003  agc branches: 1.11.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.10 08-Jul-2000  kleink In fgetpos() and fsetpos(), use ftello() and fseeko(), respectively, to avoid
truncating the value stored in the fpos_t object operated on to that of a
long integer; adresses PR lib/6637.
 1.9 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.8 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.7 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.6 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.5 31-Dec-1993  jtc Add explicit return types to function definitions.
 1.4 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.3 07-Aug-1993  cgd merge in changes from netbsd-0-9-ALPHA2
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd branches: 1.1.1.1.2;
initial import of 386bsd-0.1 sources
 1.1.1.1.2.1 06-Aug-1993  jtc fgetpos returned wrong value.
fseek/fsetpos/fgetpos manual page too specific. The functions are specified
to return nonzero on failure, not -1.
 1.11.56.1 17-Apr-2012  yamt sync with head
 1.22 13-May-2010  jruoho Remove the note about the standard recommending fgets(3);
should be clear enough from the big warning to "NEVER use gets()".
 1.21 30-Apr-2010  wiz Wording.
 1.20 30-Apr-2010  jruoho They've finally made gets(3) obsolete (in POSIX, at least).
 1.19 09-Dec-2003  grant simplify a sentence
 1.18 30-Oct-2003  grant "The fgets() and functions gets() do not..." ->
"The fgets() and gets() functions do not..."
 1.17 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.16 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.15 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.14 21-Jul-2002  mjl Correct wrong comparison in example.
 1.13 10-Jul-2002  yamt import CAVEATS sections from OpenBSD.
with little tweak by me.
 1.12 07-Feb-2002  ross Generate <>& symbolically.
 1.11 16-Sep-2001  wiz Mainly sort SEE ALSO, but also sort sections, and some punctuation and
paragraph fixes.
 1.10 29-Dec-2000  kleink branches: 1.10.2;
Sprinkle some __restrict into stdio.
 1.9 08-Jun-1998  lukem Implement a new manual page category ``SECURITY CONSIDERATIONS''
(suggested by mycroft)
 1.8 28-Apr-1998  fair fix mdoc references and other mistakes
 1.7 05-Feb-1998  perry add LIBRARY section to man page
 1.6 17-Jan-1997  perry fix pr-2664, second param to fgets is int not size_t, from SAITOH Masanobu
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 03-Apr-1994  cgd fgetln, not fgetline
 1.3 29-Nov-1993  jtc Use "Er" for argument to -width in the lists in the ERROR sections so that
formatting is consistant.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.10.2.4 01-Aug-2002  nathanw Catch up to -current.
 1.10.2.3 22-Mar-2002  nathanw Catch up to -current.
 1.10.2.2 08-Mar-2002  nathanw Catch up to -current.
 1.10.2.1 08-Oct-2001  nathanw Catch up to -current.
 1.28 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.27 25-Oct-2009  christos branches: 1.27.6;
revert some of dsl's changes to make things build on i386; he can undo what
he wants when he comes back.
 1.26 25-Oct-2009  dsl Lint is differentially far too picky...
Remove some warnings that only appear on i386 (not on amd64) and that
for some reason best known to others are deemed fatal for i386.
Making this code 'pass lint' does absolutely nothing for its readability (etc).
 1.25 24-Oct-2009  dsl Remove a load of pointless casts - one that even lint doesn't bleat about.
 1.24 24-Oct-2009  dsl Check for EOF before erroring fgets() with length <= 0.
If length is invalid, set errno = EINVAL and __SERR as well returning NULL.
Should let me close PR/41992.
 1.23 14-Oct-2009  dsl Change a while () {} into a do {} while() so that fgets(buf, 1, file)
detects EOF on an empty file.
Fixes most of PR/41992
 1.22 05-Feb-2009  lukem sign-compare fix
 1.21 03-Jun-2007  christos Make these work with _FORTIFY_SOURCE, by overriding the fortified definitions
 1.20 14-Dec-2003  lukem remove superfluous assignment
 1.19 10-Oct-2003  simonb Remove another unneeded cast to size_t.

Pointed out by Anil Madhavapeddy in private email.
 1.18 09-Oct-2003  simonb No need to cast "len" to a size_t now that "len" is a size_t.
 1.17 08-Oct-2003  itojun avoid signed->unsigned assignment. openbsd PR 1709
 1.16 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.15 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.14 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.13 14-Nov-1999  explorer branches: 1.13.6;
missing ;
 1.12 20-Sep-1999  lukem branches: 1.12.4;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.11 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.10 15-Nov-1998  christos change len from size_t to int so that len = fp->_r does not get promoted
to unsigned. cast len appropriately to size_t later.
 1.9 07-Sep-1998  kleink Sloppy stdio stream lock tracking.
 1.8 03-Feb-1998  perry remove obsolete register declarations
 1.7 19-Jan-1998  jtc Use FLOCKFILE() and FUNLOCKFILE() macros from reentrant.h so that stdio
can be made thread-safe.
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 25-Mar-1995  jtc change second arg of fgets() from size_t to int
 1.4 02-Feb-1995  jtc branches: 1.4.2;
Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.2.1 02-May-1995  jtc #include "namespace.h"
 1.12.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.13.6.2 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.13.6.1 28-Jan-2002  nathanw Catch up to -current.
 1.27.6.1 17-Apr-2012  yamt sync with head
 1.4 10-May-2004  drochner remove the fgetstr manpage
 1.3 05-May-2004  jdolecek fix reference Nx 2.1 to Nx 3.0
 1.2 21-Apr-2004  wiz Drop trailing whitespace; null -> nul; & -> \*[Am]
 1.1 21-Apr-2004  christos Add a generalized version of fgetln that can stop at an arbitrary delimiter,
and implement fgetln on top of that.
 1.12 08-Jun-2017  uwe Don't use "NULL" to talk about null-terminated strings.

The C standard seems to be inconsistent about dash vs. space. Old
text uses dash, Annex K uses space. I'll let wizd(8) to sort that
out.
 1.11 11-Jan-2010  joerg Use a proper char */size_t pair in __sfileext to keep track of the line
buffer for fgetln and fgetwln. Simplifies code by dropping the INT_MAX
related logic. Drop conditionals around FREELB, free(NULL) is valid.
 1.10 02-Dec-2009  roy Reinstate __getdelim which does no locking.
Callers are now required to FLOCKFILE so they can operate on fp as well.
 1.9 01-Dec-2009  roy Remove __getdelim and just use getdelim.
fgetstr now works with strings up to SSIZE_MAX as a result, but may
reallocate buffers needlessly just like it used to when the buffer size
exceeds INT_MAX.
fgetstr converts errno EOVERFLOW to EINVAL on getdelim error.
 1.8 15-Oct-2009  roy Handle errors from getdelim better.
 1.7 14-Oct-2009  roy Store the allocated buffer against FILE, plugging a memory leak.
Fixes PR bin/42183.
 1.6 24-Sep-2009  roy __getdelim works on strings up to SIZE_MAX - 2 and returns 0 on EOF.
getdelim works on strings up to SSIZE_MAX and returns -1 on EOF.
__fgetstr is now just a wrapper around __getdelim and ensures that
the buffer doesn't overflow the one provided by FILE.
__slbexpand is now static in fgetwln as it is the only consumer of that func.
 1.5 31-Jan-2009  lukem sign-compare fix
 1.4 24-Nov-2006  christos fix spelling of accommodate; from Zapher.
 1.3 14-May-2005  christos Add the missing wide char support functions from freebsd.
XXX: long double support is missing until we get gdtoa, and add the
necessary wide functions.
 1.2 10-May-2004  drochner After discussion with christos, turn fgetstr() into an internal function.
Its API in inherently non-threadsafe (and it depends on certain properties
of the underlying stdio implementation), so it shouldn't be a first-class
function for general use, polluting the application namespace.
Also remove the FLOCKFILE() code from it - this is under control of the
calling function now.
(XXX I'm not sure whether the FLOCKFILE() should be kept in fgetln(),
this function cannot be used in multiple threads anyway. It doesn't
hurt much, and it might prevent corruption of internal FILE structures.)
 1.1 21-Apr-2004  christos Add a generalized version of fgetln that can stop at an arbitrary delimiter,
and implement fgetln on top of that.
 1.13 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.12 13-Mar-2012  christos PR/45989: Martin Husemann: lint invocation does include -w only on i386

- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
builds)

approved by core@
 1.11 25-Oct-2009  christos branches: 1.11.6;
revert some of dsl's changes to make things build on i386; he can undo what
he wants when he comes back.
 1.10 25-Oct-2009  dsl Lint is differentially far too picky...
Remove some warnings that only appear on i386 (not on amd64) and that
for some reason best known to others are deemed fatal for i386.
Making this code 'pass lint' does absolutely nothing for its readability (etc).
 1.9 24-Oct-2009  dsl Remove a load of pointless casts - one that even lint doesn't bleat about.
 1.8 01-Apr-2007  tnozaki oops, fix miss-increment fp->_p.
 1.7 01-Apr-2007  tnozaki mbrtowc(3) never return correct multibyte length of L'\0'.
 1.6 01-Apr-2007  tnozaki don't use __sgetc() to avoid overwriting fwide(3) orientation
(__srget() call by __sgetc() uses _SET_ORIENTATION macro).
 1.5 03-Jul-2006  tnozaki SUSv3 said, if an encoding error occurs, the error indicator
for the stream shall be set.
 1.4 12-Jun-2005  lukem Add missing __RCSID()
 1.3 07-Mar-2003  tshiozak add fgetws() and fputws() (lib/20576).

Note: fgetws.c, fgetws.3, fputws.c and fputws.3 are obtained from FreeBSD,
and fitted by sigsegv@infoseek.jp and me.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 07-Dec-2001  yamt branches: 1.1.2;
- make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.1.2.3 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.1.2.2 28-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 07-Dec-2001  nathanw file fgetwc.c was added on branch nathanw_sa on 2002-01-28 20:50:53 +0000
 1.11.6.1 17-Apr-2012  yamt sync with head
 1.2 16-Dec-2010  wiz Observe the following spelling:
- wide character (noun)
- wide-character (adjective)

Inspired by jmc@OpenBSD.
 1.1 14-May-2005  christos Add the missing wide char support functions from freebsd.
XXX: long double support is missing until we get gdtoa, and add the
necessary wide functions.
 1.8 27-Aug-2016  christos Improvements to fgetwln(3) from Andrey Chernov:

1) Set the stdio error indicator on __slbexpand() failure.

2) fgetwc(3) may succeed even when ferror(3) is already set
(for example, consider a program using SIG_IGN on SIGTTIN,
reading from the tty while in the background, getting EIO,
then coming to the foreground and reading again).
So do not force fgetwln(3) to fail in such a case either.
(Yes, the program should probably clearerr(3) before
reading again, but let's be nicer in case it forgets.)
 1.7 22-Aug-2016  christos missing _
 1.6 22-Aug-2016  christos From OpenBSD:
bugfix: when fgetwc(3) fails, fgetwln(3) must fail as well;
 1.5 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.4 11-Jan-2010  joerg branches: 1.4.6;
Use a proper char */size_t pair in __sfileext to keep track of the line
buffer for fgetln and fgetwln. Simplifies code by dropping the INT_MAX
related logic. Drop conditionals around FREELB, free(NULL) is valid.
 1.3 24-Sep-2009  roy __getdelim works on strings up to SIZE_MAX - 2 and returns 0 on EOF.
getdelim works on strings up to SSIZE_MAX and returns -1 on EOF.
__fgetstr is now just a wrapper around __getdelim and ensures that
the buffer doesn't overflow the one provided by FILE.
__slbexpand is now static in fgetwln as it is the only consumer of that func.
 1.2 31-Jan-2009  lukem sign-compare fix
 1.1 14-May-2005  christos Add the missing wide char support functions from freebsd.
XXX: long double support is missing until we get gdtoa, and add the
necessary wide functions.
 1.4.6.1 17-Apr-2012  yamt sync with head
 1.3 16-Dec-2010  wiz Observe the following spelling:
- wide character (noun)
- wide-character (adjective)

Inspired by jmc@OpenBSD.
 1.2 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.1 07-Mar-2003  tshiozak add fgetws() and fputws() (lib/20576).

Note: fgetws.c, fgetws.3, fputws.c and fputws.3 are obtained from FreeBSD,
and fitted by sigsegv@infoseek.jp and me.
 1.3 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.2 03-Jul-2006  tnozaki branches: 1.2.44;
SUSv3 said, if an encoding error occurs, the error indicator
for the stream shall be set.
 1.1 07-Mar-2003  tshiozak add fgetws() and fputws() (lib/20576).

Note: fgetws.c, fgetws.3, fputws.c and fputws.3 are obtained from FreeBSD,
and fitted by sigsegv@infoseek.jp and me.
 1.2.44.1 17-Apr-2012  yamt sync with head
 1.7 19-Apr-2022  rillig lib: remove CONSTCOND comment

Since 2021-01-31, lint doesn't need it anymore for the common pattern of
'do ... while (0)'.
 1.6 11-Jan-2010  joerg Use a proper char */size_t pair in __sfileext to keep track of the line
buffer for fgetln and fgetwln. Simplifies code by dropping the INT_MAX
related logic. Drop conditionals around FREELB, free(NULL) is valid.
 1.5 18-Jul-2003  nathanw Add fields to struct __sfileext to track how many times the lock has been
taken by internal stdio functions, and what the cancellation state was when
the first such lock was taken.
 1.4 01-Feb-2003  nathanw Revert the conversion to libpthread's recursive mutexes. Too much
trouble is caused by the memory allocation in the mutex initialization,
and uncontested mutexes and condition variables have become faster in the
meantime.
 1.3 21-Jan-2003  nathanw Use recursive mutexes from libpthread rather than implementing
our own with normal mutexes and condition variables.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 07-Dec-2001  yamt branches: 1.1.2;
add files forgotten in my previous commit.
 1.1.2.4 07-Feb-2002  nathanw Make lock initialization part of _FILEEXT_SETUP() when _REENTRANT is defined;
this lets it happen automatically in the dozen places it is used in stdio
without tweaking each of them.
 1.1.2.3 06-Feb-2002  nathanw Add stream locking variables to struct __sfileext, and add appropriate
access macros.
 1.1.2.2 28-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 07-Dec-2001  nathanw file fileext.h was added on branch nathanw_sa on 2002-01-28 20:50:54 +0000
 1.13 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.12 09-May-2004  kleink branches: 1.12.50;
We now need an internal name for fileno(), since when buildling libc
_REENTRANT we can no longer use the macro version from <stdio.h>.
 1.11 07-Aug-2003  agc branches: 1.11.2;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.10 18-Jul-2003  nathanw #include "local.h" to get __flockfile_internal() prototype.
 1.9 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.8 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.7 20-Nov-1998  kleink Deploy stdio stream locking.
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 31-Dec-1993  jtc Add explicit return types to function definitions.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11.2.1 11-May-2004  tron Pull up revision 1.12 (requested by kleink in ticket #311):
We now need an internal name for fileno(), since when buildling libc
_REENTRANT we can no longer use the macro version from <stdio.h>.
 1.12.50.1 17-Apr-2012  yamt sync with head
 1.28 27-Mar-2012  christos - widen the internal read and write calls to match the syscalls
- add funopen2() which provides access to flush() and the wider calls.
- make use of the new flush call in fmemopen()
 1.27 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.26 22-Jan-2012  christos From tnozaki@: make fpos_t a complex object that keeps track of the parse
state of the stream. Change argument of the seek function to funopen() from
fpos_t to off_t. Make f{g,s}etpos() use the new fpos_t struct, while providing
backwards compatible entry points. Approved by releng@
 1.25 06-Sep-2010  christos branches: 1.25.6;
add dprintf and vdprintf
 1.24 11-Jan-2010  joerg Use a proper char */size_t pair in __sfileext to keep track of the line
buffer for fgetln and fgetwln. Simplifies code by dropping the INT_MAX
related logic. Drop conditionals around FREELB, free(NULL) is valid.
 1.23 07-Oct-2006  thorpej Grr, adjust last so that it works with our busted lint(1).
 1.22 07-Oct-2006  thorpej Use explicit initializers in STDEXT
 1.21 04-Oct-2006  tnozaki fix gcc -Werror -Wmissing-braces problem
mbstate_t(this is opaque object)'s initializer should be ``{ 0 }'',
so changed 1st field of union from character array to integer.
 1.20 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.19 18-Jul-2003  nathanw Add fields to struct __sfileext to track how many times the lock has been
taken by internal stdio functions, and what the cancellation state was when
the first such lock was taken.
 1.18 01-Feb-2003  nathanw Revert the conversion to libpthread's recursive mutexes. Too much
trouble is caused by the memory allocation in the mutex initialization,
and uncontested mutexes and condition variables have become faster in the
meantime.
 1.17 21-Jan-2003  nathanw Use recursive mutexes from libpthread rather than implementing
our own with normal mutexes and condition variables.
 1.16 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.15 12-Mar-2002  christos fully initialize the structure to avoid gcc complaints.
 1.14 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.13 21-Jan-2000  mycroft branches: 1.13.6;
Just call fflush() from _cleanup(), since it does the right locking.
 1.12 15-Nov-1998  christos delint
 1.11 18-Oct-1998  kleink Replace use of getdtablesize() with (the non-deprecated) sysconf(), hence no
need for an internal name for the former any more; suggested by Matthew Green.
 1.10 16-Oct-1998  kleink Need "namespace.h" for getdtablesize().
 1.9 03-Feb-1998  perry remove obsolete register declarations
 1.8 22-Jan-1998  jtc Use rwlocks as appropriate.
 1.7 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.6 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.5 08-Dec-1994  cgd fix pr 594, pointed out by Chuck Silvers. fix taken from 4.4-Lite, rather
than his patch. (functionally identical, though...)
 1.4 31-Dec-1993  jtc Add explicit return types to function definitions.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.13.6.7 22-Mar-2002  nathanw Catch up to -current.
 1.13.6.6 13-Mar-2002  nathanw Add a non-_REENTRANT case for __sFext.
 1.13.6.5 12-Mar-2002  nathanw "More braces make things better".
Fix the initialization of the struct wchar_io_data in struct __sfileext
in the declaration of __sFext[3] to not emit warnings.

Problem noted by Gregory McGarry and Nick Hudson, and ignored by me for
far too long because I accidentally had warnings turned off in my libc tree.
 1.13.6.4 07-Feb-2002  nathanw Remove lock initialization; this is done differently now.
 1.13.6.3 06-Feb-2002  nathanw Initialize the struct __sfileext's (both the 3 statically created
ones, and the ones initialized in __sfp()).
 1.13.6.2 28-Jan-2002  nathanw Catch up to -current.
 1.13.6.1 08-Aug-2001  nathanw _REENT -> _REENTRANT
 1.25.6.1 17-Apr-2012  yamt sync with head
 1.19 09-Nov-2017  christos Add O_REGULAR to enforce opening of only regular files
(like we have O_DIRECTORY for directories).
This is better than open(, O_NONBLOCK), fstat()+S_ISREG() because opening
devices can have side effects.
 1.18 04-Nov-2017  christos Implement nofollow (l) for fopen(3).
 1.17 15-Nov-2012  christos branches: 1.17.22;
Add 'x' to the mode bits to specify O_EXCL, like glibc.
 1.16 15-Mar-2012  christos branches: 1.16.2;
- ansify, knf.
- no functional changes
 1.15 26-Jun-2011  christos branches: 1.15.2; 1.15.4;
* Arrange for interfaces that create new file descriptors to be able to
set close-on-exec on creation (http://udrepper.livejournal.com/20407.html).

- Add F_DUPFD_CLOEXEC to fcntl(2).
- Add MSG_CMSG_CLOEXEC to recvmsg(2) for unix file descriptor passing.
- Add dup3(2) syscall with a flags argument for O_CLOEXEC, O_NONBLOCK.
- Add pipe2(2) syscall with a flags argument for O_CLOEXEC, O_NONBLOCK.
- Add flags SOCK_CLOEXEC, SOCK_NONBLOCK to the socket type parameter
for socket(2) and socketpair(2).
- Add new paccept(2) syscall that takes an additional sigset_t to alter
the sigmask temporarily and a flags argument to set SOCK_CLOEXEC,
SOCK_NONBLOCK.
- Add new mode character 'e' to fopen(3) and popen(3) to open pipes
and file descriptors for close on exec.
- Add new kqueue1(2) syscall with a new flags argument to open the
kqueue file descriptor with O_CLOEXEC, O_NONBLOCK.

* Fix the system calls that take socklen_t arguments to actually do so.

* Don't include userland header files (signal.h) from system header files
(rump_syscallargs.h).

* Bump libc version for the new syscalls.
 1.14 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.13 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.12 15-Jan-2000  christos branches: 1.12.6;
add and "f" flag to fopen that makes sure we are opening a plain file,
so that there is no chance to block.
 1.11 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.10 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.9 19-Mar-1999  christos include <fcntl.h> instead of <sys/file.h>
 1.8 03-Feb-1998  perry remove obsolete register declarations
 1.7 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.6 20-Dec-1996  cgd pull in local.h for prototypes. first arg to __sflags() is const char *
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 31-Dec-1993  jtc Add explicit return types to function definitions.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.12.6.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.15.4.1 28-Nov-2012  riz Pull up following revision(s) (requested by christos in ticket #723):
lib/libc/stdio/flags.c: revision 1.17
lib/libc/stdio/fopen.3: revision 1.29
Add 'x' to the mode bits to specify O_EXCL, like glibc.
 1.15.2.2 16-Jan-2013  yamt sync with (a bit old) head
 1.15.2.1 17-Apr-2012  yamt sync with head
 1.16.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.17.22.1 12-Apr-2018  msaitoh Pull up following revision(s) (requested by christos in ticket #741):
lib/libc/stdio/flags.c: revision 1.19
lib/libc/stdio/fdopen.c: revision 1.18
sys/kern/vfs_vnops.c: revision 1.196
lib/libc/stdio/freopen.c: revision 1.20
lib/libc/stdio/fopen.c: revision 1.17
external/bsd/nvi/dist/common/recover.c: revision 1.10
external/bsd/nvi/dist/common/recover.c: revision 1.11
lib/libc/sys/open.2: revision 1.58
sys/sys/fcntl.h: revision 1.49
make the checkok test stricter to avoid races, and use O_REGULAR.
Instead of opening the file and using popen(3), pass the file descriptor
to sendmail directory. Idea and code from Todd Miller.
Add O_REGULAR to enforce opening of only regular files
(like we have O_DIRECTORY for directories).
This is better than open(, O_NONBLOCK), fstat()+S_ISREG() because opening
devices can have side effects.
 1.5 14-May-2005  christos Add the missing wide char support functions from freebsd.
XXX: long double support is missing until we get gdtoa, and add the
necessary wide functions.
 1.4 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.3 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.6 15-Oct-2011  wiz Sort SECTIONS.
 1.5 15-Oct-2011  rmind Mention POSIX conformance of some functions, when they appeared, sprinkle .Xr.
 1.4 30-Apr-2008  martin branches: 1.4.8;
Convert TNF licenses to new 2 clause variant
 1.3 16-Apr-2003  wiz branches: 1.3.30;
Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.2 28-Jan-2003  wiz a, b, and c.
 1.1 28-Jan-2003  kleink Add a manual page for flockfile(3) etc.; while here, also add *_unlocked()
to stdio(3) overview documentation. Fixes PR lib/20096 from Jason Thorpe.
 1.3.30.1 18-May-2008  yamt sync with head.
 1.4.8.2 30-Apr-2008  martin Convert TNF licenses to new 2 clause variant
 1.4.8.1 30-Apr-2008  martin file flockfile.3 was added on branch christos-time_t on 2008-04-30 13:10:52 +0000
 1.11 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.10 08-Dec-2010  joerg branches: 1.10.6;
Don't redeclare __isthreaded.
 1.9 28-Apr-2008  martin branches: 1.9.8;
Remove clause 3 and 4 from TNF licenses
 1.8 22-Jul-2003  nathanw branches: 1.8.30;
Disable cancellation on the first lock, too, not just on internal
recursive locks (Duh).

Disable cancellation around the cond_wait() call, since that's also a
cancellation point. Arguably, that would be better handled with
pthread_cleanup_*(), but stubbing those for libc is difficult, and the
current non-exception-based implementation of cleanup handlers is
probably no faster than disabling and reenabling cancellation.
Finally, it only happens in the slow path where the thread is going to
sleep anyway...
 1.7 21-Jul-2003  nathanw Set the _LOCKINTERNAL() count on initial locking as well as subsequent
recursive locks.
 1.6 19-Jul-2003  nathanw Use threadlib stub rather than pthread_setcancelstate() directly.
 1.5 18-Jul-2003  nathanw Move guts of flockfile()/funlockfile() to __flockfile_internal(), which
takes an additional argument indicating whether this is an internal caller
taking the lock or an external (application) caller. When making an internal
lock, save the current thread cancellation state and disable cancellation
until the matching unlock. This should prevent canccelled threads from exiting
inside of stdio while holding a file lock and potentially leaving other
parts of the FILE structure in an inconsistent state.
 1.4 01-Feb-2003  nathanw Revert the conversion to libpthread's recursive mutexes. Too much
trouble is caused by the memory allocation in the mutex initialization,
and uncontested mutexes and condition variables have become faster in the
meantime.
 1.3 21-Jan-2003  nathanw Use recursive mutexes from libpthread rather than implementing
our own with normal mutexes and condition variables.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 06-Feb-2002  nathanw branches: 1.1.2;
file flockfile.c was initially added on branch nathanw_sa.
 1.1.2.1 06-Feb-2002  nathanw Implement flockfile(), ftrylockfile(), and funlockfile().
(Ewwww. Recursive mutexes.)
 1.8.30.1 18-May-2008  yamt sync with head.
 1.9.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.9.8.1 28-Apr-2008  martin file flockfile.c was added on branch christos-time_t on 2008-04-28 20:23:01 +0000
 1.10.6.1 17-Apr-2012  yamt sync with head
 1.9 06-Sep-2015  pgoyette English grammar nit: there's only one function described in this man page
 1.8 06-Sep-2015  dholland Improve the short description.
 1.7 08-Oct-2012  njoly Kill some extra spaces in function arguments.
 1.6 15-Oct-2011  rmind branches: 1.6.2; 1.6.8;
- Mention that fmemopen(3) conforms POSIX-2008.
- Drop advertising clause in TNF license.
 1.5 07-Oct-2010  enami The was is not an argument but simply a part of sentense.
 1.4 28-Sep-2010  enami Add missing period at the end of sentense.
 1.3 25-Sep-2010  wiz Remove trailing whitespace, merge error sections for same error, nits.
 1.2 25-Sep-2010  uwe Make groff happy.
 1.1 24-Sep-2010  christos add man page as promised.
 1.6.8.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.6.2.1 30-Oct-2012  yamt sync with head
 1.8 29-Mar-2012  christos The flush function makes the tests fail. So undo it for now until we decide
if the tests are wrong or the flushing is wrong.
 1.7 27-Mar-2012  christos - widen the internal read and write calls to match the syscalls
- add funopen2() which provides access to flush() and the wider calls.
- make use of the new flush call in fmemopen()
 1.6 22-Jan-2012  christos From tnozaki@: make fpos_t a complex object that keeps track of the parse
state of the stream. Change argument of the seek function to funopen() from
fpos_t to off_t. Make f{g,s}etpos() use the new fpos_t struct, while providing
backwards compatible entry points. Approved by releng@
 1.5 27-Sep-2010  tnozaki branches: 1.5.6;
validate flags/oflags from __sflag() befere call __sfp().
reviewed by enami-san, thanks.
 1.4 27-Sep-2010  tnozaki fix off-by-one, pointed out by enami-san, thanks!
 1.3 25-Sep-2010  tron Change last commit to Use "ptrdiff_t" instead of "intptr_t" because the
former is more appropriate in this case.
 1.2 25-Sep-2010  tron Add explicit cast to fix lint error on 32bit platforms.
 1.1 24-Sep-2010  tnozaki add fmemopen(3) derrived from POSIX:2008.
libc minor bump.
 1.5.6.1 17-Apr-2012  yamt sync with head
 1.36 02-Sep-2019  sevan Start documenting history
https://www.bell-labs.com/usr/dmr/www/man31.pdf
 1.35 04-Nov-2017  kre branches: 1.35.4; 1.35.6;

Be more consistent with how we refer to fopen() - pointed out by wiz@
 1.34 04-Nov-2017  kre Some (mostly minor) wording improvements (IMO)
 1.33 04-Nov-2017  wiz Fix xref. Remove Tn.
 1.32 04-Nov-2017  christos Implement nofollow (l) for fopen(3).
 1.31 15-Jul-2015  christos Allow changing the default buffering policy for a stdio stream during
construction by setting environment variables.
 1.30 11-Feb-2015  riastradh Use Pq to avoid space before O_EXCL.
 1.29 15-Nov-2012  christos branches: 1.29.8;
Add 'x' to the mode bits to specify O_EXCL, like glibc.
 1.28 02-Jul-2012  wiz branches: 1.28.2;
Sort description of flags.
 1.27 18-Jul-2011  jruoho branches: 1.27.2; 1.27.4;
Use a list for clarity, update standards, etc.
 1.26 27-Jun-2011  wiz Various minor improvements.
 1.25 26-Jun-2011  christos * Arrange for interfaces that create new file descriptors to be able to
set close-on-exec on creation (http://udrepper.livejournal.com/20407.html).

- Add F_DUPFD_CLOEXEC to fcntl(2).
- Add MSG_CMSG_CLOEXEC to recvmsg(2) for unix file descriptor passing.
- Add dup3(2) syscall with a flags argument for O_CLOEXEC, O_NONBLOCK.
- Add pipe2(2) syscall with a flags argument for O_CLOEXEC, O_NONBLOCK.
- Add flags SOCK_CLOEXEC, SOCK_NONBLOCK to the socket type parameter
for socket(2) and socketpair(2).
- Add new paccept(2) syscall that takes an additional sigset_t to alter
the sigmask temporarily and a flags argument to set SOCK_CLOEXEC,
SOCK_NONBLOCK.
- Add new mode character 'e' to fopen(3) and popen(3) to open pipes
and file descriptors for close on exec.
- Add new kqueue1(2) syscall with a new flags argument to open the
kqueue file descriptor with O_CLOEXEC, O_NONBLOCK.

* Fix the system calls that take socklen_t arguments to actually do so.

* Don't include userland header files (signal.h) from system header files
(rump_syscallargs.h).

* Bump libc version for the new syscalls.
 1.24 05-Apr-2010  joerg \\ -> \e
 1.23 25-May-2005  kleink Add restrict qualifiers to fopen()/freopen() arguments.
 1.22 07-Aug-2003  agc branches: 1.22.6;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.21 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.20 28-Mar-2003  pooka avoid using multiple different ways of saying the same thing
 1.19 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.18 01-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.17 10-Jul-2002  yamt import CAVEATS sections from OpenBSD.
with little tweak by me.
 1.16 12-Jun-2002  wiz Add Xr to fileno(3).
 1.15 15-May-2002  kleink Consistent wording: plain files -> regular files.
 1.14 07-Feb-2002  ross Generate <>& symbolically.
 1.13 29-Dec-2000  kleink branches: 1.13.2;
Sprinkle some __restrict into stdio.
 1.12 18-Oct-2000  kim Make "f" standout better.
 1.11 17-May-2000  fair Comment out a paragraph describing behavior which NetBSD's fopen(3) does
not exhibit, per PR 6072.
 1.10 15-Jan-2000  christos add and "f" flag to fopen that makes sure we are opening a plain file,
so that there is no chance to block.
 1.9 12-Jan-1999  kleink branches: 1.9.2;
* Add const keywords to function arguments as appropriate.
* Clarify the description of the initial position of the stream (some confusion
due to the way fdopen() was merged into a former ANSI-only document).
 1.8 28-Apr-1998  fair fix mdoc references and other mistakes
 1.7 05-Feb-1998  perry add LIBRARY section to man page
 1.6 14-Oct-1997  mycroft Fix a bizarre formatting error.
 1.5 14-Jul-1997  kleink Add missing `STANDARDS' compliance statements. As we #define _POSIX_VERSION
to 199009L, bump existing statements to 1003.1-1990.
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 29-Nov-1993  jtc Use "Er" for argument to -width in the lists in the ERROR sections so that
formatting is consistant.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9.2.1 22-May-2000  he Pull up revision 1.11 (requested by fair):
Correct inconsistency between implementation and documentation.
Fixes PR#6072.
 1.13.2.5 18-Oct-2002  nathanw Catch up to -current.
 1.13.2.4 01-Aug-2002  nathanw Catch up to -current.
 1.13.2.3 21-Jun-2002  nathanw Catch up to -current.
 1.13.2.2 22-Mar-2002  nathanw Catch up to -current.
 1.13.2.1 08-Mar-2002  nathanw Catch up to -current.
 1.22.6.1 28-May-2005  tron Pull up revision 1.23 (requested by kleink in ticket #344):
Add restrict qualifiers to fopen()/freopen() arguments.
 1.27.4.2 14-Apr-2015  msaitoh Pull up following revision(s) (requested by riastradh in ticket #1273):
lib/libc/stdio/fopen.3: revision 1.30
Use Pq to avoid space before O_EXCL.
 1.27.4.1 28-Nov-2012  riz Pull up following revision(s) (requested by christos in ticket #723):
lib/libc/stdio/flags.c: revision 1.17
lib/libc/stdio/fopen.3: revision 1.29
Add 'x' to the mode bits to specify O_EXCL, like glibc.
 1.27.2.2 16-Jan-2013  yamt sync with (a bit old) head
 1.27.2.1 30-Oct-2012  yamt sync with head
 1.28.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.29.8.2 04-Nov-2015  riz Pull up following revision(s) (requested by christos in ticket #920):
lib/libc/stdio/fopen.3: revision 1.31
lib/libc/stdio/setbuf.3: revision 1.14
lib/libc/stdio/makebuf.c: revision 1.18
Allow changing the default buffering policy for a stdio stream during
construction by setting environment variables.
 1.29.8.1 18-Mar-2015  snj Pull up following revision(s) (requested by riastradh in ticket #602):
lib/libc/stdio/fopen.3: revision 1.30
Use Pq to avoid space before O_EXCL.
 1.35.6.1 05-Sep-2019  martin Pull up following revision(s) (requested by sevan in ticket #174):
lib/libc/sys/chmod.2: revision 1.48
lib/libc/sys/stat.2: revision 1.59
lib/libc/sys/unlink.2: revision 1.30
lib/libc/sys/lseek.2: revision 1.25
lib/libc/sys/getuid.2: revision 1.18
lib/libc/sys/chown.2: revision 1.37
lib/libm/man/exp.3: revision 1.32
lib/libm/man/log.3: revision 1.7
lib/libc/sys/open.2: revision 1.60
lib/libc/stdio/fopen.3: revision 1.36
lib/libc/stdio/putc.3: revision 1.14
lib/libc/sys/mount.2: revision 1.51
share/man/man9/copy.9: revision 1.22
share/man/man9/uiomove.9: revision 1.20
lib/libc/sys/setuid.2: revision 1.23
lib/libc/sys/close.2: revision 1.18
sbin/init/init.8: revision 1.61
lib/libc/sys/write.2: revision 1.36
lib/libc/sys/read.2: revision 1.39
sbin/init/init.8: revision 1.62
lib/libc/sys/wait.2: revision 1.40
usr.bin/tty/tty.1: revision 1.10
lib/libc/sys/link.2: revision 1.33
usr.bin/du/du.1: revision 1.24
lib/libc/stdlib/exit.3: revision 1.17
usr.bin/su/su.1: revision 1.53
usr.bin/mail/mail.1: revision 1.66
lib/libc/sys/fork.2: revision 1.25
usr.bin/su/su.1: revision 1.54
usr.bin/mail/mail.1: revision 1.67
lib/libm/man/sin.3: revision 1.15
share/man/man9/intro.9: revision 1.26
share/man/man5/utmp.5: revision 1.17
lib/libc/compat-43/creat.3: revision 1.17
lib/libc/time/ctime.3: revision 1.61
lib/libcompat/4.1/stty.3: revision 1.10
usr.bin/dc/dc.1: revision 1.3
lib/libm/man/cos.3: revision 1.17
lib/libc/sys/chdir.2: revision 1.23
lib/libc/gen/exec.3: revision 1.30
lib/libc/gen/exec.3: revision 1.31
games/bcd/bcd.6: revision 1.18
games/bcd/bcd.6: revision 1.19
usr.bin/write/write.1: revision 1.7
usr.bin/wc/wc.1: revision 1.18
usr.bin/pr/pr.1: revision 1.24
usr.bin/who/who.1: revision 1.25
lib/libc/sys/mkdir.2: revision 1.30
lib/libc/stdio/getc.3: revision 1.13
usr.bin/sort/sort.1: revision 1.40
usr.bin/mesg/mesg.1: revision 1.11
share/man/man5/passwd.5: revision 1.34
sort was there since v1
https://www.bell-labs.com/usr/dmr/www/man61.pdf

dc was in v1
https://www.bell-labs.com/usr/dmr/www/man12.pdf

du was in v1
https://www.bell-labs.com/usr/dmr/www/man12.pdf

mail was in v1
https://www.bell-labs.com/usr/dmr/www/man12.pdf

mesg was in v1
https://www.bell-labs.com/usr/dmr/www/man12.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man13.pdf

su was in v1
https://www.bell-labs.com/usr/dmr/www/man13.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man13.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man14.pdf
Update URL

write was in v1
https://www.bell-labs.com/usr/dmr/www/man14.pdf
grammar

passwd(5) was in v1
https://www.bell-labs.com/usr/dmr/www/man51.pdf

utmp(5) was present in v1
https://www.bell-labs.com/usr/dmr/www/man51.pdf

Earliest version of wtmp I could find was in v3
https://minnie.tuhs.org/cgi-bin/utree.pl?file=V3/man/man5/wtmp.5

Document history of chdir(2)
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history of chmod(2)
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history of chown(2)
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man21.pdf

create was present in v1
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history of exec()
Move statement on execlpe() & execvpe() to HISTORY section.

Document history
https://www.bell-labs.com/usr/dmr/www/man21.pdf

fork was present in v1
https://www.bell-labs.com/usr/dmr/www/man21.pdf
stat() was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

document history of fstat()
https://www.bell-labs.com/usr/dmr/www/man21.pdf

getuid was present in v1
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man21.pdf

stty & gtty were around since v1
https://www.bell-labs.com/usr/dmr/www/man21.pdf
https://www.bell-labs.com/usr/dmr/www/man22.pdf

mount & umount were present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

Open was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

read was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

seek was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

setuid was in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

unlink was presen in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

wait was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

write was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

start documenting history
exp was present in v1
https://www.bell-labs.com/usr/dmr/www/man31.pdf

Start documenting history
https://www.bell-labs.com/usr/dmr/www/man31.pdf

Start documenting history
https://www.bell-labs.com/usr/dmr/www/man31.pdf

log appeared in v1
https://www.bell-labs.com/usr/dmr/www/man31.pdf

putc & putw were in v1
https://www.bell-labs.com/usr/dmr/www/man31.pdf

putchar was in v4
https://minie.tuhs.org/cgi-bin/utree.pl?file=V4/man/man3/putchr.3

Start documenting history
https://www.bell-labs.com/usr/dmr/www/man31.pdf

Document history.
https://www.bell-labs.com/usr/dmr/www/man11.pdf
Between v1 & v6 UNIX, bcd was rewritten in C, but I don't know if which
version,
hence I've skipped mentioning it.
End sentence with a dot.
Remove superfluous Pp.
Remove superfluous Pp.
Remove superfluous Ns.
Remove superfluous Pp.
fetch(9) -> ufetch(9)
fetch(9) -> ufetch(9). Remove superfluous Pp.
fetch(9) -> ufetch(9). Remove reference to unimplemented ppi(9).
 1.35.4.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.19 17-Jan-2018  kamil Revert to commits as they broke few rump tests

"Include namespace.h in a few of libc source files
[...]
This change finishes elimination of usage of the global name of the
following symbols:
- close -> _close
- execve -> _execve
- fcntl -> _fcntl
- setcontext -> _setcontext
- wait6 -> _wait6
- write -> _write
- writev -> _writev"

"Register more syscalls in namespace.h (of libc)

Add weak symbols for:
- fcntl
- close
- execve
- setcontext
- wait6
- write
- writev"

These changes broke:

fs/nfs/t_rquotad:get_nfs_be_1_both
fs/nfs/t_rquotad:get_nfs_be_1_group
fs/nfs/t_rquotad:get_nfs_be_1_user
fs/nfs/t_rquotad:get_nfs_le_1_both
fs/nfs/t_rquotad:get_nfs_le_1_group
fs/nfs/t_rquotad:get_nfs_le_1_user
lib/librumphijack/t_config:fdoff
lib/librumphijack/t_tcpip:http
lib/librumphijack/t_tcpip:nfs
lib/librumphijack/t_vfs:cpcopy
lib/librumphijack/t_vfs:mv_x
lib/librumphijack/t_vfs:paxcopy
net/net/t_forwarding:ipforwarding_fastforward_v4
net/net/t_forwarding:ipforwarding_fastforward_v6
net/net/t_forwarding:ipforwarding_fragment_v4
net/net/t_forwarding:ipforwarding_misc
net/net/t_mtudisc6:mtudisc6_basic

This revert fixes the failures, except lib/librumphijack/t_vfs.

The original changes were added in order to facilitate a usage of
sanitizers against programs linked with NetBSD's libc. It is no longer
needed, so abandon these changes.

Sponsored by <The NetBSD Foundation>
 1.18 05-Jan-2018  kamil Include namespace.h in a few of libc source files

The NetBSD Standard C Library uses internally some of its functions with
a mangled symbol name, usually "_symbol". The internal functions shall not
use the global (public) symbols.

This change finishes elimination of usage of the global name of the
following symbols:
- close -> _close
- execve -> _execve
- fcntl -> _fcntl
- setcontext -> _setcontext
- wait6 -> _wait6
- write -> _write
- writev -> _writev

Sponsored by <The NetBSD Foundation>
 1.17 09-Nov-2017  christos Add O_REGULAR to enforce opening of only regular files
(like we have O_DIRECTORY for directories).
This is better than open(, O_NONBLOCK), fstat()+S_ISREG() because opening
devices can have side effects.
 1.16 04-Nov-2017  kre Avoid losing a fd (ie: close it) in the (ever so likely) case that the
fd exceeds the limits of what can be stored in a FILE (65535).
 1.15 15-Mar-2012  christos branches: 1.15.24;
- ansify, knf.
- no functional changes
 1.14 22-Jan-2012  christos From tnozaki@: make fpos_t a complex object that keeps track of the parse
state of the stream. Change argument of the seek function to funopen() from
fpos_t to off_t. Make f{g,s}etpos() use the new fpos_t struct, while providing
backwards compatible entry points. Approved by releng@
 1.13 13-Mar-2008  christos branches: 1.13.6;
Since _file is a short, check that the fd fits in it, otherwise bail with
EMFILE. We treat _file as an unsigned short to double our range, with a
special case for -1 (closed). Make a note of what we should do about stdio
if we ever bump libc. We could change _file in the future compatibly to an
int by putting it in the extension space but for now we don't bother.
 1.12 07-Aug-2003  agc branches: 1.12.22; 1.12.28;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.11 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.10 29-Nov-2000  christos branches: 1.10.2;
make sure we preserve errno.
 1.9 15-Jan-2000  christos add and "f" flag to fopen that makes sure we are opening a plain file,
so that there is no chance to block.
 1.8 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.7 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.6 03-Feb-1998  perry remove obsolete register declarations
 1.5 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.4 02-Feb-1995  jtc branches: 1.4.2;
Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.2.1 02-Mar-1995  jtc #include "namespace.h"
 1.10.2.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.12.28.1 24-Mar-2008  keiichi sync with head.
 1.12.22.1 23-Mar-2008  matt sync with HEAD
 1.13.6.1 17-Apr-2012  yamt sync with head
 1.15.24.1 12-Apr-2018  msaitoh Pull up following revision(s) (requested by christos in ticket #741):
lib/libc/stdio/flags.c: revision 1.19
lib/libc/stdio/fdopen.c: revision 1.18
sys/kern/vfs_vnops.c: revision 1.196
lib/libc/stdio/freopen.c: revision 1.20
lib/libc/stdio/fopen.c: revision 1.17
external/bsd/nvi/dist/common/recover.c: revision 1.10
external/bsd/nvi/dist/common/recover.c: revision 1.11
lib/libc/sys/open.2: revision 1.58
sys/sys/fcntl.h: revision 1.49
make the checkok test stricter to avoid races, and use O_REGULAR.
Instead of opening the file and using popen(3), pass the file descriptor
to sendmail directory. Idea and code from Todd Miller.
Add O_REGULAR to enforce opening of only regular files
(like we have O_DIRECTORY for directories).
This is better than open(, O_NONBLOCK), fstat()+S_ISREG() because opening
devices can have side effects.
 1.5 07-Jan-2014  njoly Kill unneeded paragraph macro.
 1.4 21-Oct-2009  snj branches: 1.4.6; 1.4.12;
Remove 3rd and 4th clauses in christos' license. OK christos.
 1.3 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 30-Nov-2002  lukem branches: 1.1.2;
- Migrate fparseln(3) from libutil to libc, where it should have been in
the first place...
- Bump libutil major (to 7.0) and libc minor (to 12.91).
 1.1.2.2 10-Dec-2002  thorpej Sync with HEAD.
 1.1.2.1 30-Nov-2002  thorpej file fparseln.3 was added on branch nathanw_sa on 2002-12-10 06:25:53 +0000
 1.4.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.10 21-Oct-2009  snj Remove 3rd and 4th clauses in christos' license. OK christos.
 1.9 11-Jan-2009  christos merge christos-time_t
 1.8 05-Jan-2009  tnozaki 1. reworking PR lib/40317:
libnbcompat already contains empty fparseln.lo
so previous fix doesn't work correctly.
i've just added broken fparseln check to configure script.

2. reworking cross build breakage under FreeBSD/MacOS X.
FreeBSD/MacOS X still have public /usr/include/runetype.h
derived from 4.4BSD-Lite. so i renamed out private header from
src/lib/libc/locale/runetype.h to src/lib/libc/locale/runetype_local.h
to solve this problems.

3. fix build breakage when CITRUS=no was set.
 1.7 08-Mar-2007  drochner branches: 1.7.18; 1.7.20;
modify the previous fix so that no pointless realloc()s are done in
the case of multiple empty continuation lines, and comment the code
to make the logics obvious
fix an unrelated comment
 1.6 07-Mar-2007  drochner -fix a condition so that fparseln() doesn't report spurious empty lines
eg after 2 comment lines, or on EOF after a single comment line
-no escape character means no escaped characters
 1.5 20-Jun-2004  jmc branches: 1.5.10;
Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')

Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).

Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.

Fixes PR's: PR#17762 PR#25944
 1.4 11-May-2004  drochner make this build in the tools/compat reachover
case if HAVE_FPARSELN is not present
patch from Christian Limpach
 1.3 10-May-2004  drochner Add FLOCKFILE() locking - should be threadsafe now.
(Didn't test the !HAVE_FPARSELN && !_REENTRANT case -- this might be
hit in tools/compat on some host platforms.)
 1.2 18-Jan-2003  thorpej branches: 1.2.2;
Merge the nathanw_sa branch.
 1.1 30-Nov-2002  lukem branches: 1.1.2;
- Migrate fparseln(3) from libutil to libc, where it should have been in
the first place...
- Bump libutil major (to 7.0) and libc minor (to 12.91).
 1.1.2.2 10-Dec-2002  thorpej Sync with HEAD.
 1.1.2.1 30-Nov-2002  thorpej file fparseln.c was added on branch nathanw_sa on 2002-12-10 06:25:53 +0000
 1.2.2.4 22-Jun-2004  tron Apply patch (requested by jmc in ticket #538):
Fix build problems caused by changes for ticket #527.
 1.2.2.3 22-Jun-2004  tron Pull up revision 1.5 (requested by jmc in ticket #527):
Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')
Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).
Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.
Fixes PR's: PR#17762 PR#25944
 1.2.2.2 22-Jun-2004  tron Pull up revision 1.4 (requested by jmc in ticket #527):
make this build in the tools/compat reachover
case if HAVE_FPARSELN is not present
patch from Christian Limpach
 1.2.2.1 22-Jun-2004  tron Pull up revision 1.3 (requested by jmc in ticket #527):
Add FLOCKFILE() locking - should be threadsafe now.
(Didn't test the !HAVE_FPARSELN && !_REENTRANT case -- this might be
hit in tools/compat on some host platforms.)
 1.5.10.1 02-Jan-2009  jdc Pull up revisions 1.6-1.7 (requested by martin in ticket #1254).

-fix a condition so that fparseln() doesn't report spurious empty lines
eg after 2 comment lines, or on EOF after a single comment line
-no escape character means no escaped characters

modify the previous fix so that no pointless realloc()s are done in
the case of multiple empty continuation lines, and comment the code
to make the logics obvious
fix an unrelated comment
 1.7.20.1 10-Jan-2009  christos sync with head.
 1.7.18.1 15-Jan-2009  snj Pull up following revision(s) (requested by jmcneill in ticket #270):
lib/libc/locale/fix_grouping.c: revision 1.3
lib/libc/locale/iswctype_sb.c: revision 1.7
lib/libc/locale/rune.h: revision 1.14
lib/libc/locale/runetype.h: file removal
lib/libc/locale/runetype_local.h: revision 1.1
lib/libc/stdio/fparseln.c: revision 1.8
lib/libc/string/wcscmp.c: revision 1.7
lib/libc/string/wcsncmp.c: revision 1.7
lib/libc/string/wmemcmp.c: revision 1.5
tools/compat/configure: regen
tools/compat/configure.ac: revision 1.68
tools/compat/nbtool_config.h.in: regen
usr.bin/mklocale/Makefile: revision 1.15
usr.bin/mklocale/lex.l: revision 1.16
usr.bin/mklocale/yacc.y: revision 1.27
1. reworking PR lib/40317:
libnbcompat already contains empty fparseln.lo
so previous fix doesn't work correctly.
i've just added broken fparseln check to configure script.
2. reworking cross build breakage under FreeBSD/MacOS X.
FreeBSD/MacOS X still have public /usr/include/runetype.h
derived from 4.4BSD-Lite. so i renamed out private header from
src/lib/libc/locale/runetype.h to src/lib/libc/locale/runetype_local.h
to solve this problems.
3. fix build breakage when CITRUS=no was set.
 1.15 23-Jan-2019  mrg remove diag assert - the compiler demands fp is non NULL now.
 1.14 04-Feb-2018  mrg branches: 1.14.2; 1.14.4;
fixes for GCC 6:

- -Wstrict-prototypes is not available for C++, so don't try to
ignore it for C++.
- remove many _DIAGASSERT() checks against not NULL for functions
with arguments with nonnull attributes. in two cases, leave
code behind that should set defaults to "(null)".
- use -Wno-error=frame-address for i386 mcount, as it seems valid
to assume the caller will have a frame.fair
 1.13 19-Apr-2013  joerg Add explicit locale versions for the printf family. Replace asprintf,
snprintf and sprintf with simple wrappers around the corresponding
va_list functions to reduce code duplication.
 1.12 15-Mar-2012  christos branches: 1.12.2;
- ansify, knf.
- no functional changes
 1.11 07-Aug-2003  agc branches: 1.11.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.10 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.9 26-May-2002  wiz __STDC__ is always defined on NetBSD.
 1.8 20-Sep-1999  lukem branches: 1.8.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.7 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 31-Dec-1993  jtc Add explicit return types to function definitions.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8.10.1 21-Jun-2002  nathanw Catch up to -current.
 1.11.56.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.11.56.1 17-Apr-2012  yamt sync with head
 1.12.2.1 23-Jun-2013  tls resync from head
 1.14.4.1 10-Jun-2019  christos Sync with HEAD
 1.14.2.1 26-Jan-2019  pgoyette Sync with HEAD
 1.14 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.13 07-Aug-2003  agc branches: 1.13.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.12 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.11 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.10 21-Jan-2000  mycroft branches: 1.10.6;
Do the lock *after* checking that the fp is valid.
 1.9 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.8 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.7 03-Feb-1998  perry remove obsolete register declarations
 1.6 19-Jan-1998  jtc Use FLOCKFILE() and FUNLOCKFILE() macros from reentrant.h so that stdio
can be made thread-safe.
 1.5 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.4 02-Feb-1995  jtc branches: 1.4.6;
Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.6.1 20-Sep-1996  jtc snapshot namespace cleanup: net, etc.
 1.10.6.2 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.10.6.1 28-Jan-2002  nathanw Catch up to -current.
 1.13.56.1 17-Apr-2012  yamt sync with head
 1.14 04-Feb-2018  mrg fixes for GCC 6:

- -Wstrict-prototypes is not available for C++, so don't try to
ignore it for C++.
- remove many _DIAGASSERT() checks against not NULL for functions
with arguments with nonnull attributes. in two cases, leave
code behind that should set defaults to "(null)".
- use -Wno-error=frame-address for i386 mcount, as it seems valid
to assume the caller will have a frame.fair
 1.13 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.12 07-Aug-2003  agc branches: 1.12.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.11 18-Jul-2003  nathanw #include "local.h" to get __flockfile_internal() prototype.
 1.10 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.9 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.8 03-Feb-1998  perry remove obsolete register declarations
 1.7 19-Jan-1998  jtc Use FLOCKFILE() and FUNLOCKFILE() macros from reentrant.h so that stdio
can be made thread-safe.
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 29-Mar-1996  jtc Add explict function return types
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.12.56.1 17-Apr-2012  yamt sync with head
 1.14 30-Jul-2017  wiz Bump date for previous.
 1.13 30-Jul-2017  cheusov According to POSIX return value of fputs(3) should be a non-netagive value if it succeeds
 1.12 22-Feb-2017  abhinav Fix a sentence.
Add write(2) in SEE ALSO.
 1.11 07-Aug-2003  agc branches: 1.11.80; 1.11.84;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.10 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.9 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.8 07-Feb-2002  ross Generate <>& symbolically.
 1.7 16-Sep-2001  wiz Mainly sort SEE ALSO, but also sort sections, and some punctuation and
paragraph fixes.
 1.6 29-Dec-2000  kleink branches: 1.6.2;
Sprinkle some __restrict into stdio.
 1.5 05-Feb-1998  perry add LIBRARY section to man page
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 29-Nov-1993  jtc Use "Er" for argument to -width in the lists in the ERROR sections so that
formatting is consistant.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.6.2.3 22-Mar-2002  nathanw Catch up to -current.
 1.6.2.2 08-Mar-2002  nathanw Catch up to -current.
 1.6.2.1 08-Oct-2001  nathanw Catch up to -current.
 1.11.84.1 21-Apr-2017  bouyer Sync with HEAD
 1.11.80.1 20-Mar-2017  pgoyette Sync with HEAD
 1.16 04-Feb-2018  mrg fixes for GCC 6:

- -Wstrict-prototypes is not available for C++, so don't try to
ignore it for C++.
- remove many _DIAGASSERT() checks against not NULL for functions
with arguments with nonnull attributes. in two cases, leave
code behind that should set defaults to "(null)".
- use -Wno-error=frame-address for i386 mcount, as it seems valid
to assume the caller will have a frame.fair
 1.15 13-Mar-2012  christos PR/45989: Martin Husemann: lint invocation does include -w only on i386

- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
builds)

approved by core@
 1.14 22-Jun-2005  christos branches: 1.14.44;
If the string to be printed is NULL substitute "(null)". Approved by core.
This is a workaround to make gcc's behavior consistent, since gcc can
transform:
printf("%s\n", s) -> puts(s)
fprintf(fp, "%s", s) -> fputs(s, fp)
as an optimization.
I've left the _DIAGASSERT's that make sure that s != NULL alone because we
should really still abort in a debugging environment.
 1.13 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.12 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.11 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.10 20-Sep-1999  lukem branches: 1.10.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.9 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.8 15-Nov-1998  christos delint
 1.7 19-Jan-1998  jtc Use FLOCKFILE() and FUNLOCKFILE() macros from reentrant.h so that stdio
can be made thread-safe.
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 29-Mar-1996  jtc Add explict function return types
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.10.10.2 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.10.10.1 28-Jan-2002  nathanw Catch up to -current.
 1.14.44.1 17-Apr-2012  yamt sync with head
 1.5 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.4 12-Jun-2005  lukem branches: 1.4.44;
Add missing __RCSID()
 1.3 07-Mar-2003  tshiozak add fgetws() and fputws() (lib/20576).

Note: fgetws.c, fgetws.3, fputws.c and fputws.3 are obtained from FreeBSD,
and fitted by sigsegv@infoseek.jp and me.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 07-Dec-2001  yamt branches: 1.1.2;
- make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.1.2.3 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.1.2.2 28-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 07-Dec-2001  nathanw file fputwc.c was added on branch nathanw_sa on 2002-01-28 20:50:57 +0000
 1.4.44.1 17-Apr-2012  yamt sync with head
 1.3 16-Dec-2010  wiz Observe the following spelling:
- wide character (noun)
- wide-character (adjective)

Inspired by jmc@OpenBSD.
 1.2 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.1 07-Mar-2003  tshiozak add fgetws() and fputws() (lib/20576).

Note: fgetws.c, fgetws.3, fputws.c and fputws.3 are obtained from FreeBSD,
and fitted by sigsegv@infoseek.jp and me.
 1.2 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.1 07-Mar-2003  tshiozak branches: 1.1.56;
add fgetws() and fputws() (lib/20576).

Note: fgetws.c, fgetws.3, fputws.c and fputws.3 are obtained from FreeBSD,
and fitted by sigsegv@infoseek.jp and me.
 1.1.56.1 17-Apr-2012  yamt sync with head
 1.16 01-Feb-2021  jdolecek for fread(3) and fwrite(3) check for (size * nmemb) size_t overflow, and
error out with EOVERFLOW if it happens; this is less silly answer
to a silly call than returning some randomly wrapped length

change adapted from OpenBSD

FreeBSD has a similar check, but they return EINVAL instead, feel
free to adjust if SUS or other standard mandates specific value

suggested by Kamil Rytarowski
 1.15 11-Sep-2011  jruoho .Xr for fsetpos(3), not .Fn.
 1.14 11-Jan-2009  christos merge christos-time_t
 1.13 19-Dec-2008  christos PR/9359: Chris Demetriou: Document fread/fwrite mixing behavior.
 1.12 07-Aug-2003  agc branches: 1.12.38; 1.12.40;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.11 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.10 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.9 07-Feb-2002  ross Generate <>& symbolically.
 1.8 25-Jan-2001  lukem branches: 1.8.2;
apparently ansi c only required fread(3) to return 0 if size or nmembs == 0.
however, susv2 adds the same to fwrite(3), so add the explicit check.
document this for both fread & fwrite. move diagassert for buf!=NULL to after
the (size * nmembs) == 0 check.

this has the helpful side effect of preventing the _DIAGASSERT()ion in
fwrite() being triggered by lots of 3rdparty code that calls fwrite() with
buf=NULL count=0
 1.7 29-Dec-2000  kleink Sprinkle some __restrict into stdio.
 1.6 05-Feb-1998  perry add LIBRARY section to man page
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 04-Oct-1993  jtc fread and fwrite both return size_t, not int.
 1.3 01-Aug-1993  mycroft Add RCS indentifiers.
 1.2 22-Apr-1993  mycroft Fix various bugs in man pages (from 386BSD patch 130).
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8.2.2 22-Mar-2002  nathanw Catch up to -current.
 1.8.2.1 08-Mar-2002  nathanw Catch up to -current.
 1.12.40.1 04-Jan-2009  christos merge with head.
 1.12.38.1 23-Dec-2008  snj Pull up following revision(s) (requested by christos in ticket #201):
lib/libc/stdio/fread.3: revision 1.13
PR/8359: Chris Demetriou: Document fread/fwrite mixing behavior.
 1.27 20-Jan-2024  christos Catch up with all the lint warnings since exit on warning was disabled.
Disable 'missing header declaration' and 'nested extern' warnings for now.
 1.26 07-Feb-2021  jdolecek restore change from rev 1.23 "Avoid undefined behavior in fread(3)", mistakely
removed as part __SNBF optimization
 1.25 01-Feb-2021  jdolecek for fread(3) and fwrite(3) check for (size * nmemb) size_t overflow, and
error out with EOVERFLOW if it happens; this is less silly answer
to a silly call than returning some randomly wrapped length

change adapted from OpenBSD

FreeBSD has a similar check, but they return EINVAL instead, feel
free to adjust if SUS or other standard mandates specific value

suggested by Kamil Rytarowski
 1.24 31-Jan-2021  jdolecek for unbuffered I/O arrange for the destination buffer to be filled in one
go, instead of triggering long series of 1 byte read(2)s; this speeds up
fread() several order of magnitudes for this case, directly proportional
to the size of the supplied buffer

change adapted from OpenBSD rev. 1.19

fixes PR lib/55808 by Roland Illig
 1.23 22-Feb-2020  kamil Avoid undefined behavior in fread(3)

On the first call to fread(3), just after fopen(3) the internal buffers
are empty. This means that _r and _p (among others) are zeroed.

Passing NULL to the 2nd argument of memcpy(3) for the zero length is
undefined. Calling _p += 0 triggers LLVM UBSan (NULL pointer arithmetic).
Calling _p += 0, p += 0 and resid -= 0 has no effect.

Replace the "fp->_r = 0;" logic with a short circuit jump to __srefill()
that sets _r internally and refills the FILE buffers.

No functional change from an end user point of view, except skipping a few
dummy operations on the first call, for a FILE pointer, to fread(3).
 1.22 15-Mar-2012  christos branches: 1.22.32; 1.22.34;
- ansify, knf.
- no functional changes
 1.21 13-Mar-2012  christos PR/45989: Martin Husemann: lint invocation does include -w only on i386

- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
builds)

approved by core@
 1.20 25-Oct-2009  christos branches: 1.20.6;
revert some of dsl's changes to make things build on i386; he can undo what
he wants when he comes back.
 1.19 25-Oct-2009  dsl Lint is differentially far too picky...
Remove some warnings that only appear on i386 (not on amd64) and that
for some reason best known to others are deemed fatal for i386.
Making this code 'pass lint' does absolutely nothing for its readability (etc).
 1.18 24-Oct-2009  dsl Remove a load of pointless casts - one that even lint doesn't bleat about.
 1.17 31-Jan-2009  lukem sign-compare fix
 1.16 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.15 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.14 25-Jan-2001  lukem branches: 1.14.2;
apparently ansi c only required fread(3) to return 0 if size or nmembs == 0.
however, susv2 adds the same to fwrite(3), so add the explicit check.
document this for both fread & fwrite. move diagassert for buf!=NULL to after
the (size * nmembs) == 0 check.

this has the helpful side effect of preventing the _DIAGASSERT()ion in
fwrite() being triggered by lots of 3rdparty code that calls fwrite() with
buf=NULL count=0
 1.13 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.12 17-Sep-1999  lukem revert previous; if we examine SUS more closely we find that unless explictly specified, use of a NULL pointer is undefined
 1.11 16-Sep-1999  lukem return (0) if size or count == 0 before check for _DIAGASSERT(buf != NULL).
this is ok according to SUS.
 1.10 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.9 03-Feb-1998  perry remove obsolete register declarations
 1.8 19-Jan-1998  jtc Use FLOCKFILE() and FUNLOCKFILE() macros from reentrant.h so that stdio
can be made thread-safe.
 1.7 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.6 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.5 14-Dec-1993  jtc Change from Chris Torek (via comp.std.c) to make fread() ANSI compliant.
 1.4 04-Oct-1993  jtc fread and fwrite both return size_t, not int.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.14.2.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.20.6.1 17-Apr-2012  yamt sync with head
 1.22.34.1 07-Feb-2021  martin Pull up following revision(s) (requested by jdolecek in ticket #1198):

lib/libc/stdio/fread.c: revision 1.24 (via patch)

for unbuffered I/O arrange for the destination buffer to be filled in one
go, instead of triggering long series of 1 byte read(2)s; this speeds up
fread() several order of magnitudes for this case, directly proportional
to the size of the supplied buffer
change adapted from OpenBSD rev. 1.19

fixes PR lib/55808 by Roland Illig
 1.22.32.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.22 17-Jan-2018  kamil Revert to commits as they broke few rump tests

"Include namespace.h in a few of libc source files
[...]
This change finishes elimination of usage of the global name of the
following symbols:
- close -> _close
- execve -> _execve
- fcntl -> _fcntl
- setcontext -> _setcontext
- wait6 -> _wait6
- write -> _write
- writev -> _writev"

"Register more syscalls in namespace.h (of libc)

Add weak symbols for:
- fcntl
- close
- execve
- setcontext
- wait6
- write
- writev"

These changes broke:

fs/nfs/t_rquotad:get_nfs_be_1_both
fs/nfs/t_rquotad:get_nfs_be_1_group
fs/nfs/t_rquotad:get_nfs_be_1_user
fs/nfs/t_rquotad:get_nfs_le_1_both
fs/nfs/t_rquotad:get_nfs_le_1_group
fs/nfs/t_rquotad:get_nfs_le_1_user
lib/librumphijack/t_config:fdoff
lib/librumphijack/t_tcpip:http
lib/librumphijack/t_tcpip:nfs
lib/librumphijack/t_vfs:cpcopy
lib/librumphijack/t_vfs:mv_x
lib/librumphijack/t_vfs:paxcopy
net/net/t_forwarding:ipforwarding_fastforward_v4
net/net/t_forwarding:ipforwarding_fastforward_v6
net/net/t_forwarding:ipforwarding_fragment_v4
net/net/t_forwarding:ipforwarding_misc
net/net/t_mtudisc6:mtudisc6_basic

This revert fixes the failures, except lib/librumphijack/t_vfs.

The original changes were added in order to facilitate a usage of
sanitizers against programs linked with NetBSD's libc. It is no longer
needed, so abandon these changes.

Sponsored by <The NetBSD Foundation>
 1.21 05-Jan-2018  kamil Include namespace.h in a few of libc source files

The NetBSD Standard C Library uses internally some of its functions with
a mangled symbol name, usually "_symbol". The internal functions shall not
use the global (public) symbols.

This change finishes elimination of usage of the global name of the
following symbols:
- close -> _close
- execve -> _execve
- fcntl -> _fcntl
- setcontext -> _setcontext
- wait6 -> _wait6
- write -> _write
- writev -> _writev

Sponsored by <The NetBSD Foundation>
 1.20 09-Nov-2017  christos Add O_REGULAR to enforce opening of only regular files
(like we have O_DIRECTORY for directories).
This is better than open(, O_NONBLOCK), fstat()+S_ISREG() because opening
devices can have side effects.
 1.19 27-Mar-2012  christos branches: 1.19.24;
- widen the internal read and write calls to match the syscalls
- add funopen2() which provides access to flush() and the wider calls.
- make use of the new flush call in fmemopen()
 1.18 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.17 22-Jan-2012  christos From tnozaki@: make fpos_t a complex object that keeps track of the parse
state of the stream. Change argument of the seek function to funopen() from
fpos_t to off_t. Make f{g,s}etpos() use the new fpos_t struct, while providing
backwards compatible entry points. Approved by releng@
 1.16 11-Jan-2010  joerg branches: 1.16.6;
Use a proper char */size_t pair in __sfileext to keep track of the line
buffer for fgetln and fgetwln. Simplifies code by dropping the INT_MAX
related logic. Drop conditionals around FREELB, free(NULL) is valid.
 1.15 13-Mar-2008  christos Since _file is a short, check that the fd fits in it, otherwise bail with
EMFILE. We treat _file as an unsigned short to double our range, with a
special case for -1 (closed). Make a note of what we should do about stdio
if we ever bump libc. We could change _file in the future compatibly to an
int by putting it in the extension space but for now we don't bother.
 1.14 07-Aug-2003  agc branches: 1.14.22; 1.14.28;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.13 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.12 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.11 29-Nov-2000  christos branches: 1.11.2;
Add checks for O_NDELAY [which indicates that we only want plain files],
and return an error if the file was not plain.
 1.10 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.9 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.8 06-Jan-1999  kleink When reopening in append mode, seek to the end of file in order to have the
internally kept offset pointer reflect this; ftell(3) would report an
incorrect current offset otherwise. From Geoff C. Wing in lib/6381.
 1.7 03-Feb-1998  perry remove obsolete register declarations
 1.6 13-Jul-1997  christos branches: 1.6.2;
Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 04-May-1996  mycroft Change suggested by Chris Torek to fix problem freopen()ing with a closed
file descriptor.
 1.4 02-Feb-1995  jtc branches: 1.4.2;
Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.2.1 02-Mar-1995  jtc #include "namespace.h"
 1.6.2.1 18-Jan-1999  cgd pull up rev 1.8 from trunk (PR#6381). (kleink)
 1.11.2.2 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.11.2.1 28-Jan-2002  nathanw Catch up to -current.
 1.14.28.1 24-Mar-2008  keiichi sync with head.
 1.14.22.1 23-Mar-2008  matt sync with HEAD
 1.16.6.1 17-Apr-2012  yamt sync with head
 1.19.24.1 12-Apr-2018  msaitoh Pull up following revision(s) (requested by christos in ticket #741):
lib/libc/stdio/flags.c: revision 1.19
lib/libc/stdio/fdopen.c: revision 1.18
sys/kern/vfs_vnops.c: revision 1.196
lib/libc/stdio/freopen.c: revision 1.20
lib/libc/stdio/fopen.c: revision 1.17
external/bsd/nvi/dist/common/recover.c: revision 1.10
external/bsd/nvi/dist/common/recover.c: revision 1.11
lib/libc/sys/open.2: revision 1.58
sys/sys/fcntl.h: revision 1.49
make the checkok test stricter to avoid races, and use O_REGULAR.
Instead of opening the file and using popen(3), pass the file descriptor
to sendmail directory. Idea and code from Todd Miller.
Add O_REGULAR to enforce opening of only regular files
(like we have O_DIRECTORY for directories).
This is better than open(, O_NONBLOCK), fstat()+S_ISREG() because opening
devices can have side effects.
 1.14 19-Apr-2013  joerg Add scanf_l and wscanf_l families.
 1.13 15-Mar-2012  christos branches: 1.13.2;
- ansify, knf.
- no functional changes
 1.12 07-Aug-2003  agc branches: 1.12.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.11 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.10 26-May-2002  wiz __STDC__ is always defined on NetBSD.
 1.9 24-May-2002  thorpej * Move the prototype of __svfscanf from <stdio.h> to libc/stdio/local.h.
* Add prototype for vfscanf to <stdio.h>.
* Remove #define of vfscanf to __svfscanf from <stdio.h>.
* Include local.h in libc files which need __svfscanf.
* Add vfscanf weak alias to __svfscanf.

Fixes standards/16997.

NOTE: libc minor not bumped -- ride on the bump to 12.84 made by
itojun today.
 1.8 20-Sep-1999  lukem branches: 1.8.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.7 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 29-Mar-1996  jtc Add explict function return types
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8.10.2 22-Jun-2002  thorpej Need "reentrant.h"
 1.8.10.1 21-Jun-2002  nathanw Catch up to -current.
 1.12.56.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.12.56.1 17-Apr-2012  yamt sync with head
 1.13.2.1 23-Jun-2013  tls resync from head
 1.29 11-Sep-2021  rillig fseek.3: fix grammar
 1.28 01-Jan-2017  abhinav Fix sentences at a couple of places.
Reorganize the RETURN VALUES section a bit to improve readability.
Add xrefs to clearerr(3) and ungetc(3) in SEE ALSO.
Bump date.

ok wiz@
 1.27 22-Jan-2012  wiz branches: 1.27.22;
Remove trailing whitespace.
 1.26 22-Jan-2012  christos From tnozaki@: make fpos_t a complex object that keeps track of the parse
state of the stream. Change argument of the seek function to funopen() from
fpos_t to off_t. Make f{g,s}etpos() use the new fpos_t struct, while providing
backwards compatible entry points. Approved by releng@
 1.25 22-Oct-2010  christos branches: 1.25.6;
Fix return value documentation. Add EOVERFLOW for ftell, but not for fseek.
 1.24 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.23 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.22 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.21 07-Feb-2002  ross Generate <>& symbolically.
 1.20 02-Feb-2002  wiz Punctuation nit, and slight grammar improvement.
 1.19 02-Feb-2002  yamt note that our fsetpos/fgetpos don't know about stream's state.
it's a bug since we now have stateful encodings like iso2022 and
wide char functions like fgetwc.
 1.18 16-Sep-2001  wiz Boring whitespace fixes.
 1.17 29-Dec-2000  kleink branches: 1.17.2;
Sprinkle some __restrict into stdio.
 1.16 26-Jul-2000  kleink XCU5 -> XSH5.
 1.15 08-Jul-2000  kleink Elaborate a bit on fseeko() and ftello().
 1.14 08-Jul-2000  kleink Bump date for fseeko() and ftello().
 1.13 08-Jul-2000  kleink XCU5: Add fseeko() and ftello() functions which provide the functionality of
fseek() and ftell(), respectively, but operate on file offsets of type off_t.
 1.12 08-Mar-1999  kleink Const poisoning.
 1.11 09-Sep-1998  kleink Make the fseek() return value description match XSH5 (again).
 1.10 09-Sep-1998  kleink Typo; from Michael Richardson <mcr@sandelman.ottawa.on.ca> in PR misc/6053.
 1.9 28-Apr-1998  fair Change occurrences of "UNIX" to .Ux or .At as appropriate.
 1.8 05-Feb-1998  perry add LIBRARY section to man page
 1.7 08-Mar-1997  mouse branches: 1.7.2;
alternate -> alternative, per PR 2643
 1.6 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.5 30-Nov-1993  jtc Use ".Va" macro when formatting "errno".
 1.4 29-Nov-1993  jtc Use "Er" for argument to -width in the lists in the ERROR sections so that
formatting is consistant.
 1.3 07-Aug-1993  cgd merge in changes from netbsd-0-9-ALPHA2
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd branches: 1.1.1.1.2;
initial import of 386bsd-0.1 sources
 1.1.1.1.2.2 06-Aug-1993  jtc Clarified the wording of the RETURN VALUES section once again. Fseek
returns -1 on error, the others return non-zero.
The wording is still awkward, fgetpos & fsetpos should probably get a
separate manual page. But this should be good enough for the release.
 1.1.1.1.2.1 06-Aug-1993  jtc fgetpos returned wrong value.
fseek/fsetpos/fgetpos manual page too specific. The functions are specified
to return nonzero on failure, not -1.
 1.7.2.1 27-Sep-1998  cgd pull up revs 1.10-1.11 from trunk (kleink).
 1.17.2.3 22-Mar-2002  nathanw Catch up to -current.
 1.17.2.2 08-Mar-2002  nathanw Catch up to -current.
 1.17.2.1 08-Oct-2001  nathanw Catch up to -current.
 1.25.6.1 17-Apr-2012  yamt sync with head
 1.27.22.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.24 16-Nov-2014  christos Don't try to extend the offset range on 32 bit machines by treating negative
offsets as positive. It is just confusing.
 1.23 29-Apr-2008  martin branches: 1.23.8;
Convert to new 2 clause license
 1.22 26-Jan-2006  kleink branches: 1.22.18;
Must include "namespace.h" for fseeko()'s internal name.
 1.21 04-Mar-2005  dsl branches: 1.21.2;
Re-implement in terms of fseek0()
 1.20 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.19 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.18 20-Sep-1999  lukem branches: 1.18.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.17 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.16 15-Nov-1998  christos delint
 1.15 06-Sep-1998  kleink Sloppy stdio stream lock tracking.
 1.14 03-Feb-1998  perry remove obsolete register declarations
 1.13 03-Feb-1998  mycroft Deal with GCC warning.
 1.12 19-Jan-1998  jtc Use FLOCKFILE() and FUNLOCKFILE() macros from reentrant.h so that stdio
can be made thread-safe.
 1.11 19-Dec-1997  kleink Change several functions to return -1 instead of EOF, which was semantically
wrong.
 1.10 19-Oct-1997  mycroft Use S_IS*(), not S_IF*.
 1.9 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.8 05-Mar-1995  jtc flush so that the offset will be correct on streams opened in
append mode (from chris torek).
 1.7 02-Feb-1995  jtc branches: 1.7.2;
Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.6 04-Jan-1994  cgd rename fgetline()
 1.5 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.4 02-Aug-1993  mycroft Nuke remaining patchkit headers.
 1.3 01-Aug-1993  mycroft Add RCS identifiers.
 1.2 21-Mar-1993  cgd after 0.2.2 "stable" patches applied
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7.2.1 02-Mar-1995  jtc #include "namespace.h"
 1.18.10.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.21.2.1 28-Jan-2006  tron Pull up following revision(s) (requested by kleink in ticket #1140):
lib/libc/stdio/fseek.c: revision 1.22
Must include "namespace.h" for fseeko()'s internal name.
 1.22.18.1 18-May-2008  yamt sync with head.
 1.23.8.2 29-Apr-2008  martin Convert to new 2 clause license
 1.23.8.1 29-Apr-2008  martin file fseek.c was added on branch christos-time_t on 2008-04-29 06:53:02 +0000
 1.14 10-Jan-2017  christos add linted comment
 1.13 19-Oct-2014  justin branches: 1.13.2;
Add negative offset checks to fseeko

These were not strictly needed before, as lseek would error on negative
arguments, but having added open_memstream we have a virtual file pointer
that assumes that it gets sane values, so we get an assertion triggered
on a negative value. Best to check in one place rather than at all the
relevant points.
 1.12 27-Mar-2012  christos - widen the internal read and write calls to match the syscalls
- add funopen2() which provides access to flush() and the wider calls.
- make use of the new flush call in fmemopen()
 1.11 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.10 13-Mar-2012  christos PR/45989: Martin Husemann: lint invocation does include -w only on i386

- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
builds)

approved by core@
 1.9 22-Jan-2012  christos From tnozaki@: make fpos_t a complex object that keeps track of the parse
state of the stream. Change argument of the seek function to funopen() from
fpos_t to off_t. Make f{g,s}etpos() use the new fpos_t struct, while providing
backwards compatible entry points. Approved by releng@
 1.8 31-Jan-2009  lukem branches: 1.8.8;
sign-compare fix
 1.7 13-Mar-2008  christos Since _file is a short, check that the fd fits in it, otherwise bail with
EMFILE. We treat _file as an unsigned short to double our range, with a
special case for -1 (closed). Make a note of what we should do about stdio
if we ever bump libc. We could change _file in the future compatibly to an
int by putting it in the extension space but for now we don't bother.
 1.6 18-Dec-2006  christos branches: 1.6.4; 1.6.8;
remove bogus (void)&var; From Anon Ymous
 1.5 04-Mar-2005  dsl de __P
 1.4 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.3 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.2 26-Jul-2000  kleink branches: 1.2.2;
Oops, forgot to define weak aliases for public names.
Fixes PR {pkg,lib}/10655.
 1.1 08-Jul-2000  kleink XCU5: Add fseeko() and ftello() functions which provide the functionality of
fseek() and ftell(), respectively, but operate on file offsets of type off_t.
 1.2.2.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.6.8.1 24-Mar-2008  keiichi sync with head.
 1.6.4.1 23-Mar-2008  matt sync with HEAD
 1.8.8.1 17-Apr-2012  yamt sync with head
 1.13.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.11 22-Jan-2012  christos From tnozaki@: make fpos_t a complex object that keeps track of the parse
state of the stream. Change argument of the seek function to funopen() from
fpos_t to off_t. Make f{g,s}etpos() use the new fpos_t struct, while providing
backwards compatible entry points. Approved by releng@
 1.10 07-Aug-2003  agc branches: 1.10.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.9 08-Jul-2000  kleink In fgetpos() and fsetpos(), use ftello() and fseeko(), respectively, to avoid
truncating the value stored in the fpos_t object operated on to that of a
long integer; adresses PR lib/6637.
 1.8 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.7 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 31-Dec-1993  jtc Add explicit return types to function definitions.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.10.56.1 17-Apr-2012  yamt sync with head
 1.20 27-Mar-2012  christos - widen the internal read and write calls to match the syscalls
- add funopen2() which provides access to flush() and the wider calls.
- make use of the new flush call in fmemopen()
 1.19 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.18 22-Jan-2012  christos From tnozaki@: make fpos_t a complex object that keeps track of the parse
state of the stream. Change argument of the seek function to funopen() from
fpos_t to off_t. Make f{g,s}etpos() use the new fpos_t struct, while providing
backwards compatible entry points. Approved by releng@
 1.17 24-Oct-2010  tron branches: 1.17.6;
Replace _FPOS_OVERFLOW() macro with a static inline function called
__fpos_overflow() that doesn't cause any lint warnings.
 1.16 22-Oct-2010  christos implement EOVERFLOW
 1.15 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.14 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.13 20-Sep-1999  lukem branches: 1.13.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.12 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.11 15-Nov-1998  christos delint
 1.10 03-Feb-1998  perry remove obsolete register declarations
 1.9 02-Feb-1998  perry merge lite-2
 1.8 19-Jan-1998  jtc Use FLOCKFILE() and FUNLOCKFILE() macros from reentrant.h so that stdio
can be made thread-safe.
 1.7 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.6 22-Mar-1995  jtc Removed const qualifier from ftell's FILE * argument. It's not ANSI,
and the recent change to flush output causes it to be changed.
 1.5 05-Mar-1995  jtc flush so that the offset will be correct on streams opened in
append mode (from chris torek).
 1.4 02-Feb-1995  jtc branches: 1.4.2;
Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 02-Feb-1998  perry import lite-2
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.2.1 22-Mar-1995  jtc Merge with changes from main branch.
 1.13.10.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.17.6.1 17-Apr-2012  yamt sync with head
 1.7 27-Mar-2012  christos - widen the internal read and write calls to match the syscalls
- add funopen2() which provides access to flush() and the wider calls.
- make use of the new flush call in fmemopen()
 1.6 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.5 22-Jan-2012  christos From tnozaki@: make fpos_t a complex object that keeps track of the parse
state of the stream. Change argument of the seek function to funopen() from
fpos_t to off_t. Make f{g,s}etpos() use the new fpos_t struct, while providing
backwards compatible entry points. Approved by releng@
 1.4 07-Aug-2003  agc branches: 1.4.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.3 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.2 26-Jul-2000  kleink branches: 1.2.2;
Oops, forgot to define weak aliases for public names.
Fixes PR {pkg,lib}/10655.
 1.1 08-Jul-2000  kleink XCU5: Add fseeko() and ftello() functions which provide the functionality of
fseek() and ftell(), respectively, but operate on file offsets of type off_t.
 1.2.2.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.4.56.1 17-Apr-2012  yamt sync with head
 1.27 24-Feb-2025  andvar s/sightly/slightly/ and s/sligtly/slightly/ in documentation and comment.
 1.26 13-Oct-2024  rillig lib: sync some manual pages with reality
 1.25 21-Mar-2019  uwe branches: 1.25.12;
Minor markup and wording fixes.
 1.24 06-Apr-2016  dholland branches: 1.24.16;
improve usage
 1.23 06-Sep-2015  dholland SEE ALSO fmemopen(3)
 1.22 08-Oct-2012  njoly Kill some extra spaces in function arguments.
 1.21 09-Jun-2012  njoly branches: 1.21.2;
Consistently use major/minor for NetBSD version.
 1.20 11-May-2012  njoly Small typo.
 1.19 27-Mar-2012  christos - widen the internal read and write calls to match the syscalls
- add funopen2() which provides access to flush() and the wider calls.
- make use of the new flush call in fmemopen()
 1.18 22-Jan-2012  wiz Bump date for previous.
 1.17 22-Jan-2012  christos From tnozaki@: make fpos_t a complex object that keeps track of the parse
state of the stream. Change argument of the seek function to funopen() from
fpos_t to off_t. Make f{g,s}etpos() use the new fpos_t struct, while providing
backwards compatible entry points. Approved by releng@
 1.16 11-Sep-2011  jruoho branches: 1.16.2;
It is not just funopen(3) that is a BSDism.
 1.15 22-Mar-2010  joerg Use .In for header files instead of .Ar Pa and variations.
 1.14 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.13 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.12 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.11 07-Feb-2002  ross Generate <>& symbolically.
 1.10 16-Sep-2001  wiz Boring whitespace fixes.
 1.9 05-Feb-1998  perry branches: 1.9.12;
add LIBRARY section to man page
 1.8 03-Feb-1998  perry .Bx'ize
 1.7 23-Jan-1997  mikel xref lseek(2) instead of seek(2); PR lib/2750
also note fpos_t/off_t discrepancy.
 1.6 07-Nov-1996  mouse Apply PR 2751 - writefn's second arg is const char *, not char *.
 1.5 17-Jan-1996  jtc Fix typo in funopen prototype; Reported by Noriyuki Soda in PR #1954
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 29-Nov-1993  jtc Use "Er" for argument to -width in the lists in the ERROR sections so that
formatting is consistant.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9.12.3 22-Mar-2002  nathanw Catch up to -current.
 1.9.12.2 08-Mar-2002  nathanw Catch up to -current.
 1.9.12.1 08-Oct-2001  nathanw Catch up to -current.
 1.16.2.3 30-Oct-2012  yamt sync with head
 1.16.2.2 23-May-2012  yamt sync with head.
 1.16.2.1 17-Apr-2012  yamt sync with head
 1.21.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.24.16.1 10-Jun-2019  christos Sync with HEAD
 1.25.12.1 02-Aug-2025  perseant Sync with HEAD
 1.15 23-Oct-2016  christos PR/51572: calling funopen on each printw call is a tad excessive, but this
is not a reason for funopen to leak. Always call the close function since we
are indirecting through our cookie and we need to free it.
 1.14 28-Mar-2012  christos branches: 1.14.10; 1.14.12; 1.14.14; 1.14.16;
only provide compatibility i/o functions to the ones provided by the caller.
 1.13 27-Mar-2012  christos - widen the internal read and write calls to match the syscalls
- add funopen2() which provides access to flush() and the wider calls.
- make use of the new flush call in fmemopen()
 1.12 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.11 22-Jan-2012  christos From tnozaki@: make fpos_t a complex object that keeps track of the parse
state of the stream. Change argument of the seek function to funopen() from
fpos_t to off_t. Make f{g,s}etpos() use the new fpos_t struct, while providing
backwards compatible entry points. Approved by releng@
 1.10 29-Nov-2005  christos branches: 1.10.44;
WARNS=4
 1.9 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.8 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.7 15-Nov-1998  christos branches: 1.7.12;
delint
 1.6 03-Feb-1998  perry remove obsolete register declarations
 1.5 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7.12.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.10.44.1 17-Apr-2012  yamt sync with head
 1.14.16.1 18-Jan-2017  skrll Sync with netbsd-5
 1.14.14.1 04-Nov-2016  pgoyette Sync with HEAD
 1.14.12.1 12-Dec-2016  snj Pull up following revision(s) (requested by mrg in ticket #1303):
lib/libc/stdio/funopen.c: revision 1.15
PR/51572: calling funopen on each printw call is a tad excessive, but this
is not a reason for funopen to leak. Always call the close function since we
are indirecting through our cookie and we need to free it.
 1.14.10.1 12-Dec-2016  snj Pull up following revision(s) (requested by mrg in ticket #1303):
lib/libc/stdio/funopen.c: revision 1.15
PR/51572: calling funopen on each printw call is a tad excessive, but this
is not a reason for funopen to leak. Always call the close function since we
are indirecting through our cookie and we need to free it.
 1.31 29-Mar-2024  christos From enh at google dot com in tech-userlevel. Don't limit writes to BUFSIZ,
change the limit to INT_MAX; improves performance dramatically. From:
https://github.com/apple-oss-distributions/Libc/commit/\
c5a3293354e22262702a3add5b2dfc9bb0b93b85\
#diff-3b844a19cfb0aab1a23f7fbc457d3bce7453513730c489a72f66ff89d6557ff3
 1.30 22-Jul-2021  christos branches: 1.30.2;
revert changes to fflush.c (1.18) and fvwrite.c (1.25) until we investigate
collateral damage. Breaks h_intr.c test. Requested by RVP.
 1.29 19-Jul-2021  christos There's no need to adjust `iov' in the error path.
Returning the amount written is all that's needed.
from RVP
 1.28 16-Jul-2021  christos When fflush fails, adjust pointers and the io vectors. From RVP. Fixes
core-dump at cvs(1) exit(3).
 1.27 08-Jul-2021  christos Obey EINTR and return immediately adjusting for unwritten. From RVP
 1.26 06-Jul-2021  christos Handle EINTR, from RVP.
 1.25 27-Mar-2012  christos - widen the internal read and write calls to match the syscalls
- add funopen2() which provides access to flush() and the wider calls.
- make use of the new flush call in fmemopen()
 1.24 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.23 13-Mar-2012  christos PR/45989: Martin Husemann: lint invocation does include -w only on i386

- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
builds)

approved by core@
 1.22 24-Mar-2011  dholland branches: 1.22.4;
Eliminate dead store. From Henning Petersen in PR 42776. Doesn't change
the output .o file.
 1.21 25-Oct-2009  christos revert some of dsl's changes to make things build on i386; he can undo what
he wants when he comes back.
 1.20 25-Oct-2009  dsl Lint is differentially far too picky...
Remove some warnings that only appear on i386 (not on amd64) and that
for some reason best known to others are deemed fatal for i386.
Making this code 'pass lint' does absolutely nothing for its readability (etc).
 1.19 24-Oct-2009  dsl Remove a load of pointless casts - one that even lint doesn't bleat about.
 1.18 11-Feb-2009  lukem Fix sign-compare issues.
Ensure provided uio_resid >= 0; negative sizes have "interesting"
semantics elsewhere in stdio, so it's better to avoid them.
 1.17 02-Feb-2007  christos branches: 1.17.22;
Instead of abusing stdio to get a signal-safe version of sprintf, provide one.
 1.16 27-Oct-2006  christos branches: 1.16.2;
Add signal-safe versions of snprintf and vsnprintf
 1.15 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.14 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.13 20-Sep-1999  lukem branches: 1.13.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.12 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.11 15-Nov-1998  christos delint
 1.10 15-Oct-1998  mycroft Allocate space exponentially, not linearly.
 1.9 28-Aug-1998  perry add asprintf and vasprintf, originally written by Todd Miller for OpenBSD
 1.8 03-Feb-1998  perry remove obsolete register declarations
 1.7 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.6 03-May-1997  kleink Upon an attempt to write to a stream that can't be written to, set errno
to EBADF.
 1.5 29-Mar-1996  jtc Add explict function return types
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.13.10.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.16.2.1 07-May-2007  pavel Pull up following revision(s) (requested by manu in ticket #607):
lib/libc/arch/i386/gen/isnanl.c: revision 1.6
lib/libc/gdtoa/gdtoa.c: revision 1.2-1.3
lib/libc/arch/x86_64/gen/isnanl.c: revision 1.6
lib/libc/gdtoa/gdtoaimp.h: revision 1.6
sys/arch/m68k/include/ieee.h: revision 1.13
usr.bin/xlint/lint1/scan.l: revision 1.36-1.37
lib/libc/stdio/snprintf_ss.c: revision 1.4
lib/libc/arch/i386/gen/isfinitel.c: revision 1.2
lib/libc/stdio/vfscanf.c: revision 1.38
sys/arch/sparc/include/ieee.h: revision 1.11-1.12
lib/libc/gdtoa/dtoa.c: revision 1.4
lib/libc/stdio/Makefile.inc: revision 1.35
lib/libc/stdio/fvwrite.c: revision 1.17
lib/libc/arch/m68k/gen/fpclassifyl.c: revision 1.2
lib/libc/arch/i386/gen/isinfl.c: revision 1.6
lib/libc/arch/x86_64/gen/isinfl.c: revision 1.6
lib/libc/arch/x86_64/gen/isfinitel.c: revision 1.2
lib/libc/stdio/vfprintf.c: revision 1.55-1.57
lib/libc/stdio/vsnprintf_ss.c: revision 1.3
lib/libc/stdio/vfwprintf.c: revision 1.10
sys/arch/x86/include/ieee.h: revision 1.10
lib/libc/gdtoa/dmisc.c: revision 1.3
lib/libc/gdtoa/Makefile.inc: revision 1.5
sys/arch/hppa/include/ieee.h: revision 1.10
lib/libc/arch/x86_64/gen/fpclassifyl.c: revision 1.3
lib/libc/arch/i386/gen/fpclassifyl.c: revision 1.2
sys/sys/ieee754.h: revision 1.7
lib/libc/gdtoa/gdtoa.h: revision 1.7
include/stdio.h: revision 1.67-1.68
lib/libc/gdtoa/hdtoa.c: revision 1.1-1.4
lib/libc/gdtoa/ldtoa.c: revision 1.1-1.4
defined(_NETBSD_SOURCE) is equivalent to (!defined(_ANSI_SOURCE) &&
!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)), so there's no
need to check both of them.
Fix for issue reported in PR lib/35401 as well as related overflow bugs.
deal with hex doubles.
Instead of abusing stdio to get a signal-safe version of sprintf, provide one.
remove __SAFE
add long double and hex double support from freebsd.
make this compile.
add new prototypes.
add the new files to the build. Note I am not bumping libc now, because
these are not used yet.
Merge the int bit with the high fraction bit. Add constants/macros
needed by gdtoa.
add constants used by gdtoa
since the int bit is merged, do the explicit math.
ext_int bit is no more.
ext_int bit is no more.
- merge change from freebsd
- add support for building as vfprintf.c
- XXX: we strdup to simplify the freeing logic. This should be fixed for
efficiency in the vfprintf case.
use vfwprintf.c
enable wide doubles.
some int -> size_t
deal with sparc64 that has 112 bits of mantissa.
make extended precision gdtoa friendly.
int/size_t changes
make this gdtoa friendly.
remove dup definition
use dtoa() instead of returning empty when we don't have extended precision
information.
Fix previous, add forgotten pointer dereference in the call to dtoa().
Add a cheesy workaround marked XXX for the situation where the
strtod() implementation available in the environment does not
handle hex floats.
Discussed with and suggested by christos
From Christos: gdtoa fixes for m68k. M68k ports should build now, but
printing extended precision is a little off.
vax does not have <machine/ieee.h> or long double
It would be nice if the compiler provided something like __IEEE_MATH__
bring in FreeBSD's vfscanf() to gain multi-byte/collation support.
Unfortunately it is too difficult to make vfwscanf and this share
the same code like I did with printf, because for string parsing
the code is too different.
 1.17.22.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.22.4.1 17-Apr-2012  yamt sync with head
 1.30.2.1 20-Jul-2024  martin Pull up following revision(s) (requested by rin in ticket #754):

lib/libc/stdio/fvwrite.c: revision 1.31

From enh at google dot com in tech-userlevel. Don't limit writes to
BUFSIZ, change the limit to INT_MAX; improves performance dramatically. From:
https://github.com/apple-oss-distributions/Libc/commit/c5a3293354e22262702a3add5b2dfc9bb0b93b85#diff-3b844a19cfb0aab1a23f7fbc457d3bce7453513730c489a72f66ff89d6557ff3
 1.8 13-Mar-2012  christos PR/45989: Martin Husemann: lint invocation does include -w only on i386

- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
builds)

approved by core@
 1.7 07-Aug-2003  agc branches: 1.7.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.6 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.5 26-May-2002  wiz __STDC__ is always defined on NetBSD.
 1.4 08-Sep-1998  kleink branches: 1.4.12;
s/c_plusplus/__cplusplus/
 1.3 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.12.1 21-Jun-2002  nathanw Catch up to -current.
 1.7.56.1 17-Apr-2012  yamt sync with head
 1.12 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.11 07-Aug-2003  agc branches: 1.11.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.10 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.9 20-Sep-1999  lukem branches: 1.9.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.8 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.7 03-Feb-1998  perry remove obsolete register declarations
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 29-Mar-1996  jtc Add explict function return types
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9.10.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.11.56.1 17-Apr-2012  yamt sync with head
 1.6 08-Sep-2003  wiz Use St -isoC-9X instead of St -isoC9X, to be in sync with groff.
 1.5 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.4 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.3 07-Feb-2002  ross Generate <>& symbolically.
 1.2 07-Dec-2001  wiz branches: 1.2.2;
Grammar improvements, some additional markup and a typo fix.
 1.1 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.2.2.4 22-Mar-2002  nathanw Catch up to -current.
 1.2.2.3 08-Mar-2002  nathanw Catch up to -current.
 1.2.2.2 28-Jan-2002  nathanw Catch up to -current.
 1.2.2.1 07-Dec-2001  nathanw file fwide.3 was added on branch nathanw_sa on 2002-01-28 20:50:59 +0000
 1.3 12-Jun-2005  lukem Add missing __RCSID()
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 07-Dec-2001  yamt branches: 1.1.2;
- make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.1.2.3 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.1.2.2 28-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 07-Dec-2001  nathanw file fwide.c was added on branch nathanw_sa on 2002-01-28 20:51:00 +0000
 1.3 19-Apr-2013  joerg Add explicit locale versions for the printf family. Replace asprintf,
snprintf and sprintf with simple wrappers around the corresponding
va_list functions to reduce code duplication.
 1.2 15-Mar-2012  christos branches: 1.2.2;
- ansify, knf.
- no functional changes
 1.1 14-May-2005  christos branches: 1.1.44;
Add the missing wide char support functions from freebsd.
XXX: long double support is missing until we get gdtoa, and add the
necessary wide functions.
 1.1.44.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.44.1 17-Apr-2012  yamt sync with head
 1.2.2.1 23-Jun-2013  tls resync from head
 1.19 01-Feb-2021  jdolecek for fread(3) and fwrite(3) check for (size * nmemb) size_t overflow, and
error out with EOVERFLOW if it happens; this is less silly answer
to a silly call than returning some randomly wrapped length

change adapted from OpenBSD

FreeBSD has a similar check, but they return EINVAL instead, feel
free to adjust if SUS or other standard mandates specific value

suggested by Kamil Rytarowski
 1.18 04-Feb-2018  mrg fixes for GCC 6:

- -Wstrict-prototypes is not available for C++, so don't try to
ignore it for C++.
- remove many _DIAGASSERT() checks against not NULL for functions
with arguments with nonnull attributes. in two cases, leave
code behind that should set defaults to "(null)".
- use -Wno-error=frame-address for i386 mcount, as it seems valid
to assume the caller will have a frame.fair
 1.17 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.16 29-Nov-2005  christos branches: 1.16.44;
WARNS=4
 1.15 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.14 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.13 25-Jan-2001  lukem branches: 1.13.2;
apparently ansi c only required fread(3) to return 0 if size or nmembs == 0.
however, susv2 adds the same to fwrite(3), so add the explicit check.
document this for both fread & fwrite. move diagassert for buf!=NULL to after
the (size * nmembs) == 0 check.

this has the helpful side effect of preventing the _DIAGASSERT()ion in
fwrite() being triggered by lots of 3rdparty code that calls fwrite() with
buf=NULL count=0
 1.12 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.11 17-Sep-1999  lukem revert previous; if we examine SUS more closely we find that unless explictly specified, use of a NULL pointer is undefined
 1.10 16-Sep-1999  lukem return (0) if size or count == 0 before check for _DIAGASSERT(buf != NULL).
this is ok according to SUS.
 1.9 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.8 15-Nov-1998  christos delint
 1.7 19-Jan-1998  jtc Use FLOCKFILE() and FUNLOCKFILE() macros from reentrant.h so that stdio
can be made thread-safe.
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 04-Oct-1993  jtc fread and fwrite both return size_t, not int.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.13.2.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.16.44.1 17-Apr-2012  yamt sync with head
 1.3 19-Apr-2013  joerg Add scanf_l and wscanf_l families.
 1.2 15-Mar-2012  christos branches: 1.2.2;
- ansify, knf.
- no functional changes
 1.1 14-May-2005  christos branches: 1.1.44;
Add the missing wide char support functions from freebsd.
XXX: long double support is missing until we get gdtoa, and add the
necessary wide functions.
 1.1.44.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.44.1 17-Apr-2012  yamt sync with head
 1.2.2.1 23-Jun-2013  tls resync from head
 1.13 02-Sep-2019  sevan Start documenting history
https://www.bell-labs.com/usr/dmr/www/man31.pdf
 1.12 07-Aug-2003  agc branches: 1.12.98; 1.12.100;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.11 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.10 28-Jan-2003  kleink Add a manual page for flockfile(3) etc.; while here, also add *_unlocked()
to stdio(3) overview documentation. Fixes PR lib/20096 from Jason Thorpe.
 1.9 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.8 07-Feb-2002  ross Generate <>& symbolically.
 1.7 16-Sep-2001  wiz Mainly sort SEE ALSO, but also sort sections, and some punctuation and
paragraph fixes.
 1.6 25-Apr-2001  kleink Document getc_unlocked(3), getchar_unlocked(3), putc_unlocked(3) and
putchar_unlocked(3); fixes PR lib/11340.
 1.5 28-Apr-1998  fair branches: 1.5.12;
fix mdoc references and other mistakes
 1.4 05-Feb-1998  perry add LIBRARY section to man page
 1.3 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.12.3 22-Mar-2002  nathanw Catch up to -current.
 1.5.12.2 08-Mar-2002  nathanw Catch up to -current.
 1.5.12.1 08-Oct-2001  nathanw Catch up to -current.
 1.12.100.1 05-Sep-2019  martin Pull up following revision(s) (requested by sevan in ticket #174):
lib/libc/sys/chmod.2: revision 1.48
lib/libc/sys/stat.2: revision 1.59
lib/libc/sys/unlink.2: revision 1.30
lib/libc/sys/lseek.2: revision 1.25
lib/libc/sys/getuid.2: revision 1.18
lib/libc/sys/chown.2: revision 1.37
lib/libm/man/exp.3: revision 1.32
lib/libm/man/log.3: revision 1.7
lib/libc/sys/open.2: revision 1.60
lib/libc/stdio/fopen.3: revision 1.36
lib/libc/stdio/putc.3: revision 1.14
lib/libc/sys/mount.2: revision 1.51
share/man/man9/copy.9: revision 1.22
share/man/man9/uiomove.9: revision 1.20
lib/libc/sys/setuid.2: revision 1.23
lib/libc/sys/close.2: revision 1.18
sbin/init/init.8: revision 1.61
lib/libc/sys/write.2: revision 1.36
lib/libc/sys/read.2: revision 1.39
sbin/init/init.8: revision 1.62
lib/libc/sys/wait.2: revision 1.40
usr.bin/tty/tty.1: revision 1.10
lib/libc/sys/link.2: revision 1.33
usr.bin/du/du.1: revision 1.24
lib/libc/stdlib/exit.3: revision 1.17
usr.bin/su/su.1: revision 1.53
usr.bin/mail/mail.1: revision 1.66
lib/libc/sys/fork.2: revision 1.25
usr.bin/su/su.1: revision 1.54
usr.bin/mail/mail.1: revision 1.67
lib/libm/man/sin.3: revision 1.15
share/man/man9/intro.9: revision 1.26
share/man/man5/utmp.5: revision 1.17
lib/libc/compat-43/creat.3: revision 1.17
lib/libc/time/ctime.3: revision 1.61
lib/libcompat/4.1/stty.3: revision 1.10
usr.bin/dc/dc.1: revision 1.3
lib/libm/man/cos.3: revision 1.17
lib/libc/sys/chdir.2: revision 1.23
lib/libc/gen/exec.3: revision 1.30
lib/libc/gen/exec.3: revision 1.31
games/bcd/bcd.6: revision 1.18
games/bcd/bcd.6: revision 1.19
usr.bin/write/write.1: revision 1.7
usr.bin/wc/wc.1: revision 1.18
usr.bin/pr/pr.1: revision 1.24
usr.bin/who/who.1: revision 1.25
lib/libc/sys/mkdir.2: revision 1.30
lib/libc/stdio/getc.3: revision 1.13
usr.bin/sort/sort.1: revision 1.40
usr.bin/mesg/mesg.1: revision 1.11
share/man/man5/passwd.5: revision 1.34
sort was there since v1
https://www.bell-labs.com/usr/dmr/www/man61.pdf

dc was in v1
https://www.bell-labs.com/usr/dmr/www/man12.pdf

du was in v1
https://www.bell-labs.com/usr/dmr/www/man12.pdf

mail was in v1
https://www.bell-labs.com/usr/dmr/www/man12.pdf

mesg was in v1
https://www.bell-labs.com/usr/dmr/www/man12.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man13.pdf

su was in v1
https://www.bell-labs.com/usr/dmr/www/man13.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man13.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man14.pdf
Update URL

write was in v1
https://www.bell-labs.com/usr/dmr/www/man14.pdf
grammar

passwd(5) was in v1
https://www.bell-labs.com/usr/dmr/www/man51.pdf

utmp(5) was present in v1
https://www.bell-labs.com/usr/dmr/www/man51.pdf

Earliest version of wtmp I could find was in v3
https://minnie.tuhs.org/cgi-bin/utree.pl?file=V3/man/man5/wtmp.5

Document history of chdir(2)
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history of chmod(2)
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history of chown(2)
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man21.pdf

create was present in v1
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history of exec()
Move statement on execlpe() & execvpe() to HISTORY section.

Document history
https://www.bell-labs.com/usr/dmr/www/man21.pdf

fork was present in v1
https://www.bell-labs.com/usr/dmr/www/man21.pdf
stat() was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

document history of fstat()
https://www.bell-labs.com/usr/dmr/www/man21.pdf

getuid was present in v1
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man21.pdf

stty & gtty were around since v1
https://www.bell-labs.com/usr/dmr/www/man21.pdf
https://www.bell-labs.com/usr/dmr/www/man22.pdf

mount & umount were present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

Open was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

read was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

seek was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

setuid was in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

unlink was presen in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

wait was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

write was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

start documenting history
exp was present in v1
https://www.bell-labs.com/usr/dmr/www/man31.pdf

Start documenting history
https://www.bell-labs.com/usr/dmr/www/man31.pdf

Start documenting history
https://www.bell-labs.com/usr/dmr/www/man31.pdf

log appeared in v1
https://www.bell-labs.com/usr/dmr/www/man31.pdf

putc & putw were in v1
https://www.bell-labs.com/usr/dmr/www/man31.pdf

putchar was in v4
https://minie.tuhs.org/cgi-bin/utree.pl?file=V4/man/man3/putchr.3

Start documenting history
https://www.bell-labs.com/usr/dmr/www/man31.pdf

Document history.
https://www.bell-labs.com/usr/dmr/www/man11.pdf
Between v1 & v6 UNIX, bcd was rewritten in C, but I don't know if which
version,
hence I've skipped mentioning it.
End sentence with a dot.
Remove superfluous Pp.
Remove superfluous Pp.
Remove superfluous Ns.
Remove superfluous Pp.
fetch(9) -> ufetch(9)
fetch(9) -> ufetch(9). Remove superfluous Pp.
fetch(9) -> ufetch(9). Remove reference to unimplemented ppi(9).
 1.12.98.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.12 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.11 07-Aug-2003  agc branches: 1.11.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.10 18-Jul-2003  nathanw #include "local.h" to get __flockfile_internal() prototype.
 1.9 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.8 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.7 19-Jan-1998  jtc Use FLOCKFILE() and FUNLOCKFILE() macros from reentrant.h so that stdio
can be made thread-safe.
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 31-Dec-1993  jtc Add explicit return types to function definitions.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11.56.1 17-Apr-2012  yamt sync with head
 1.10 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.9 07-Aug-2003  agc branches: 1.9.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.8 18-Jul-2003  nathanw #include "local.h" to get __flockfile_internal() prototype.
 1.7 19-Jan-1998  jtc Use FLOCKFILE() and FUNLOCKFILE() macros from reentrant.h so that stdio
can be made thread-safe.
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 29-Mar-1996  jtc Add explict function return types
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9.56.1 17-Apr-2012  yamt sync with head
 1.15 03-Jul-2017  wiz Remove workaround for ancient HTML generation code.
 1.14 16-Sep-2014  wiz Remove trailing whitespace.
 1.13 16-Sep-2014  apb Rephrase the NOTE about embedded NUL characters, using "apparent length"
for what strlen(3) reports, and "true length" for what the return value
reports.
 1.12 15-Sep-2014  christos mention what happens if the line contains NUL's.
 1.11 15-Sep-2014  christos fix markup.
 1.10 15-Sep-2014  christos Fix documentation to reflect what happens when EOF is found before delimiter,
aligning us with POSIX.
 1.9 20-Apr-2011  enami - Put empty line after the local variable definition in the sample code
to improve readability.
- Remove indirection operator to clarify error condition.
 1.8 30-Jun-2010  jruoho Use .Fn instead of .Fa for functions. Also rearrange slightly.
 1.7 09-Dec-2009  joerg Fix markup.
 1.6 01-Dec-2009  wiz Make HTML-ready, use standard section headers, fix Xr.
 1.5 30-Nov-2009  roy Note that callers should use feof(3) or ferror(3) to distinguish between
EOF or an error.
 1.4 30-Nov-2009  roy Note that EOF returns -1 when no characters are read.
Add code example.
 1.3 25-Aug-2009  wiz Note some restrictions for getdelim arguments noted by joerg.
Bump date.
 1.2 13-Jul-2009  wiz The character is NUL, the pointer is NULL.
Fix a typo.
It's \-1, not -1.
Add "and getline" in a few places.
Add comma in enumeration.
No dot needed in SEE ALSO.
End sentence with a dot.
 1.1 13-Jul-2009  roy Add implementations for getdelim(3) and getline(3).
 1.14 08-Jun-2017  uwe Don't use "NULL" to talk about null-terminated strings.

The C standard seems to be inconsistent about dash vs. space. Old
text uses dash, Annex K uses space. I'll let wizd(8) to sort that
out.
 1.13 22-Jul-2011  joerg Set error indicator on invalid arguments. From Carsten Hey.
 1.12 07-Dec-2009  roy Test against SSIZE_MAX as pointed out by enami tsugutomo.
 1.11 02-Dec-2009  roy Pass lint.
 1.10 02-Dec-2009  roy Reinstate __getdelim which does no locking.
Callers are now required to FLOCKFILE so they can operate on fp as well.
 1.9 01-Dec-2009  roy Protect getdelim when used internally.
 1.8 01-Dec-2009  roy Remove __getdelim and just use getdelim.
fgetstr now works with strings up to SSIZE_MAX as a result, but may
reallocate buffers needlessly just like it used to when the buffer size
exceeds INT_MAX.
fgetstr converts errno EOVERFLOW to EINVAL on getdelim error.
 1.7 25-Oct-2009  christos revert some of dsl's changes to make things build on i386; he can undo what
he wants when he comes back.
 1.6 25-Oct-2009  dsl Lint is differentially far too picky...
Remove some warnings that only appear on i386 (not on amd64) and that
for some reason best known to others are deemed fatal for i386.
Making this code 'pass lint' does absolutely nothing for its readability (etc).
 1.5 24-Oct-2009  dsl Remove a load of pointless casts - one that even lint doesn't bleat about.
 1.4 24-Sep-2009  roy __getdelim works on strings up to SIZE_MAX - 2 and returns 0 on EOF.
getdelim works on strings up to SSIZE_MAX and returns -1 on EOF.
__fgetstr is now just a wrapper around __getdelim and ensures that
the buffer doesn't overflow the one provided by FILE.
__slbexpand is now static in fgetwln as it is the only consumer of that func.
 1.3 14-Jul-2009  roy Allow a buffer of SSIZE_MAX + 1 as the returned bytes do not include the NULL.
 1.2 14-Jul-2009  christos pass lint
 1.1 13-Jul-2009  roy Add implementations for getdelim(3) and getline(3).
 1.3 02-Dec-2009  roy Protect getline.
 1.2 01-Dec-2009  roy Protect getdelim when used internally.
 1.1 13-Jul-2009  roy Add implementations for getdelim(3) and getline(3).
 1.18 04-Oct-2013  christos avoid linker warning for compat symbols that are used internally in libc,
by introducing a hidden compat_foo() function, using that internally in
libc, and exposing foo as a strong alias to compat_foo(). I am open for
better ideas.
 1.17 15-Mar-2012  christos branches: 1.17.2;
- ansify, knf.
- no functional changes
 1.16 03-Jun-2007  christos branches: 1.16.36;
Make these work with _FORTIFY_SOURCE, by overriding the fortified definitions
 1.15 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.14 18-Jul-2003  nathanw #include "local.h" to get __flockfile_internal() prototype.
 1.13 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.12 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.11 20-Nov-1998  kleink Need to wrap stdio stream locking around the function body. On the bright
side, getchar_unlocked() can now be used instead of getchar().
 1.10 03-Feb-1998  perry remove obsolete register declarations
 1.9 04-Nov-1997  thorpej __warn_references and __indr_reference semicolon fixups. From
Chris Demetriou <cgd@pa.dec.com>.
 1.8 13-Jul-1997  christos branches: 1.8.2;
Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.7 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.6 21-Jul-1994  jtc Converted to use link-time warning messages.
 1.5 24-Apr-1994  mycroft branches: 1.5.2;
Get rid of extra calls to strlen().
 1.4 24-Apr-1994  mycroft Print the name of the program using a deprecated function.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.2.1 24-Jul-1994  cgd update from runk
 1.8.2.1 04-Nov-1997  thorpej Pull up from trunk: __warn_references and __indr_reference semicolon fixups.
 1.16.36.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.16.36.1 17-Apr-2012  yamt sync with head
 1.17.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.24 06-Aug-2025  kre Clean up sources (remove temporary hack)

Remove the temporary hack added so these could build before
O_CLOFORK (etc) became visible to userland.

NFCI.
 1.23 17-Jul-2025  kre Libc functions which need to know about O_CLOFORK.

These are Ricardo Branco's libc updates for affected functions
that use O_CLOFORK &/or FD_CLOFORK.

These are currently padded (by me) with temporary additions so
they build while the O_CLOFORK/FD_CLOFORK definitions remain hidden
to userland.
 1.22 20-Jan-2024  christos branches: 1.22.2;
Catch up with all the lint warnings since exit on warning was disabled.
Disable 'missing header declaration' and 'nested extern' warnings for now.
 1.21 10-Jan-2017  christos include <sys/stat.h>
 1.20 05-Feb-2015  christos branches: 1.20.2;
add a couple of casts.
 1.19 19-Jun-2014  msaitoh Fix "shadows a global declaration" compile error.
 1.18 18-Jun-2014  christos add mkostemp, mkostemps, mkstemps from FreeBSD.
 1.17 21-Jan-2014  seanb branches: 1.17.2;
Handle case where a 0 length template string or a template
of all 'X' would dereference, and maybe assign to, memory
before the template. Simplify.
 1.16 22-Apr-2013  christos PR/47757: Eric Radman: mktemp(3) mangles the pathname if not given an absolute
path
1. on error, gettemp() did not restore the path string
2. when emulating mktemp() it is not an error for the pattern not to represent
a real directory structure
XXX[1]: pullup-5, pullup-6
XXX[2]: the default pattern is the simplistic <pid><X> for mktemp.
 1.15 15-Mar-2012  christos branches: 1.15.2;
- ansify, knf.
- no functional changes
 1.14 20-Oct-2008  apb branches: 1.14.2; 1.14.4; 1.14.20; 1.14.22;
The tools/compat versions of mkstemp() and mkdtemp() need to call the
internal function that's usually named "__gettemp". However in a cross
build, "__gettemp" is in a namespace reserved for the host system, so we
can't use that. Use "__nbcompat_gettemp" instead, following the example
of several other functions or macros in tools/compat. Previously, this
was handled by using the name "gettemp", but that conflicts with the
local gettemp() function in dist/nawk.
 1.13 05-Dec-2003  uebayasi Spaces.
 1.12 27-Oct-2003  lukem Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.11 23-Oct-2003  jmc Move include for reentrant.h inside CONFIG_H test so this works correctly
with tools/compat. Fixes PR#21344
 1.10 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.9 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.8 14-Sep-2002  thorpej Allow mktemp to be built as a host tool.
 1.7 01-Apr-2002  bjh21 branches: 1.7.2;
Revert addition of mkdtemp() to libnbcompat. I don't think we need mktemp(1)
after all.
 1.6 31-Mar-2002  bjh21 Add mkdtemp to libnbcompat, since glibc doesn't have it an mktemp(1) will
need it.
 1.5 20-Sep-1999  lukem branches: 1.5.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.4 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.3 19-Mar-1999  christos braces for gcc-2.8.1
 1.2 27-Jul-1998  mycroft Add a mktempdir(), like mkstemp(), but it creates a directory.
 1.1 27-Jul-1998  mycroft If AUDIT, do not compile certain functions.
 1.5.10.2 17-Sep-2002  nathanw Catch up to -current.
 1.5.10.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.7.2.1 30-Nov-2002  he Pull up revision 1.8 (requested by thorpej in ticket #806):
Allow mktemp to build as a host tool.
 1.14.22.1 16-Apr-2015  snj Pull up following revision(s) (requested by msaitoh in ticket #1282):
lib/libc/stdio/gettemp.c: revision 1.16
PR/47757: Eric Radman: mktemp(3) mangles the pathname if not given an absolute
path
1. on error, gettemp() did not restore the path string
2. when emulating mktemp() it is not an error for the pattern not to represent
a real directory structure
XXX[1]: pullup-5, pullup-6
XXX[2]: the default pattern is the simplistic <pid><X> for mktemp.
 1.14.20.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.14.20.1 17-Apr-2012  yamt sync with head
 1.14.4.2 20-Oct-2008  apb The tools/compat versions of mkstemp() and mkdtemp() need to call the
internal function that's usually named "__gettemp". However in a cross
build, "__gettemp" is in a namespace reserved for the host system, so we
can't use that. Use "__nbcompat_gettemp" instead, following the example
of several other functions or macros in tools/compat. Previously, this
was handled by using the name "gettemp", but that conflicts with the
local gettemp() function in dist/nawk.
 1.14.4.1 20-Oct-2008  apb file gettemp.c was added on branch christos-time_t on 2008-10-20 10:28:39 +0000
 1.14.2.1 16-Apr-2015  snj Pull up following revision(s) (requested by msaitoh in ticket #1955):
lib/libc/stdio/gettemp.c: revision 1.16 via patch
PR/47757: Eric Radman: mktemp(3) mangles the pathname if not given an absolute
path
1. on error, gettemp() did not restore the path string
2. when emulating mktemp() it is not an error for the pattern not to represent
a real directory structure
XXX[1]: pullup-5, pullup-6
XXX[2]: the default pattern is the simplistic <pid><X> for mktemp.
 1.15.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.15.2.1 23-Jun-2013  tls resync from head
 1.17.2.1 10-Aug-2014  tls Rebase.
 1.20.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.22.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 18-Jun-2014  christos branches: 1.1.2; 1.1.6;
add mkostemp, mkostemps, mkstemps from FreeBSD.
 1.1.6.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.6.1 18-Jun-2014  tls file gettemp.h was added on branch tls-maxphys on 2014-08-20 00:02:16 +0000
 1.1.2.2 10-Aug-2014  tls Rebase.
 1.1.2.1 18-Jun-2014  tls file gettemp.h was added on branch tls-earlyentropy on 2014-08-10 06:51:51 +0000
 1.10 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.9 07-Aug-2003  agc branches: 1.9.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.8 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.7 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 02-Feb-1995  jtc branches: 1.5.6;
Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 31-Dec-1993  jtc Add explicit return types to function definitions.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.6.1 20-Sep-1996  jtc snapshot namespace cleanup: net, etc.
 1.9.56.1 17-Apr-2012  yamt sync with head
 1.10 25-Oct-2017  abhinav Remove comma after last Nm entry
 1.9 16-Dec-2010  wiz Observe the following spelling:
- wide character (noun)
- wide-character (adjective)

Inspired by jmc@OpenBSD.
 1.8 06-May-2010  jruoho Note POSIX compliance.
 1.7 08-Sep-2003  wiz Use St -isoC-9X instead of St -isoC9X, to be in sync with groff.
 1.6 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.5 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.4 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.3 07-Feb-2002  ross Generate <>& symbolically.
 1.2 07-Dec-2001  wiz branches: 1.2.2;
Markup getwc in one place.
 1.1 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.2.2.4 22-Mar-2002  nathanw Catch up to -current.
 1.2.2.3 08-Mar-2002  nathanw Catch up to -current.
 1.2.2.2 28-Jan-2002  nathanw Catch up to -current.
 1.2.2.1 07-Dec-2001  nathanw file getwc.3 was added on branch nathanw_sa on 2002-01-28 20:51:00 +0000
 1.3 12-Jun-2005  lukem Add missing __RCSID()
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 07-Dec-2001  yamt branches: 1.1.2;
- make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.1.2.2 28-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 07-Dec-2001  nathanw file getwc.c was added on branch nathanw_sa on 2002-01-28 20:51:01 +0000
 1.4 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.3 12-Jun-2005  lukem branches: 1.3.44;
Add missing __RCSID()
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 07-Dec-2001  yamt branches: 1.1.2;
- make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.1.2.2 28-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 07-Dec-2001  nathanw file getwchar.c was added on branch nathanw_sa on 2002-01-28 20:51:01 +0000
 1.3.44.1 17-Apr-2012  yamt sync with head
 1.5 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.4 10-Dec-2000  christos fix duplicate declaration of __glue.
 1.3 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.38 18-Jun-2014  christos add mkostemp, mkostemps, mkstemps from FreeBSD.
 1.37 04-Oct-2013  christos branches: 1.37.2;
avoid linker warning for compat symbols that are used internally in libc,
by introducing a hidden compat_foo() function, using that internally in
libc, and exposing foo as a strong alias to compat_foo(). I am open for
better ideas.
 1.36 19-Apr-2013  joerg Add scanf_l and wscanf_l families.
 1.35 19-Apr-2013  joerg Add explicit locale versions for the printf family. Replace asprintf,
snprintf and sprintf with simple wrappers around the corresponding
va_list functions to reduce code duplication.
 1.34 27-Mar-2012  christos branches: 1.34.2;
- widen the internal read and write calls to match the syscalls
- add funopen2() which provides access to flush() and the wider calls.
- make use of the new flush call in fmemopen()
 1.33 15-Mar-2012  christos fix signature.
 1.32 15-Mar-2012  christos ansi prototypes.
 1.31 22-Jan-2012  christos From tnozaki@: make fpos_t a complex object that keeps track of the parse
state of the stream. Change argument of the seek function to funopen() from
fpos_t to off_t. Make f{g,s}etpos() use the new fpos_t struct, while providing
backwards compatible entry points. Approved by releng@
 1.30 17-Jul-2011  joerg branches: 1.30.2;
Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.29 24-Oct-2010  tron Replace _FPOS_OVERFLOW() macro with a static inline function called
__fpos_overflow() that doesn't cause any lint warnings.
 1.28 23-Oct-2010  christos tell lint to shut up.
 1.27 22-Oct-2010  christos not that it can happen, but make the test more robust.
 1.26 22-Oct-2010  christos implement EOVERFLOW
 1.25 06-Sep-2010  christos add dprintf and vdprintf
 1.24 11-Jan-2010  joerg Use a proper char */size_t pair in __sfileext to keep track of the line
buffer for fgetln and fgetwln. Simplifies code by dropping the INT_MAX
related logic. Drop conditionals around FREELB, free(NULL) is valid.
 1.23 02-Dec-2009  roy Reinstate __getdelim which does no locking.
Callers are now required to FLOCKFILE so they can operate on fp as well.
 1.22 01-Dec-2009  roy Remove __getdelim and just use getdelim.
fgetstr now works with strings up to SSIZE_MAX as a result, but may
reallocate buffers needlessly just like it used to when the buffer size
exceeds INT_MAX.
fgetstr converts errno EOVERFLOW to EINVAL on getdelim error.
 1.21 24-Sep-2009  roy __getdelim works on strings up to SIZE_MAX - 2 and returns 0 on EOF.
getdelim works on strings up to SSIZE_MAX and returns -1 on EOF.
__fgetstr is now just a wrapper around __getdelim and ensures that
the buffer doesn't overflow the one provided by FILE.
__slbexpand is now static in fgetwln as it is the only consumer of that func.
 1.20 14-May-2005  christos Add the missing wide char support functions from freebsd.
XXX: long double support is missing until we get gdtoa, and add the
necessary wide functions.
 1.19 09-Feb-2005  kleink A little libc namespace housekeeping exercise:
* Make vfprintf_unlocked() an internal function, c.f. __svfscanf_unlocked().
* Add internal names for arc4random(), endnetpath(), fhstatvfs(),
fstatvfs(), mkstemp(), shquote(), statvfs(), taddr2uaddr(), uaddr2taddr(),
uuid_create_nil(), uuid_is_nil(), and wcwidth().
* Include namespace.h where supposed to.
 1.18 10-May-2004  drochner After discussion with christos, turn fgetstr() into an internal function.
Its API in inherently non-threadsafe (and it depends on certain properties
of the underlying stdio implementation), so it shouldn't be a first-class
function for general use, polluting the application namespace.
Also remove the FLOCKFILE() code from it - this is under control of the
calling function now.
(XXX I'm not sure whether the FLOCKFILE() should be kept in fgetln(),
this function cannot be used in multiple threads anyway. It doesn't
hurt much, and it might prevent corruption of internal FILE structures.)
 1.17 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.16 18-Jul-2003  nathanw Move guts of flockfile()/funlockfile() to __flockfile_internal(), which
takes an additional argument indicating whether this is an internal caller
taking the lock or an external (application) caller. When making an internal
lock, save the current thread cancellation state and disable cancellation
until the matching unlock. This should prevent canccelled threads from exiting
inside of stdio while holding a file lock and potentially leaving other
parts of the FILE structure in an inconsistent state.
 1.15 07-Mar-2003  tshiozak add fgetws() and fputws() (lib/20576).

Note: fgetws.c, fgetws.3, fputws.c and fputws.3 are obtained from FreeBSD,
and fitted by sigsegv@infoseek.jp and me.
 1.14 01-Feb-2003  nathanw Revert the conversion to libpthread's recursive mutexes. Too much
trouble is caused by the memory allocation in the mutex initialization,
and uncontested mutexes and condition variables have become faster in the
meantime.
 1.13 21-Jan-2003  nathanw Use recursive mutexes from libpthread rather than implementing
our own with normal mutexes and condition variables.
 1.12 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.11 24-May-2002  thorpej * Move the prototype of __svfscanf from <stdio.h> to libc/stdio/local.h.
* Add prototype for vfscanf to <stdio.h>.
* Remove #define of vfscanf to __svfscanf from <stdio.h>.
* Include local.h in libc files which need __svfscanf.
* Add vfscanf weak alias to __svfscanf.

Fixes standards/16997.

NOTE: libc minor not bumped -- ride on the bump to 12.84 made by
itojun today.
 1.10 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.9 27-Jul-1998  mycroft branches: 1.9.12;
Add a mktempdir(), like mkstemp(), but it creates a directory.
 1.8 27-Jul-1998  mycroft If AUDIT, do not compile certain functions.
 1.7 02-Feb-1998  perry merge lite-2
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 04-Jan-1994  cgd rename fgetline()
 1.3 01-Aug-1993  mycroft Add RCS identifiers.
 1.2 07-May-1993  cgd update with new files from Chris Torek
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 02-Feb-1998  perry import lite-2
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9.12.2 21-Jun-2002  nathanw Catch up to -current.
 1.9.12.1 28-Jan-2002  nathanw Catch up to -current.
 1.30.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.30.2.1 17-Apr-2012  yamt sync with head
 1.34.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.34.2.1 23-Jun-2013  tls resync from head
 1.37.2.1 10-Aug-2014  tls Rebase.
 1.19 14-Dec-2018  uwe Fix typo in the function comment.
 1.18 15-Jul-2015  christos branches: 1.18.14; 1.18.16;
Allow changing the default buffering policy for a stdio stream during
construction by setting environment variables.
 1.17 15-Mar-2012  christos branches: 1.17.10;
- ansify, knf.
- no functional changes
 1.16 13-Mar-2012  christos PR/45989: Martin Husemann: lint invocation does include -w only on i386

- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
builds)

approved by core@
 1.15 13-Mar-2008  christos branches: 1.15.6;
Since _file is a short, check that the fd fits in it, otherwise bail with
EMFILE. We treat _file as an unsigned short to double our range, with a
special case for -1 (closed). Make a note of what we should do about stdio
if we ever bump libc. We could change _file in the future compatibly to an
int by putting it in the extension space but for now we don't bother.
 1.14 07-Aug-2003  agc branches: 1.14.22; 1.14.28;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.13 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.12 20-Sep-1999  lukem branches: 1.12.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.11 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.10 15-Nov-1998  christos st_blksize cannot be negative
 1.9 13-Oct-1998  kleink Need an internal name for isatty().
 1.8 03-Feb-1998  perry remove obsolete register declarations
 1.7 19-Oct-1997  mycroft Use S_IS*(), not S_IF*.
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 02-Feb-1995  jtc branches: 1.5.2;
Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.3 01-Aug-1993  mycroft Add RCS identifiers.
 1.2 07-May-1993  cgd update with new files from Chris Torek
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.2.1 02-Mar-1995  jtc #include "namespace.h"
 1.12.10.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.14.28.1 24-Mar-2008  keiichi sync with head.
 1.14.22.1 23-Mar-2008  matt sync with HEAD
 1.15.6.1 17-Apr-2012  yamt sync with head
 1.17.10.1 04-Nov-2015  riz Pull up following revision(s) (requested by christos in ticket #920):
lib/libc/stdio/fopen.3: revision 1.31
lib/libc/stdio/setbuf.3: revision 1.14
lib/libc/stdio/makebuf.c: revision 1.18
Allow changing the default buffering policy for a stdio stream during
construction by setting environment variables.
 1.18.16.1 10-Jun-2019  christos Sync with HEAD
 1.18.14.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.12 18-Jun-2014  christos add mkostemp, mkostemps, mkstemps from FreeBSD.
 1.11 15-Mar-2012  christos branches: 1.11.2; 1.11.8;
- ansify, knf.
- no functional changes
 1.10 20-Oct-2008  apb branches: 1.10.4; 1.10.20;
The tools/compat versions of mkstemp() and mkdtemp() need to call the
internal function that's usually named "__gettemp". However in a cross
build, "__gettemp" is in a namespace reserved for the host system, so we
can't use that. Use "__nbcompat_gettemp" instead, following the example
of several other functions or macros in tools/compat. Previously, this
was handled by using the name "gettemp", but that conflicts with the
local gettemp() function in dist/nawk.
 1.9 27-Oct-2003  lukem Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.7 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.6 14-Sep-2002  thorpej Allow mktemp to be built as a host tool.
 1.5 01-Apr-2002  bjh21 branches: 1.5.2;
Revert addition of mkdtemp() to libnbcompat. I don't think we need mktemp(1)
after all.
 1.4 31-Mar-2002  bjh21 Add mkdtemp to libnbcompat, since glibc doesn't have it an mktemp(1) will
need it.
 1.3 20-Sep-1999  lukem branches: 1.3.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.2 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.1 27-Jul-1998  mycroft Actually, FreeBSD calls this mkdtemp(). No point in creating a new name.
 1.3.10.2 17-Sep-2002  nathanw Catch up to -current.
 1.3.10.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.5.2.1 30-Nov-2002  he Pull up revision 1.6 (requested by thorpej in ticket #806):
Allow mktemp to build as a host tool.
 1.10.20.1 17-Apr-2012  yamt sync with head
 1.10.4.2 20-Oct-2008  apb The tools/compat versions of mkstemp() and mkdtemp() need to call the
internal function that's usually named "__gettemp". However in a cross
build, "__gettemp" is in a namespace reserved for the host system, so we
can't use that. Use "__nbcompat_gettemp" instead, following the example
of several other functions or macros in tools/compat. Previously, this
was handled by using the name "gettemp", but that conflicts with the
local gettemp() function in dist/nawk.
 1.10.4.1 20-Oct-2008  apb file mkdtemp.c was added on branch christos-time_t on 2008-10-20 10:28:39 +0000
 1.11.8.1 10-Aug-2014  tls Rebase.
 1.11.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1 18-Jun-2014  christos branches: 1.1.2; 1.1.6;
add mkostemp, mkostemps, mkstemps from FreeBSD.
 1.1.6.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.6.1 18-Jun-2014  tls file mkostemp.c was added on branch tls-maxphys on 2014-08-20 00:02:16 +0000
 1.1.2.2 10-Aug-2014  tls Rebase.
 1.1.2.1 18-Jun-2014  tls file mkostemp.c was added on branch tls-earlyentropy on 2014-08-10 06:51:51 +0000
 1.1 18-Jun-2014  christos branches: 1.1.2; 1.1.6;
add mkostemp, mkostemps, mkstemps from FreeBSD.
 1.1.6.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.6.1 18-Jun-2014  tls file mkostemps.c was added on branch tls-maxphys on 2014-08-20 00:02:16 +0000
 1.1.2.2 10-Aug-2014  tls Rebase.
 1.1.2.1 18-Jun-2014  tls file mkostemps.c was added on branch tls-earlyentropy on 2014-08-10 06:51:51 +0000
 1.12 18-Jun-2014  christos add mkostemp, mkostemps, mkstemps from FreeBSD.
 1.11 15-Mar-2012  christos branches: 1.11.2; 1.11.8;
- ansify, knf.
- no functional changes
 1.10 20-Oct-2008  apb branches: 1.10.4; 1.10.20;
The tools/compat versions of mkstemp() and mkdtemp() need to call the
internal function that's usually named "__gettemp". However in a cross
build, "__gettemp" is in a namespace reserved for the host system, so we
can't use that. Use "__nbcompat_gettemp" instead, following the example
of several other functions or macros in tools/compat. Previously, this
was handled by using the name "gettemp", but that conflicts with the
local gettemp() function in dist/nawk.
 1.9 09-Feb-2005  kleink A little libc namespace housekeeping exercise:
* Make vfprintf_unlocked() an internal function, c.f. __svfscanf_unlocked().
* Add internal names for arc4random(), endnetpath(), fhstatvfs(),
fstatvfs(), mkstemp(), shquote(), statvfs(), taddr2uaddr(), uaddr2taddr(),
uuid_create_nil(), uuid_is_nil(), and wcwidth().
* Include namespace.h where supposed to.
 1.8 27-Oct-2003  lukem Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.7 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.6 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.5 14-Sep-2002  thorpej Allow mktemp to be built as a host tool.
 1.4 20-Sep-1999  lukem branches: 1.4.10; 1.4.12;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.3 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.2 27-Jul-1998  mycroft Add a mktempdir(), like mkstemp(), but it creates a directory.
 1.1 27-Jul-1998  mycroft If AUDIT, do not compile certain functions.
 1.4.12.1 30-Nov-2002  he Pull up revision 1.5 (requested by thorpej in ticket #806):
Allow mktemp to build as a host tool.
 1.4.10.2 17-Sep-2002  nathanw Catch up to -current.
 1.4.10.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.10.20.1 17-Apr-2012  yamt sync with head
 1.10.4.2 20-Oct-2008  apb The tools/compat versions of mkstemp() and mkdtemp() need to call the
internal function that's usually named "__gettemp". However in a cross
build, "__gettemp" is in a namespace reserved for the host system, so we
can't use that. Use "__nbcompat_gettemp" instead, following the example
of several other functions or macros in tools/compat. Previously, this
was handled by using the name "gettemp", but that conflicts with the
local gettemp() function in dist/nawk.
 1.10.4.1 20-Oct-2008  apb file mkstemp.c was added on branch christos-time_t on 2008-10-20 10:28:39 +0000
 1.11.8.1 10-Aug-2014  tls Rebase.
 1.11.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2 18-Sep-2025  christos Do the nbtool dance.
 1.1 18-Jun-2014  christos branches: 1.1.2; 1.1.6; 1.1.42;
add mkostemp, mkostemps, mkstemps from FreeBSD.
 1.1.42.1 19-Oct-2025  martin Pull up following revision(s) (requested by mrg in ticket #56):

tools/compat/configure.ac: revision 1.111
tools/compat/compat_defs.h: revision 1.126
tools/compat/compat_defs.h: revision 1.127
tools/compat/nbtool_config.h.in: revision 1.60
tools/compat/nbtool_config.h.in: revision 1.61
lib/libc/stdio/mkstemps.c: revision 1.2
tools/compat/configure: revision 1.108
tools/compat/configure: revision 1.109
tools/compat/nbtool_config.h.in: revision 1.59
tools/compat/Makefile: revision 1.95
tools/compat/configure.ac: revision 1.110

Add more functions needed by mandoc

regen

add vsyslog decl check

regen

Do the nbtool dance.
 1.1.6.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.6.1 18-Jun-2014  tls file mkstemps.c was added on branch tls-maxphys on 2014-08-20 00:02:16 +0000
 1.1.2.2 10-Aug-2014  tls Rebase.
 1.1.2.1 18-Jun-2014  tls file mkstemps.c was added on branch tls-earlyentropy on 2014-08-10 06:51:51 +0000
 1.36 06-Aug-2025  kre Include O_CLOFORK in mkostemp()'s allowed flags.
 1.35 02-Nov-2024  nia branches: 1.35.2;
bump date for previous
 1.34 02-Nov-2024  nia libc: Expose mkostemp(3) to POSIX.1-2024 applications.
 1.33 04-May-2024  rillig branches: 1.33.2;
mktemp.3: mkdtemp is no longer nonstandard

Reported by Aleksey Cheusov on tech-userlevel.
 1.32 28-Oct-2021  kim Use .Sq instead of a dangling .So
 1.31 25-Jul-2021  simonb Update to reflect current reality for template characters - the process
ID is not longer used and we replace each "X" with one of 64 values not
26 values.
 1.30 19-Jun-2014  wiz Add all functions to NAME section. End sentences with dots.
Bump date for previous.
 1.29 18-Jun-2014  christos add mkostemp, mkostemps, mkstemps from FreeBSD.
 1.28 14-May-2010  joerg branches: 1.28.12; 1.28.22;
Fix trailing whitespace
 1.27 29-Apr-2010  wiz Improve a sentence.
 1.26 29-Apr-2010  jruoho Add some STANDARDS lingo, mainly to note the functions that have been
removed from POSIX (2008).
 1.25 04-Aug-2006  jld Remove inappropriate comma.
 1.24 15-Oct-2003  wiz Make the plural of `X' `X's instead of `Xs'.
Following a suggestion from jmc@openbsd.
 1.23 14-Oct-2003  christos PR/23158: Johan Danielsson: Portable usage of the mk*temp() functions requires
six `X's.
 1.22 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.21 03-May-2003  wiz Misc. fixes from jmc@openbsd.
 1.20 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.19 16-Feb-2003  wiz Use strlcpy, not strcpy, in one more place. From deraadt.
 1.18 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.17 01-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.16 10-Aug-2002  yamt bring in EXAMPLES and BUGS from openbsd.
 1.15 07-Feb-2002  ross Generate <>& symbolically.
 1.14 22-Jun-2001  aymeric Draw attention to the fact that the created file/dir may not be readable
or writable due to a weird umask.
 1.13 28-Jul-1998  mycroft branches: 1.13.12;
Update the date on this man page.
 1.12 27-Jul-1998  mycroft Document mkdtemp(3).
 1.11 08-Jun-1998  lukem Implement a new manual page category ``SECURITY CONSIDERATIONS''
(suggested by mycroft)
 1.10 01-Jun-1998  kleink Prototypes have moved: change inclusion of <unistd.h> to <stdlib.h>.
 1.9 05-Feb-1998  perry add LIBRARY section to man page
 1.8 14-Nov-1997  mrg add missing .Nm entries. from spz@serpens.swb.de.
 1.7 24-Mar-1997  lukem branches: 1.7.2;
* clarify that tempnam and tmpnam still have problems
* advise mkstemp() over mktemp(), tmpnam(), tempnam(), and indicate
link-time warning if latter 3 are used
* minor cleanups
 1.6 24-Mar-1997  lukem explain why mktemp() should generally be avoided in favour of mkstemp()
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 01-Dec-1993  jtc Manpage formatting tweaks.
 1.3 29-Nov-1993  jtc Use "Er" for argument to -width in the lists in the ERROR sections so that
formatting is consistant.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7.2.1 14-Nov-1997  mrg pull up from trunk: add missing .Nm entries. from spz@serpens.swb.de.
 1.13.12.5 18-Oct-2002  nathanw Catch up to -current.
 1.13.12.4 13-Aug-2002  nathanw Catch up to -current.
 1.13.12.3 22-Mar-2002  nathanw Catch up to -current.
 1.13.12.2 08-Mar-2002  nathanw Catch up to -current.
 1.13.12.1 08-Oct-2001  nathanw Catch up to -current.
 1.28.22.1 10-Aug-2014  tls Rebase.
 1.28.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.33.2.1 02-Aug-2025  perseant Sync with HEAD
 1.35.2.1 08-Aug-2025  martin Pull up following revision(s) (requested by kre in ticket #7):

lib/libc/stdio/mktemp.3: revision 1.36

Include O_CLOFORK in mkostemp()'s allowed flags.
 1.21 18-Jun-2014  christos add mkostemp, mkostemps, mkstemps from FreeBSD.
 1.20 15-Mar-2012  christos branches: 1.20.2; 1.20.8;
- ansify, knf.
- no functional changes
 1.19 07-Aug-2003  agc branches: 1.19.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.18 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.17 20-Sep-1999  lukem branches: 1.17.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.16 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.15 27-Jul-1998  mycroft Mention mkdtemp() in the warnings.
 1.14 27-Jul-1998  mycroft Add a mktempdir(), like mkstemp(), but it creates a directory.
 1.13 27-Jul-1998  mycroft If AUDIT, do not compile certain functions.
 1.12 01-Jun-1998  kleink Need <stdlib.h> for mkstemp() and mktemp() prototypes.
 1.11 03-Feb-1998  perry remove obsolete register declarations
 1.10 04-Nov-1997  thorpej __warn_references and __indr_reference semicolon fixups. From
Chris Demetriou <cgd@pa.dec.com>.
 1.9 13-Jul-1997  christos branches: 1.9.2;
Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.8 07-Jul-1997  phil Modify to have _gettemp generate different names on repeated calls even if the
file was not created. Tempnam modified to make use of full possibilities.
 1.7 08-Apr-1997  lukem use lstat() instead of stat() when checking for existance.
from Keith Bostic <bostic@bostic.com>
 1.6 16-Mar-1997  lukem add warn_refs for mktemp(), tempnam(), and tmpnam() since most code
use these incorrectly. mkstemp() is ok however. inspired by openbsd
 1.5 02-Feb-1995  jtc branches: 1.5.2;
Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 11-Nov-1993  jtc First pass at getting a clean compile with "gcc -Wall", mostly explictly
declaring function return values, etc.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.2.1 02-Mar-1995  jtc #include "namespace.h"
 1.9.2.1 04-Nov-1997  thorpej Pull up from trunk: __warn_references and __indr_reference semicolon fixups.
 1.17.10.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.19.56.1 17-Apr-2012  yamt sync with head
 1.20.8.1 10-Aug-2014  tls Rebase.
 1.20.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2 27-Jul-1998  mycroft Actually, FreeBSD calls this mkdtemp(). No point in creating a new name.
 1.1 27-Jul-1998  mycroft Add a mktempdir(), like mkstemp(), but it creates a directory.
 1.4 12-Dec-2021  andvar fix typos in word "operation(s)".
 1.3 26-Oct-2014  christos PR/49317: Henning Petersen: Fix prototypes inman page.
 1.2 13-Oct-2014  wiz Fix whitespace in Xr. Remove sbuf(3) Xr, we do not have that.
 1.1 13-Oct-2014  christos PR/49279: Justin Cormack: add open_memstream
 1.2 23-Jan-2024  christos handle sizeof(off_t) > sizeof(size_t)
 1.1 13-Oct-2014  christos PR/49279: Justin Cormack: add open_memstream
 1.2 23-Jan-2024  christos handle sizeof(off_t) > sizeof(size_t)
 1.1 13-Oct-2014  christos PR/49279: Justin Cormack: add open_memstream
 1.11 28-Jul-2005  christos PR/30845: Luke Mewburn: strerror_r(3) missing
- Merge 4.4BSD strerror.3 man page changes that summarize information
for all the error printing functions. This makes the perror(3) page
obsolete.
- Implement all error functions in terms of strerror_r(), including
__strerror() which is not used internally. Can it be removed?
- Bump version for strerror_r
 1.10 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.9 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.8 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.7 07-Feb-2002  ross Generate <>& symbolically.
 1.6 22-Mar-1999  garbled branches: 1.6.12;
Last of the .Os cleanups. .Os is defined in the tmac.doc-common file,
so we shouldn't override it with versions in the manpages. Wheee!
 1.5 05-Feb-1998  perry add LIBRARY section to man page
 1.4 03-Jul-1995  jtc Remove trailing comma from cross reference list.
 1.3 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.2 11-Jan-1994  jtc Fix spelling errors.
 1.1 07-Oct-1993  jtc Moved strerror.[c3] from libc/stdio to libc/string.
Since perror is not permitted to change strerror()'s static buffer, I have
changed both functions to pass their own buffers to the new library-internal
function _strerror() that actually does the error message string look up.
Split strerror manpage into strerror and perror manpages.
 1.6.12.2 22-Mar-2002  nathanw Catch up to -current.
 1.6.12.1 08-Mar-2002  nathanw Catch up to -current.
 1.24 26-Jan-2006  kleink Must include "namespace.h" for strerror_r()'s internal name.
 1.23 28-Jul-2005  christos PR/30845: Luke Mewburn: strerror_r(3) missing
- Merge 4.4BSD strerror.3 man page changes that summarize information
for all the error printing functions. This makes the perror(3) page
obsolete.
- Implement all error functions in terms of strerror_r(), including
__strerror() which is not used internally. Can it be removed?
- Bump version for strerror_r
 1.22 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.21 22-Aug-1999  kleink No need for "namespace.h".
 1.20 09-Mar-1999  kleink Functionally back out namespace.h revision 1.7 and perror.c revision 1.15;
perror() is an identifier reserved by ANSI/ISO C, and in case of a redefition
the behavior is undefined.
 1.19 28-Jan-1999  kleink Per ANSI C, place the error message on the stderr stream rather than on
STDERR_FILENO.
 1.18 17-Nov-1998  christos revert previous change; this reveals another bug in lints LINTED option.
 1.17 15-Nov-1998  christos delint
 1.16 09-Sep-1998  kleink Since perror() must be reentrant, change the storage class of the buffer used
to hold the error message from static to automatic.
 1.15 28-Jul-1998  mycroft Add an internal name for perror(3).
 1.14 26-Jul-1998  mycroft Minor nit.
 1.13 26-Jul-1998  mycroft const poisoning.
 1.12 16-Feb-1998  lukem don't assume buf is NL_TEXTMAX long
 1.11 03-Feb-1998  perry remove obsolete register declarations
 1.10 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.9 23-Jan-1997  mrg - convert unsafe strcpy(), strcat() and sprintf() to the `n' versions.
- some KNF.
 1.8 02-Feb-1995  jtc branches: 1.8.2;
Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.7 06-Oct-1994  jtc Change size of array passed to __strerror() from 128 to NL_TEXTMAX.
 1.6 03-Sep-1994  jtc Increased the size of char buffer used by perror(); the error strings may
be much longer in some locales.
 1.5 09-Oct-1993  jtc Helper function _strerror is in the user's namespace, renamed it to
__strerror().
 1.4 07-Oct-1993  jtc Moved strerror.[c3] from libc/stdio to libc/string.
Since perror is not permitted to change strerror()'s static buffer, I have
changed both functions to pass their own buffers to the new library-internal
function _strerror() that actually does the error message string look up.
Split strerror manpage into strerror and perror manpages.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8.2.1 02-Mar-1995  jtc #include "namespace.h"
 1.71 03-Apr-2022  christos Improve wording to avoid confusion about the return value of {v,}asprintf(3)
 1.70 23-Sep-2021  wiz printf(3): mention snprintb(3)
 1.69 16-Feb-2021  riastradh Correct floating-point terminology.

Might want to harmonize the printf(3) and wprintf(3) descriptions of
`%a'.
 1.68 31-Dec-2017  dholland Fix plurals.
 1.67 03-Jul-2017  wiz Remove workaround for ancient HTML generation code.
 1.66 21-Feb-2017  abhinav Insert comma between two Nm entries.
Replace Nm with Fn to refer a function.
 1.65 19-Nov-2015  pgoyette branches: 1.65.2; 1.65.4;
Remove duplicated 'i' from list of numeric formats
 1.64 29-Sep-2014  christos Return EOVERFLOW like FreeBSD does if the buffer size exceeds INT_MAX
(well FreeBSD documents INT_MAX + 1, but in the code it is INT_MAX).
 1.63 04-May-2013  wiz branches: 1.63.6;
Grammar.
 1.62 04-May-2013  christos _ss improvements
 1.61 20-Jan-2013  uwe Mark up occurence of printf() in text with .Fn
 1.60 20-Jan-2013  uwe In newfmt() example one level of indentation is enough.
 1.59 19-Jan-2013  uwe Fix typo.
 1.58 26-Dec-2010  jnemeth branches: 1.58.6; 1.58.8; 1.58.12;
vsnprintf_ss does NOT handle floating point formats
 1.57 22-Dec-2010  wiz Add punctuation.
 1.56 22-Dec-2010  christos document vsnprintf_ss
 1.55 16-Dec-2010  wiz Observe the following spelling:
- wide character (noun)
- wide-character (adjective)

Inspired by jmc@OpenBSD.
 1.54 06-Sep-2010  wiz I assume "POSIX 200805" is IEEE Std 1003.1-2008 (POSIX.1), so use
appropriate .St.
 1.53 06-Sep-2010  christos add dprintf and vdprintf
 1.52 13-May-2010  joerg Use plain references and don't depend on multiple expansion runs.
 1.51 13-May-2010  joerg Mask %U, it is a macro nowadays.
 1.50 21-Mar-2010  jruoho Mention the recommended usage of inttypes(3) when applicable.
 1.49 09-Apr-2009  joerg No .br after .Sh.
 1.48 11-Jan-2009  christos branches: 1.48.2;
merge christos-time_t
 1.47 16-Dec-2008  christos fix return values for snprintf and vsnprintf.
 1.46 11-Dec-2008  wiz Sort sections, sort SEE ALSO, remove trailing whitespace.
 1.45 11-Dec-2008  yamt move a description of return values into the RETURN VALUES section.
 1.44 09-Jun-2007  christos branches: 1.44.20;
bring in many changes from FreeBSD
 1.43 25-Sep-2006  martin As suggested by Johan Veenhuizen in PR 32981, reword slightly to avoid
the impression return values would always be -1.
Approved by christos.
 1.42 19-Mar-2006  wiz Mark up NULL and -.
 1.41 18-Mar-2006  rumble Note that for asprintf and vasprintf it is more portable to check for
a -1 return, rather than ret being set to NULL on error.

From Otto Moerbeek.
 1.40 20-Jul-2005  christos PR/30971: Noriyuki Soda: Fix %ll prints long long, and %q is not portable.
 1.39 21-Jun-2005  christos Document that passing NULL to %s prints "(null)".
 1.38 08-Sep-2003  wiz Use St -isoC-9X instead of St -isoC9X, to be in sync with groff.
 1.37 27-Aug-2003  heas plural "characters" for ret of {v}snprintf
 1.36 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.35 11-May-2003  wiz Drop trailing space.
 1.34 11-May-2003  kleink Oops, typo in previous.
 1.33 11-May-2003  kleink As prompted by Thomas Klausner, add a RETURN VALUES section.
 1.32 03-May-2003  wiz Misc. fixes from jmc@openbsd.
 1.31 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.30 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.29 03-Jan-2003  mjl Fix typos (from PR 19650)
 1.28 11-Nov-2002  simonb Document that the *printf() functions can return a negative value under
output error conditions.
 1.27 01-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.26 10-Jul-2002  yamt import CAVEATS sections from OpenBSD.
with little tweak by me.
 1.25 07-Feb-2002  ross Generate <>& symbolically.
 1.24 21-Jan-2002  kleink One pasto, one typo.
 1.23 02-Dec-2001  kleink Fix a mis-pasting in previous; pointed out by Thomas Klausner.
 1.22 02-Dec-2001  kleink C99:
* Recognize %F.
* Convert {Infinity,NaN} to {"inf","nan"} for %[efg], and to
{"INF","NAN"} for %[EFG].
 1.21 17-Oct-2001  kleink Drop a VAX/Tahoe reference (the VAX case wasn't true with the current compiler
either).
 1.20 16-Sep-2001  wiz Mainly sort SEE ALSO, but also sort sections, and some punctuation and
paragraph fixes.
 1.19 30-Apr-2001  kleink Clarify C standards situation a bit.
 1.18 28-Apr-2001  kleink * Move definitions of exact-width integer types from <machine/types.h>
to <sys/types.h> and <sys/stdint.h>.
* Add a new C99 <stdint.h> header, which provides integer types of
explicit width, related limits and integer constant macros.
* Extend <inttypes.h> to provide <stdint.h> definitions and format
macros for printf() and scanf().
* Add C99 strtoimax() and strtoumax() functions.
* Use the latter within scanf().
* Add C99 %j, %t and %z printf()/scanf() conversions for
intmax_t, pointer-type and size_t arguments.
 1.17 26-Apr-2001  kleink Fix an ... interesting pasto in the description of the l length modifier
that's been here forever.
 1.16 03-Apr-2001  jhawk Xr printf(9)
 1.15 29-Dec-2000  kleink branches: 1.15.2;
Sprinkle some __restrict into stdio.
 1.14 19-Oct-2000  kleink C99: Passing a null pointer as the buffer argument to snprintf() and
vsnprintf() is permitted when the size argument is zero as well; mostly
from Peter Seebach in PR standards/9603.
 1.13 14-Sep-1998  tv branches: 1.13.10;
Document %ll[diouxX] as requested by <bgrayson@ece.utexas.edu> in PR
standards/3527. Also describe the argument to such a format as "quad_t",
not "quad int".
 1.12 29-Aug-1998  lukem first pass at fixing up capitalization of function names and
arguments; ensure that each is correct with respect to the
implementation, rather than being correct as per english.
 1.11 28-Aug-1998  perry document asprintf and vasprintf
 1.10 08-Jun-1998  jeremy Changed HISTORY section to reflect that vsnprintf and snprintf first
appeared in 4.4BSD, rather than ``the current release''.
 1.9 08-Jun-1998  lukem Implement a new manual page category ``SECURITY CONSIDERATIONS''
(suggested by mycroft)
 1.8 28-Apr-1998  fair fix mdoc references and other mistakes
 1.7 05-Feb-1998  perry add LIBRARY section to man page
 1.6 08-Mar-1997  mouse alternate -> alternative, per PR 2643
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 16-May-1994  jtc Fix typo, from Giles Lean (Fixes bug #248)
 1.3 11-Jan-1994  jtc Fix spelling errors.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.13.10.2 01-May-2001  he Pull up revision 1.17 (requested by kleink):
Correct description of the ``l'' length modifier.
 1.13.10.1 19-Oct-2000  he Pull up revision 1.14 (requested by kleink):
C99 alignment: a buffer size of 0 is permitted. Also, when
size is 0, a null buffer pointer may be passed. Fixes PR#9603.
 1.15.2.9 08-Jan-2003  thorpej Sync with HEAD.
 1.15.2.8 11-Nov-2002  nathanw Catch up to -current
 1.15.2.7 18-Oct-2002  nathanw Catch up to -current.
 1.15.2.6 01-Aug-2002  nathanw Catch up to -current.
 1.15.2.5 22-Mar-2002  nathanw Catch up to -current.
 1.15.2.4 08-Mar-2002  nathanw Catch up to -current.
 1.15.2.3 28-Jan-2002  nathanw Catch up to -current.
 1.15.2.2 14-Nov-2001  nathanw Catch up to -current.
 1.15.2.1 08-Oct-2001  nathanw Catch up to -current.
 1.44.20.1 04-Jan-2009  christos merge with head.
 1.48.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.58.12.2 23-Jun-2013  tls resync from head
 1.58.12.1 25-Feb-2013  tls resync with head
 1.58.8.1 03-Nov-2014  msaitoh Pull up following revision(s) (requested by christos in ticket #1161):
lib/libc/stdio/printf.3: revision 1.64 via patch
lib/libc/stdio/vsnprintf.c: revision 1.28 via patch
lib/libc/stdio/vsnprintf_ss.c: revision 1.13 via patch
Return EOVERFLOW like FreeBSD does if the buffer size exceeds INT_MAX
(well FreeBSD documents INT_MAX + 1, but in the code it is INT_MAX).
Return EOVERFLOW like FreeBSD does if the buffer size exceeds INT_MAX
(well FreeBSD documents INT_MAX + 1, but in the code it is INT_MAX).
 1.58.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.58.6.1 23-Jan-2013  yamt sync with head
 1.63.6.1 30-Sep-2014  martin Pull up following revision(s) (requested by christos in ticket #122):
lib/libc/stdio/printf.3: revision 1.64
lib/libc/stdio/vsnprintf.c: revision 1.28
lib/libc/stdio/vsnprintf_ss.c: revision 1.13
Return EOVERFLOW like FreeBSD does if the buffer size exceeds INT_MAX
(well FreeBSD documents INT_MAX + 1, but in the code it is INT_MAX).
 1.65.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.65.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.13 19-Apr-2013  joerg Add explicit locale versions for the printf family. Replace asprintf,
snprintf and sprintf with simple wrappers around the corresponding
va_list functions to reduce code duplication.
 1.12 15-Mar-2012  christos branches: 1.12.2;
- ansify, knf.
- no functional changes
 1.11 07-Aug-2003  agc branches: 1.11.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.10 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.9 26-May-2002  wiz __STDC__ is always defined on NetBSD.
 1.8 20-Sep-1999  lukem branches: 1.8.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.7 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 31-Dec-1993  jtc Add explicit return types to function definitions.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8.10.1 21-Jun-2002  nathanw Catch up to -current.
 1.11.56.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.11.56.1 17-Apr-2012  yamt sync with head
 1.12.2.1 23-Jun-2013  tls resync from head
 1.2 29-Dec-2016  wiz Mention stdarg.h for va_list.
 1.1 29-Dec-2015  christos branches: 1.1.2;
Add printf/scanf man pages from FreeBSD
 1.1.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.15 12-Dec-2024  rillig putc.3: clarify putw, fix commas, brush up markup
 1.14 02-Sep-2019  sevan branches: 1.14.10;
putc & putw were in v1
https://www.bell-labs.com/usr/dmr/www/man31.pdf
putchar was in v4
https://minie.tuhs.org/cgi-bin/utree.pl?file=V4/man/man3/putchr.3
 1.13 22-Feb-2017  abhinav branches: 1.13.12; 1.13.14;
Add reference to flockfile(3) in SEE ALSO section.
 1.12 06-May-2010  jruoho branches: 1.12.28; 1.12.32;
Put the historical note to its own section. Note that also the other
functions (except the _unlocked variants) were in early UNIX versions.
 1.11 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.10 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.9 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.8 01-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.7 07-Feb-2002  ross Generate <>& symbolically.
 1.6 25-Apr-2001  kleink Document getc_unlocked(3), getchar_unlocked(3), putc_unlocked(3) and
putchar_unlocked(3); fixes PR lib/11340.
 1.5 29-Aug-1998  lukem branches: 1.5.12;
first pass at fixing up capitalization of function names and
arguments; ensure that each is correct with respect to the
implementation, rather than being correct as per english.
 1.4 05-Feb-1998  perry add LIBRARY section to man page
 1.3 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.12.4 18-Oct-2002  nathanw Catch up to -current.
 1.5.12.3 22-Mar-2002  nathanw Catch up to -current.
 1.5.12.2 08-Mar-2002  nathanw Catch up to -current.
 1.5.12.1 08-Oct-2001  nathanw Catch up to -current.
 1.12.32.1 21-Apr-2017  bouyer Sync with HEAD
 1.12.28.1 20-Mar-2017  pgoyette Sync with HEAD
 1.13.14.1 05-Sep-2019  martin Pull up following revision(s) (requested by sevan in ticket #174):
lib/libc/sys/chmod.2: revision 1.48
lib/libc/sys/stat.2: revision 1.59
lib/libc/sys/unlink.2: revision 1.30
lib/libc/sys/lseek.2: revision 1.25
lib/libc/sys/getuid.2: revision 1.18
lib/libc/sys/chown.2: revision 1.37
lib/libm/man/exp.3: revision 1.32
lib/libm/man/log.3: revision 1.7
lib/libc/sys/open.2: revision 1.60
lib/libc/stdio/fopen.3: revision 1.36
lib/libc/stdio/putc.3: revision 1.14
lib/libc/sys/mount.2: revision 1.51
share/man/man9/copy.9: revision 1.22
share/man/man9/uiomove.9: revision 1.20
lib/libc/sys/setuid.2: revision 1.23
lib/libc/sys/close.2: revision 1.18
sbin/init/init.8: revision 1.61
lib/libc/sys/write.2: revision 1.36
lib/libc/sys/read.2: revision 1.39
sbin/init/init.8: revision 1.62
lib/libc/sys/wait.2: revision 1.40
usr.bin/tty/tty.1: revision 1.10
lib/libc/sys/link.2: revision 1.33
usr.bin/du/du.1: revision 1.24
lib/libc/stdlib/exit.3: revision 1.17
usr.bin/su/su.1: revision 1.53
usr.bin/mail/mail.1: revision 1.66
lib/libc/sys/fork.2: revision 1.25
usr.bin/su/su.1: revision 1.54
usr.bin/mail/mail.1: revision 1.67
lib/libm/man/sin.3: revision 1.15
share/man/man9/intro.9: revision 1.26
share/man/man5/utmp.5: revision 1.17
lib/libc/compat-43/creat.3: revision 1.17
lib/libc/time/ctime.3: revision 1.61
lib/libcompat/4.1/stty.3: revision 1.10
usr.bin/dc/dc.1: revision 1.3
lib/libm/man/cos.3: revision 1.17
lib/libc/sys/chdir.2: revision 1.23
lib/libc/gen/exec.3: revision 1.30
lib/libc/gen/exec.3: revision 1.31
games/bcd/bcd.6: revision 1.18
games/bcd/bcd.6: revision 1.19
usr.bin/write/write.1: revision 1.7
usr.bin/wc/wc.1: revision 1.18
usr.bin/pr/pr.1: revision 1.24
usr.bin/who/who.1: revision 1.25
lib/libc/sys/mkdir.2: revision 1.30
lib/libc/stdio/getc.3: revision 1.13
usr.bin/sort/sort.1: revision 1.40
usr.bin/mesg/mesg.1: revision 1.11
share/man/man5/passwd.5: revision 1.34
sort was there since v1
https://www.bell-labs.com/usr/dmr/www/man61.pdf

dc was in v1
https://www.bell-labs.com/usr/dmr/www/man12.pdf

du was in v1
https://www.bell-labs.com/usr/dmr/www/man12.pdf

mail was in v1
https://www.bell-labs.com/usr/dmr/www/man12.pdf

mesg was in v1
https://www.bell-labs.com/usr/dmr/www/man12.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man13.pdf

su was in v1
https://www.bell-labs.com/usr/dmr/www/man13.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man13.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man14.pdf
Update URL

write was in v1
https://www.bell-labs.com/usr/dmr/www/man14.pdf
grammar

passwd(5) was in v1
https://www.bell-labs.com/usr/dmr/www/man51.pdf

utmp(5) was present in v1
https://www.bell-labs.com/usr/dmr/www/man51.pdf

Earliest version of wtmp I could find was in v3
https://minnie.tuhs.org/cgi-bin/utree.pl?file=V3/man/man5/wtmp.5

Document history of chdir(2)
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history of chmod(2)
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history of chown(2)
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man21.pdf

create was present in v1
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history of exec()
Move statement on execlpe() & execvpe() to HISTORY section.

Document history
https://www.bell-labs.com/usr/dmr/www/man21.pdf

fork was present in v1
https://www.bell-labs.com/usr/dmr/www/man21.pdf
stat() was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

document history of fstat()
https://www.bell-labs.com/usr/dmr/www/man21.pdf

getuid was present in v1
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man21.pdf

stty & gtty were around since v1
https://www.bell-labs.com/usr/dmr/www/man21.pdf
https://www.bell-labs.com/usr/dmr/www/man22.pdf

mount & umount were present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

Open was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

read was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

seek was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

setuid was in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

unlink was presen in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

wait was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

write was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

start documenting history
exp was present in v1
https://www.bell-labs.com/usr/dmr/www/man31.pdf

Start documenting history
https://www.bell-labs.com/usr/dmr/www/man31.pdf

Start documenting history
https://www.bell-labs.com/usr/dmr/www/man31.pdf

log appeared in v1
https://www.bell-labs.com/usr/dmr/www/man31.pdf

putc & putw were in v1
https://www.bell-labs.com/usr/dmr/www/man31.pdf

putchar was in v4
https://minie.tuhs.org/cgi-bin/utree.pl?file=V4/man/man3/putchr.3

Start documenting history
https://www.bell-labs.com/usr/dmr/www/man31.pdf

Document history.
https://www.bell-labs.com/usr/dmr/www/man11.pdf
Between v1 & v6 UNIX, bcd was rewritten in C, but I don't know if which
version,
hence I've skipped mentioning it.
End sentence with a dot.
Remove superfluous Pp.
Remove superfluous Pp.
Remove superfluous Ns.
Remove superfluous Pp.
fetch(9) -> ufetch(9)
fetch(9) -> ufetch(9). Remove superfluous Pp.
fetch(9) -> ufetch(9). Remove reference to unimplemented ppi(9).
 1.13.12.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.14.10.1 02-Aug-2025  perseant Sync with HEAD
 1.13 04-Feb-2018  mrg fixes for GCC 6:

- -Wstrict-prototypes is not available for C++, so don't try to
ignore it for C++.
- remove many _DIAGASSERT() checks against not NULL for functions
with arguments with nonnull attributes. in two cases, leave
code behind that should set defaults to "(null)".
- use -Wno-error=frame-address for i386 mcount, as it seems valid
to assume the caller will have a frame.fair
 1.12 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.11 07-Aug-2003  agc branches: 1.11.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.10 18-Jul-2003  nathanw #include "local.h" to get __flockfile_internal() prototype.
 1.9 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.8 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.7 19-Jan-1998  jtc Use FLOCKFILE() and FUNLOCKFILE() macros from reentrant.h so that stdio
can be made thread-safe.
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 29-Mar-1996  jtc Add explict function return types
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11.56.1 17-Apr-2012  yamt sync with head
 1.10 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.9 07-Aug-2003  agc branches: 1.9.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.8 18-Jul-2003  nathanw #include "local.h" to get __flockfile_internal() prototype.
 1.7 19-Jan-1998  jtc Use FLOCKFILE() and FUNLOCKFILE() macros from reentrant.h so that stdio
can be made thread-safe.
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 29-Mar-1996  jtc Add explict function return types
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9.56.1 17-Apr-2012  yamt sync with head
 1.17 04-Feb-2018  mrg fixes for GCC 6:

- -Wstrict-prototypes is not available for C++, so don't try to
ignore it for C++.
- remove many _DIAGASSERT() checks against not NULL for functions
with arguments with nonnull attributes. in two cases, leave
code behind that should set defaults to "(null)".
- use -Wno-error=frame-address for i386 mcount, as it seems valid
to assume the caller will have a frame.fair
 1.16 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.15 17-Mar-2006  chris branches: 1.15.44;
Move strlen(s) to after s is known to be not NULL, or set to "(null)" .

Fixes Coverity CID 2353.
 1.14 29-Nov-2005  christos WARNS=4
 1.13 22-Jun-2005  christos If the string to be printed is NULL substitute "(null)". Approved by core.
This is a workaround to make gcc's behavior consistent, since gcc can
transform:
printf("%s\n", s) -> puts(s)
fprintf(fp, "%s", s) -> fputs(s, fp)
as an optimization.
I've left the _DIAGASSERT's that make sure that s != NULL alone because we
should really still abort in a debugging environment.
 1.12 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.11 18-Jul-2003  nathanw #include "local.h" to get __flockfile_internal() prototype.
 1.10 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.9 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.8 15-Nov-1998  christos delint
 1.7 07-Sep-1998  kleink Deploy stdio stream locking as necessary.
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 29-Mar-1996  jtc Add explict function return types
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.15.44.1 17-Apr-2012  yamt sync with head
 1.12 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.11 07-Aug-2003  agc branches: 1.11.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.10 18-Jul-2003  nathanw #include "local.h" to get __flockfile_internal() prototype.
 1.9 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.8 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.7 22-Jan-1998  jtc Use FLOCKFILE() and FUNLOCKFILE() macros from reentrant.h so that stdio
can be made thread-safe.
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 29-Mar-1996  jtc branches: 1.5.2;
Add explict function return types
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.2.1 20-Sep-1996  jtc snapshot namespace cleanup: net, etc.
 1.11.56.1 17-Apr-2012  yamt sync with head
 1.9 16-Dec-2010  wiz Observe the following spelling:
- wide character (noun)
- wide-character (adjective)

Inspired by jmc@OpenBSD.
 1.8 24-Jan-2004  wiz Lots of grammar and wording changes from jmc@openbsd, with some
additional consistency changes by me.
 1.7 08-Sep-2003  wiz Use St -isoC-9X instead of St -isoC9X, to be in sync with groff.
 1.6 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.5 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.4 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.3 01-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.2 07-Feb-2002  ross Generate <>& symbolically.
 1.1 07-Dec-2001  yamt branches: 1.1.2;
- make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.1.2.5 18-Oct-2002  nathanw Catch up to -current.
 1.1.2.4 22-Mar-2002  nathanw Catch up to -current.
 1.1.2.3 08-Mar-2002  nathanw Catch up to -current.
 1.1.2.2 28-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 07-Dec-2001  nathanw file putwc.3 was added on branch nathanw_sa on 2002-01-28 20:51:03 +0000
 1.4 12-Jun-2005  lukem Add missing __RCSID()
 1.3 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.2 14-Mar-2002  yamt putwc and putwchar's argument is wchar_t, not wint_t.
 1.1 07-Dec-2001  yamt branches: 1.1.2;
- make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.1.2.3 22-Mar-2002  nathanw Catch up to -current.
 1.1.2.2 28-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 07-Dec-2001  nathanw file putwc.c was added on branch nathanw_sa on 2002-01-28 20:51:04 +0000
 1.4 12-Jun-2005  lukem Add missing __RCSID()
 1.3 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.2 14-Mar-2002  yamt putwc and putwchar's argument is wchar_t, not wint_t.
 1.1 07-Dec-2001  yamt branches: 1.1.2;
- make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.1.2.3 22-Mar-2002  nathanw Catch up to -current.
 1.1.2.2 28-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 07-Dec-2001  nathanw file putwchar.c was added on branch nathanw_sa on 2002-01-28 20:51:05 +0000
 1.16 27-Mar-2012  christos - widen the internal read and write calls to match the syscalls
- add funopen2() which provides access to flush() and the wider calls.
- make use of the new flush call in fmemopen()
 1.15 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.14 10-Sep-2010  drochner branches: 1.14.6;
apply an 11 years old fix from FreeBSD:
if EBADF is returned due to a read from a write-only stream, also
set ferror()
found by a selftest of Python-2.6.6, thanks to obache for pointing
out the details
 1.13 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.12 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.11 20-Sep-1999  lukem branches: 1.11.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.10 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.9 03-Feb-1998  perry remove obsolete register declarations
 1.8 22-Jan-1998  jtc Use rwlocks as appropriate.
 1.7 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.6 13-Aug-1996  explorer Cute little bug with operator precedence in our stdio code. It appears
that flushing wasn't done right when input buffers were refilled, due
to a check like
if (foo == _A | _B) which, since _A and _B are both != 0, always
evaluates to true.

Found by proven@cygnus.com
 1.5 29-Mar-1996  jtc Add explict function return types
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11.10.2 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.11.10.1 08-Aug-2001  nathanw _REENT -> _REENTRANT
 1.14.6.1 17-Apr-2012  yamt sync with head
 1.12 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.11 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.10 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.9 10-Aug-2002  yamt if the path is directory, remove(3) behaves as rmdir instead of unlink.
from OpenBSD.
 1.8 07-Feb-2002  ross Generate <>& symbolically.
 1.7 16-Sep-2001  wiz Boring whitespace fixes.
 1.6 26-Sep-1999  jdolecek branches: 1.6.8;
xref symlink(7)
 1.5 05-Feb-1998  perry branches: 1.5.4;
add LIBRARY section to man page
 1.4 03-Jun-1997  kleink Add an Xref to rmdir(2).
 1.3 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.6.8.4 13-Aug-2002  nathanw Catch up to -current.
 1.6.8.3 22-Mar-2002  nathanw Catch up to -current.
 1.6.8.2 08-Mar-2002  nathanw Catch up to -current.
 1.6.8.1 08-Oct-2001  nathanw Catch up to -current.
 1.14 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.13 07-Aug-2003  agc branches: 1.13.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.12 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.11 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.10 07-Sep-1998  kleink Minor KNF nit.
 1.9 07-Oct-1997  hubertf Partly backing out last change, only leaving lstat() instead of stat().
Pointed out by Enami Tsugutomo <enami@but-b.or.jp>.
 1.8 06-Oct-1997  hubertf remove(3) doesn't remove dangling links due to stat() returning an
error. Now try lstat() before really aborting.
OK'd by thorpej.
 1.7 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.6 03-Jun-1997  kleink Always use rmdir(2) to remove a directory, as the file system may prohibit
using unlink(2) on directories.
 1.5 29-Mar-1996  jtc Add explict function return types
 1.4 02-Feb-1995  jtc branches: 1.4.2;
Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.2.1 02-Mar-1995  jtc #include "namespace.h"
 1.13.56.1 17-Apr-2012  yamt sync with head
 1.14 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.13 07-Aug-2003  agc branches: 1.13.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.12 18-Jul-2003  nathanw #include "local.h" to get __flockfile_internal() prototype.
 1.11 21-Jan-2000  mycroft Call __sclearerr(), nor clearerr(), so we don\`t try to double lock.
 1.10 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.9 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.8 18-Nov-1998  kleink Oops, don't need <errno.h> any more.
 1.7 18-Nov-1998  kleink * Wrap file locking around the function body in order to have fseek() and
clearerr() executed as a single unit.
* Remove clearing of errno; this fseek() error indicator must be visible to
the caller.
 1.6 03-Feb-1998  perry remove obsolete register declarations
 1.5 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.13.56.1 17-Apr-2012  yamt sync with head
 1.13 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.12 07-Aug-2003  agc branches: 1.12.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.11 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.10 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.9 20-Sep-1999  lukem branches: 1.9.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.8 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.7 03-Feb-1998  perry remove obsolete register declarations
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 29-Mar-1996  jtc Add explict function return types
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9.10.2 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.9.10.1 28-Jan-2002  nathanw Catch up to -current.
 1.12.56.1 17-Apr-2012  yamt sync with head
 1.27 14-May-2010  joerg Fix markup
 1.26 22-Mar-2010  jruoho Break the (too) big lead paragraph into three smaller ones.
 1.25 21-Mar-2010  jruoho Bump date for previous.
 1.24 21-Mar-2010  jruoho Note inttypes(3) also here.
 1.23 14-Dec-2009  wiz Whitespace nit.
 1.22 14-Dec-2009  dholland whoops, bump date for previous.
 1.21 14-Dec-2009  dholland Document %ll. Closes PR 42283.
 1.20 30-May-2008  gdt branches: 1.20.6;
Document the C99-required and already implemented hh modifier (pointer
is to a char, vs. h for short). Bump date.
 1.19 08-Sep-2003  wiz branches: 1.19.30; 1.19.32;
Use St -isoC-9X instead of St -isoC9X, to be in sync with groff.
 1.18 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.17 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.16 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.15 01-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.14 07-Feb-2002  ross Generate <>& symbolically.
 1.13 16-Sep-2001  wiz Mainly sort SEE ALSO, but also sort sections, and some punctuation and
paragraph fixes.
 1.12 30-Apr-2001  kleink Clarify C standards situation a bit.
 1.11 28-Apr-2001  kleink * Move definitions of exact-width integer types from <machine/types.h>
to <sys/types.h> and <sys/stdint.h>.
* Add a new C99 <stdint.h> header, which provides integer types of
explicit width, related limits and integer constant macros.
* Extend <inttypes.h> to provide <stdint.h> definitions and format
macros for printf() and scanf().
* Add C99 strtoimax() and strtoumax() functions.
* Use the latter within scanf().
* Add C99 %j, %t and %z printf()/scanf() conversions for
intmax_t, pointer-type and size_t arguments.
 1.10 29-Dec-2000  kleink branches: 1.10.2;
Sprinkle some __restrict into stdio.
 1.9 16-Jul-2000  jdolecek v*scanf() are hardly 'new to this release' when they have
been around since 386BSD-0.1 import; they have been present in 4.4BSD-Lite
at least, can't currently check if even in 4.3BSD
put note aboud eventual removing of compatibility formats to NOTES, it's
hardly a bug description
 1.8 05-Feb-1998  perry branches: 1.8.10;
add LIBRARY section to man page
 1.7 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.6 30-Jan-1995  jtc Handle long doubles.

Like Plauger's implementation in "The Standard C Library", we use strtod(),
which will limit the range of values that can be converter properly if
long double has greater precision or range than double.

We will need a string to long double function to handle this properly, but
this change is better than the previous behavior of ignoring the existance
of long doubles.
 1.5 27-Jan-1995  jtc Added support for quad_t and u_quad_t's with the 'q' flag.
 1.4 26-Jan-1995  jtc Removed conflicting "backwards compatibility" code to make scanf
ANSI compliant.
 1.3 01-Aug-1993  mycroft Add RCS indentifiers.
 1.2 09-Jul-1993  cgd update for better FP routines, from AT&T & elsewhere
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8.10.1 16-Jul-2000  jdolecek pullup rev. 1.9 from trunk (approved by thorpej):
correct obsolete comment about v*scanf() being 'new to this release' - that
comment was there since 386BSD-0.1 import, the functions got added in 4.4BSD
or even 4.3BSD

move note about eventual removing of compatibility formats to separate
NOTES, it can hardly be considered a bug :)
 1.10.2.4 18-Oct-2002  nathanw Catch up to -current.
 1.10.2.3 22-Mar-2002  nathanw Catch up to -current.
 1.10.2.2 08-Mar-2002  nathanw Catch up to -current.
 1.10.2.1 08-Oct-2001  nathanw Catch up to -current.
 1.19.32.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.19.30.1 04-Jun-2008  yamt sync with head
 1.20.6.2 30-May-2008  gdt Document the C99-required and already implemented hh modifier (pointer
is to a char, vs. h for short). Bump date.
 1.20.6.1 30-May-2008  gdt file scanf.3 was added on branch christos-time_t on 2008-05-30 17:29:55 +0000
 1.15 04-Feb-2018  mrg fixes for GCC 6:

- -Wstrict-prototypes is not available for C++, so don't try to
ignore it for C++.
- remove many _DIAGASSERT() checks against not NULL for functions
with arguments with nonnull attributes. in two cases, leave
code behind that should set defaults to "(null)".
- use -Wno-error=frame-address for i386 mcount, as it seems valid
to assume the caller will have a frame.fair
 1.14 19-Apr-2013  joerg Add scanf_l and wscanf_l families.
 1.13 15-Mar-2012  christos branches: 1.13.2;
- ansify, knf.
- no functional changes
 1.12 07-Aug-2003  agc branches: 1.12.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.11 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.10 26-May-2002  wiz __STDC__ is always defined on NetBSD.
 1.9 24-May-2002  thorpej * Move the prototype of __svfscanf from <stdio.h> to libc/stdio/local.h.
* Add prototype for vfscanf to <stdio.h>.
* Remove #define of vfscanf to __svfscanf from <stdio.h>.
* Include local.h in libc files which need __svfscanf.
* Add vfscanf weak alias to __svfscanf.

Fixes standards/16997.

NOTE: libc minor not bumped -- ride on the bump to 12.84 made by
itojun today.
 1.8 20-Sep-1999  lukem branches: 1.8.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.7 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 29-Mar-1996  jtc Add explict function return types
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8.10.2 22-Jun-2002  thorpej Need "reentrant.h"
 1.8.10.1 21-Jun-2002  nathanw Catch up to -current.
 1.12.56.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.12.56.1 17-Apr-2012  yamt sync with head
 1.13.2.1 23-Jun-2013  tls resync from head
 1.1 29-Dec-2015  christos Add printf/scanf man pages from FreeBSD
 1.20 14-Dec-2018  uwe Don't leave a subordinate clause out in the cold.
 1.19 20-Feb-2018  uwe branches: 1.19.2; 1.19.4;
Markup "stdin".
 1.18 20-Feb-2018  uwe Make the list of STDBUF values and the list of mode values congruent
in formatting and spelling.
 1.17 20-Feb-2018  uwe Use semantic markup.
 1.16 20-Feb-2018  wiz Remove ineffective macros and arguments.
 1.15 20-Feb-2018  kamil Improve the setbuf(3) man-page

Move historical lines to newly added HISTORY section.
Additional historical notes obtained from OpenBSD.
 1.14 15-Jul-2015  christos Allow changing the default buffering policy for a stdio stream during
construction by setting environment variables.
 1.13 07-Aug-2003  agc branches: 1.13.76;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.12 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.11 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.10 07-Feb-2002  ross Generate <>& symbolically.
 1.9 16-Sep-2001  wiz Mainly sort SEE ALSO, but also sort sections, and some punctuation and
paragraph fixes.
 1.8 16-Sep-2001  wiz Boring whitespace fixes.
 1.7 29-Dec-2000  kleink branches: 1.7.2;
Sprinkle some __restrict into stdio.
 1.6 22-Mar-1999  garbled Last of the .Os cleanups. .Os is defined in the tmac.doc-common file,
so we shouldn't override it with versions in the manpages. Wheee!
 1.5 28-Jan-1999  kleink stderr is not always but initially unbuffered.
 1.4 05-Feb-1998  perry add LIBRARY section to man page
 1.3 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7.2.3 22-Mar-2002  nathanw Catch up to -current.
 1.7.2.2 08-Mar-2002  nathanw Catch up to -current.
 1.7.2.1 08-Oct-2001  nathanw Catch up to -current.
 1.13.76.1 04-Nov-2015  riz Pull up following revision(s) (requested by christos in ticket #920):
lib/libc/stdio/fopen.3: revision 1.31
lib/libc/stdio/setbuf.3: revision 1.14
lib/libc/stdio/makebuf.c: revision 1.18
Allow changing the default buffering policy for a stdio stream during
construction by setting environment variables.
 1.19.4.1 10-Jun-2019  christos Sync with HEAD
 1.19.2.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.10 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.9 07-Aug-2003  agc branches: 1.9.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.8 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.7 20-Sep-1999  lukem branches: 1.7.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.6 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.5 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7.10.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.9.56.1 17-Apr-2012  yamt sync with head
 1.13 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.12 25-Oct-2009  christos branches: 1.12.6;
revert some of dsl's changes to make things build on i386; he can undo what
he wants when he comes back.
 1.11 24-Oct-2009  dsl Remove a load of pointless casts - one that even lint doesn't bleat about.
 1.10 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.9 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.8 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.7 15-Nov-1998  christos delint
 1.6 03-Feb-1998  perry remove obsolete register declarations
 1.5 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.4 02-Feb-1995  jtc branches: 1.4.6;
Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.6.1 20-Sep-1996  jtc snapshot namespace cleanup: net, etc.
 1.12.6.1 17-Apr-2012  yamt sync with head
 1.19 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.18 13-Mar-2012  christos PR/45989: Martin Husemann: lint invocation does include -w only on i386

- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
builds)

approved by core@
 1.17 07-Aug-2003  agc branches: 1.17.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.16 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.15 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.14 20-Sep-1999  lukem branches: 1.14.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.13 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.12 03-Feb-1998  perry remove obsolete register declarations
 1.11 22-Jan-1998  jtc Use FLOCKFILE() and FUNLOCKFILE() macros from reentrant.h so that stdio
can be made thread-safe.
 1.10 19-Dec-1997  kleink Change several functions to return -1 instead of EOF, which was semantically
wrong.
 1.9 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.8 29-Mar-1996  jtc Add explict function return types
 1.7 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.6 17-Nov-1993  cgd yet another setvbuf fix from torek...
 1.5 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 24-May-1993  cgd apply fix to setvbuf(), supplied by chris torek
 1.2 07-May-1993  cgd update with new files from Chris Torek
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.14.10.2 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.14.10.1 28-Jan-2002  nathanw Catch up to -current.
 1.17.56.1 17-Apr-2012  yamt sync with head
 1.25 19-Apr-2013  joerg Add explicit locale versions for the printf family. Replace asprintf,
snprintf and sprintf with simple wrappers around the corresponding
va_list functions to reduce code duplication.
 1.24 15-Mar-2012  christos branches: 1.24.2;
- ansify, knf.
- no functional changes
 1.23 13-Mar-2012  christos PR/45989: Martin Husemann: lint invocation does include -w only on i386

- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
builds)

approved by core@
 1.22 26-Oct-2007  christos branches: 1.22.30;
make _FORTIFY_SOURCE play nicely with lint
 1.21 03-Jun-2007  christos branches: 1.21.4;
Make these work with _FORTIFY_SOURCE, by overriding the fortified definitions
 1.20 09-Feb-2005  kleink A little libc namespace housekeeping exercise:
* Make vfprintf_unlocked() an internal function, c.f. __svfscanf_unlocked().
* Add internal names for arc4random(), endnetpath(), fhstatvfs(),
fstatvfs(), mkstemp(), shquote(), statvfs(), taddr2uaddr(), uaddr2taddr(),
uuid_create_nil(), uuid_is_nil(), and wcwidth().
* Include namespace.h where supposed to.
 1.19 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.18 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.17 05-Jan-2003  kristerw Fix two bugs:

1. snprintf(foo, 0. "XXX") is guaranteed not to write in foo by the
standard (ISO/IEC 9899 7.19.6.5) but our implementation handles this
as if the buffer has a size of (size_t)-1.

2. snprintf(NULL, 0, "XXX") leaks memory since cantwrite() allocates
memory if _bf._base == NULL, and this buffer is never freed
(PR 16483).
 1.16 26-May-2002  wiz __STDC__ is always defined on NetBSD.
 1.15 07-Dec-2001  yamt branches: 1.15.2;
- make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.14 19-Oct-2000  kleink branches: 1.14.2;
Actually EINVAL fits the circumstances better.
 1.13 19-Oct-2000  kleink C99: Passing a null pointer as the buffer argument to snprintf() and
vsnprintf() is permitted when the size argument is zero as well; mostly
from Peter Seebach in PR standards/9603.
 1.12 22-Jan-2000  mycroft branches: 1.12.4;
Delint.
Remove trailing ; from uses of __weak_alias(). The macro inserts this if
needed.
 1.11 21-Jan-2000  mycroft Initialize f._file for locking primitives.
 1.10 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.9 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.8 13-Oct-1998  kleink Need internal names for snprintf() and vsnprintf().
 1.7 19-Dec-1997  kleink Change several functions to return -1 instead of EOF, which was semantically
wrong.
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 29-Mar-1996  jtc Add explict function return types
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.12.4.1 19-Oct-2000  he Pull up revisions 1.13-1.14 (requested by kleink):
C99 alignment: a buffer size of 0 is permitted. Also, when
size is 0, a null buffer pointer may be passed. Fixes PR#9603.
 1.14.2.5 08-Jan-2003  thorpej Sync with HEAD.
 1.14.2.4 21-Jun-2002  nathanw Catch up to -current.
 1.14.2.3 02-May-2002  nathanw Call the _unlocked versions of vfprintf() and __svfscanf(); there's no point
in locking and unlocking a FILE object that only exists in the local scope.
This also has the nice side effect of making sprintf() usable for debugging
threaded code.
 1.14.2.2 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.14.2.1 28-Jan-2002  nathanw Catch up to -current.
 1.15.2.1 10-Jan-2003  jmc Pull up revisions 1.16-1.17 (requested by kristerw in ticket #1059)
Fix two bugs:
1. snprintf(foo, 0. XXX) is guaranteed not to write in foo by the
standard (ISO/IEC 9899 7.19.6.5) but our implementation handles this
as if the buffer has a size of (size_t)-1.
2. snprintf(NULL, 0, XXX) leaks memory since cantwrite() allocates
memory if _bf._base == NULL, and this buffer is never freed
(PR 16483).
 1.21.4.1 06-Nov-2007  matt sync with HEAD
 1.22.30.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.22.30.1 17-Apr-2012  yamt sync with head
 1.24.2.1 23-Jun-2013  tls resync from head
 1.4 02-Feb-2007  christos Instead of abusing stdio to get a signal-safe version of sprintf, provide one.
 1.3 22-Nov-2006  christos branches: 1.3.2;
Don't expose _ss functions for 4.0. Requested by core.
 1.2 29-Oct-2006  christos fix name in weak alias.
 1.1 27-Oct-2006  christos Add signal-safe versions of snprintf and vsnprintf
 1.3.2.1 07-May-2007  pavel Pull up following revision(s) (requested by manu in ticket #607):
lib/libc/arch/i386/gen/isnanl.c: revision 1.6
lib/libc/gdtoa/gdtoa.c: revision 1.2-1.3
lib/libc/arch/x86_64/gen/isnanl.c: revision 1.6
lib/libc/gdtoa/gdtoaimp.h: revision 1.6
sys/arch/m68k/include/ieee.h: revision 1.13
usr.bin/xlint/lint1/scan.l: revision 1.36-1.37
lib/libc/stdio/snprintf_ss.c: revision 1.4
lib/libc/arch/i386/gen/isfinitel.c: revision 1.2
lib/libc/stdio/vfscanf.c: revision 1.38
sys/arch/sparc/include/ieee.h: revision 1.11-1.12
lib/libc/gdtoa/dtoa.c: revision 1.4
lib/libc/stdio/Makefile.inc: revision 1.35
lib/libc/stdio/fvwrite.c: revision 1.17
lib/libc/arch/m68k/gen/fpclassifyl.c: revision 1.2
lib/libc/arch/i386/gen/isinfl.c: revision 1.6
lib/libc/arch/x86_64/gen/isinfl.c: revision 1.6
lib/libc/arch/x86_64/gen/isfinitel.c: revision 1.2
lib/libc/stdio/vfprintf.c: revision 1.55-1.57
lib/libc/stdio/vsnprintf_ss.c: revision 1.3
lib/libc/stdio/vfwprintf.c: revision 1.10
sys/arch/x86/include/ieee.h: revision 1.10
lib/libc/gdtoa/dmisc.c: revision 1.3
lib/libc/gdtoa/Makefile.inc: revision 1.5
sys/arch/hppa/include/ieee.h: revision 1.10
lib/libc/arch/x86_64/gen/fpclassifyl.c: revision 1.3
lib/libc/arch/i386/gen/fpclassifyl.c: revision 1.2
sys/sys/ieee754.h: revision 1.7
lib/libc/gdtoa/gdtoa.h: revision 1.7
include/stdio.h: revision 1.67-1.68
lib/libc/gdtoa/hdtoa.c: revision 1.1-1.4
lib/libc/gdtoa/ldtoa.c: revision 1.1-1.4
defined(_NETBSD_SOURCE) is equivalent to (!defined(_ANSI_SOURCE) &&
!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)), so there's no
need to check both of them.
Fix for issue reported in PR lib/35401 as well as related overflow bugs.
deal with hex doubles.
Instead of abusing stdio to get a signal-safe version of sprintf, provide one.
remove __SAFE
add long double and hex double support from freebsd.
make this compile.
add new prototypes.
add the new files to the build. Note I am not bumping libc now, because
these are not used yet.
Merge the int bit with the high fraction bit. Add constants/macros
needed by gdtoa.
add constants used by gdtoa
since the int bit is merged, do the explicit math.
ext_int bit is no more.
ext_int bit is no more.
- merge change from freebsd
- add support for building as vfprintf.c
- XXX: we strdup to simplify the freeing logic. This should be fixed for
efficiency in the vfprintf case.
use vfwprintf.c
enable wide doubles.
some int -> size_t
deal with sparc64 that has 112 bits of mantissa.
make extended precision gdtoa friendly.
int/size_t changes
make this gdtoa friendly.
remove dup definition
use dtoa() instead of returning empty when we don't have extended precision
information.
Fix previous, add forgotten pointer dereference in the call to dtoa().
Add a cheesy workaround marked XXX for the situation where the
strtod() implementation available in the environment does not
handle hex floats.
Discussed with and suggested by christos
From Christos: gdtoa fixes for m68k. M68k ports should build now, but
printing extended precision is a little off.
vax does not have <machine/ieee.h> or long double
It would be nice if the compiler provided something like __IEEE_MATH__
bring in FreeBSD's vfscanf() to gain multi-byte/collation support.
Unfortunately it is too difficult to make vfwscanf and this share
the same code like I did with printf, because for string parsing
the code is too different.
 1.17 19-Apr-2013  joerg Add explicit locale versions for the printf family. Replace asprintf,
snprintf and sprintf with simple wrappers around the corresponding
va_list functions to reduce code duplication.
 1.16 15-Mar-2012  christos branches: 1.16.2;
- ansify, knf.
- no functional changes
 1.15 03-Jun-2007  christos branches: 1.15.36;
Make these work with _FORTIFY_SOURCE, by overriding the fortified definitions
 1.14 09-Feb-2005  kleink A little libc namespace housekeeping exercise:
* Make vfprintf_unlocked() an internal function, c.f. __svfscanf_unlocked().
* Add internal names for arc4random(), endnetpath(), fhstatvfs(),
fstatvfs(), mkstemp(), shquote(), statvfs(), taddr2uaddr(), uaddr2taddr(),
uuid_create_nil(), uuid_is_nil(), and wcwidth().
* Include namespace.h where supposed to.
 1.13 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.12 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.11 26-May-2002  wiz __STDC__ is always defined on NetBSD.
 1.10 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.9 21-Jan-2000  mycroft branches: 1.9.6;
Initialize f._file for locking primitives.
 1.8 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.7 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 31-Dec-1993  jtc Add explicit return types to function definitions.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9.6.4 21-Jun-2002  nathanw Catch up to -current.
 1.9.6.3 02-May-2002  nathanw Call the _unlocked versions of vfprintf() and __svfscanf(); there's no point
in locking and unlocking a FILE object that only exists in the local scope.
This also has the nice side effect of making sprintf() usable for debugging
threaded code.
 1.9.6.2 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.9.6.1 28-Jan-2002  nathanw Catch up to -current.
 1.15.36.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.15.36.1 17-Apr-2012  yamt sync with head
 1.16.2.1 23-Jun-2013  tls resync from head
 1.22 04-Feb-2018  mrg fixes for GCC 6:

- -Wstrict-prototypes is not available for C++, so don't try to
ignore it for C++.
- remove many _DIAGASSERT() checks against not NULL for functions
with arguments with nonnull attributes. in two cases, leave
code behind that should set defaults to "(null)".
- use -Wno-error=frame-address for i386 mcount, as it seems valid
to assume the caller will have a frame.fair
 1.21 19-Apr-2013  joerg Add scanf_l and wscanf_l families.
 1.20 27-Mar-2012  christos branches: 1.20.2;
- widen the internal read and write calls to match the syscalls
- add funopen2() which provides access to flush() and the wider calls.
- make use of the new flush call in fmemopen()
 1.19 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.18 13-Mar-2012  christos PR/45989: Martin Husemann: lint invocation does include -w only on i386

- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
builds)

approved by core@
 1.17 11-Jan-2010  joerg branches: 1.17.6;
Use a proper char */size_t pair in __sfileext to keep track of the line
buffer for fgetln and fgetwln. Simplifies code by dropping the INT_MAX
related logic. Drop conditionals around FREELB, free(NULL) is valid.
 1.16 29-Nov-2005  christos WARNS=4
 1.15 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.14 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.13 26-May-2002  wiz __STDC__ is always defined on NetBSD.
 1.12 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.11 20-Sep-1999  lukem branches: 1.11.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.10 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.9 15-Nov-1998  christos delint
 1.8 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.7 29-Mar-1996  jtc Add explict function return types
 1.6 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.5 05-Oct-1993  jtc Fix typo from last change.
 1.4 05-Oct-1993  cgd make the first param const char *, so it compiles...
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11.10.6 21-Jun-2002  nathanw Catch up to -current.
 1.11.10.5 02-May-2002  nathanw Call the _unlocked versions of vfprintf() and __svfscanf(); there's no point
in locking and unlocking a FILE object that only exists in the local scope.
This also has the nice side effect of making sprintf() usable for debugging
threaded code.
 1.11.10.4 07-Feb-2002  nathanw Revert previous; this will be done a different way.
 1.11.10.3 07-Feb-2002  nathanw sscanf() and vsscanf() construct private FILE structures; be sure to
initialize the flockfile() locks there, too.
 1.11.10.2 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.11.10.1 28-Jan-2002  nathanw Catch up to -current.
 1.17.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.17.6.1 17-Apr-2012  yamt sync with head
 1.20.2.1 23-Jun-2013  tls resync from head
 1.28 29-Aug-2020  rillig stdio(3): fix typos in the manual page

fputc cannot read characters, it can only write them.
 1.27 22-Feb-2018  pgoyette Remove extra "an"

Thanks to J. Lewis Muir
 1.26 06-Sep-2015  mrg add a bunch of functions found in <stdio.h> that weren't listed here.
(this list may still be incomplete.)
 1.25 06-Sep-2015  dholland Mention fmemopen().
 1.24 05-May-2010  jruoho Upon lukem@'s request, put the list of functions back.

XXX: Someone needs to go through all standard I/O functions in the libc,
update the list, and keep it updated. While at it, please convert the
list to use .Xr so that we can have links in HTML pages.
 1.23 04-May-2010  jruoho Remove the list of functions.

This list was updated only two times in nearly two decades.

(If people need to learn the standard I/O functions in C, it would be better
to mention K&R or some other textbook; if people need to know the list of
functions, it would be better to point out the location of the standard.)

In addition, some clean-up and structural editing.
 1.22 13-Jul-2009  wiz Fix typo added in previous.
 1.21 13-Jul-2009  roy Add implementations for getdelim(3) and getline(3).
 1.20 15-Mar-2009  joerg Fix markup.
 1.19 07-Aug-2003  agc branches: 1.19.42;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.18 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.17 28-Jan-2003  kleink Add a manual page for flockfile(3) etc.; while here, also add *_unlocked()
to stdio(3) overview documentation. Fixes PR lib/20096 from Jason Thorpe.
 1.16 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.15 01-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.14 07-Feb-2002  ross Generate <>& symbolically.
 1.13 07-Dec-2001  wiz Slight grammar improvement.
 1.12 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.11 16-Sep-2001  wiz Mainly sort SEE ALSO, but also sort sections, and some punctuation and
paragraph fixes.
 1.10 16-Sep-2001  wiz Boring whitespace fixes.
 1.9 06-Jul-2001  abs Do not xref pc(1)
 1.8 22-Mar-1999  garbled branches: 1.8.12;
Last of the .Os cleanups. .Os is defined in the tmac.doc-common file,
so we shouldn't override it with versions in the manpages. Wheee!
 1.7 28-Apr-1998  fair fix mdoc references and other mistakes
 1.6 05-Feb-1998  perry add LIBRARY section to man page
 1.5 05-May-1996  pk typo: DV -> Dv
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 11-Jan-1994  jtc Fix spelling errors.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8.12.5 18-Oct-2002  nathanw Catch up to -current.
 1.8.12.4 22-Mar-2002  nathanw Catch up to -current.
 1.8.12.3 08-Mar-2002  nathanw Catch up to -current.
 1.8.12.2 28-Jan-2002  nathanw Catch up to -current.
 1.8.12.1 08-Oct-2001  nathanw Catch up to -current.
 1.19.42.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.22 19-May-2013  christos from kre: Don't fail if we are seeking on a pipe, clear the append bit
since we always append.
 1.21 27-Mar-2012  christos branches: 1.21.2;
- widen the internal read and write calls to match the syscalls
- add funopen2() which provides access to flush() and the wider calls.
- make use of the new flush call in fmemopen()
 1.20 20-Mar-2012  christos ansi prototype
 1.19 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.18 13-Mar-2012  christos PR/45989: Martin Husemann: lint invocation does include -w only on i386

- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
builds)

approved by core@
 1.17 22-Jan-2012  christos From tnozaki@: make fpos_t a complex object that keeps track of the parse
state of the stream. Change argument of the seek function to funopen() from
fpos_t to off_t. Make f{g,s}etpos() use the new fpos_t struct, while providing
backwards compatible entry points. Approved by releng@
 1.16 25-Oct-2009  christos branches: 1.16.6;
revert some of dsl's changes to make things build on i386; he can undo what
he wants when he comes back.
 1.15 24-Oct-2009  dsl Remove a load of pointless casts - one that even lint doesn't bleat about.
 1.14 13-Mar-2008  christos Since _file is a short, check that the fd fits in it, otherwise bail with
EMFILE. We treat _file as an unsigned short to double our range, with a
special case for -1 (closed). Make a note of what we should do about stdio
if we ever bump libc. We could change _file in the future compatibly to an
int by putting it in the extension space but for now we don't bother.
 1.13 07-Aug-2003  agc branches: 1.13.22; 1.13.28;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.12 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.11 20-Sep-1999  lukem branches: 1.11.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.10 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.9 15-Nov-1998  christos delint
 1.8 14-Oct-1998  kleink Need "namespace.h".
 1.7 03-Feb-1998  perry remove obsolete register declarations
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 29-Mar-1996  jtc Add explict function return types
 1.4 02-Feb-1995  jtc branches: 1.4.2;
Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.2.1 02-Mar-1995  jtc #include "namespace.h"
 1.11.10.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.13.28.1 24-Mar-2008  keiichi sync with head.
 1.13.22.1 23-Mar-2008  matt sync with HEAD
 1.16.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.16.6.1 17-Apr-2012  yamt sync with head
 1.21.2.1 23-Jun-2013  tls resync from head
 1.4 07-Oct-1993  mycroft Clean up deleted files.
 1.3 05-Oct-1993  jtc Changed SYNOPSIS, #include <string.h> before using strerror().
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4 07-Oct-1993  mycroft Clean up deleted files.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.3 19-Apr-2013  joerg Add explicit locale versions for the printf family. Replace asprintf,
snprintf and sprintf with simple wrappers around the corresponding
va_list functions to reduce code duplication.
 1.2 15-Mar-2012  christos branches: 1.2.2;
- ansify, knf.
- no functional changes
 1.1 14-May-2005  christos branches: 1.1.44;
Add the missing wide char support functions from freebsd.
XXX: long double support is missing until we get gdtoa, and add the
necessary wide functions.
 1.1.44.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.44.1 17-Apr-2012  yamt sync with head
 1.2.2.1 23-Jun-2013  tls resync from head
 1.3 19-Apr-2013  joerg Add scanf_l and wscanf_l families.
 1.2 15-Mar-2012  christos branches: 1.2.2;
- ansify, knf.
- no functional changes
 1.1 14-May-2005  christos branches: 1.1.44;
Add the missing wide char support functions from freebsd.
XXX: long double support is missing until we get gdtoa, and add the
necessary wide functions.
 1.1.44.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.44.1 17-Apr-2012  yamt sync with head
 1.2.2.1 23-Jun-2013  tls resync from head
 1.22 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.21 25-Oct-2009  christos branches: 1.21.6;
revert some of dsl's changes to make things build on i386; he can undo what
he wants when he comes back.
 1.20 24-Oct-2009  dsl Remove a load of pointless casts - one that even lint doesn't bleat about.
 1.19 27-Jul-2005  drochner get the trailing-slash logics right
 1.18 26-Jul-2005  christos PR/30839: Tomas Sk�re: Buffer underflow in lib/libc/stdio/tempnam.c
when *dir == "".
 1.17 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.16 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.15 10-Aug-2002  yamt use more Xs for filename templates.
from OpenBSD.
 1.14 21-Jun-2001  christos casts to size_t
 1.13 15-Nov-1998  christos branches: 1.13.12;
delint
 1.12 13-Oct-1998  kleink Need internal names for snprintf() and vsnprintf().
 1.11 27-Jul-1998  mycroft Mention mkdtemp() in the warnings.
 1.10 04-Nov-1997  thorpej __warn_references and __indr_reference semicolon fixups. From
Chris Demetriou <cgd@pa.dec.com>.
 1.9 13-Jul-1997  christos branches: 1.9.2;
Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.8 07-Jul-1997  phil Modify to have _gettemp generate different names on repeated calls even if the
file was not created. Tempnam modified to make use of full possibilities.
 1.7 16-Mar-1997  lukem add warn_refs for mktemp(), tempnam(), and tmpnam() since most code
use these incorrectly. mkstemp() is ok however. inspired by openbsd
 1.6 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.5 19-Oct-1994  cgd needs string.h
 1.4 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.3 01-Aug-1993  mycroft Add RCS identifiers.
 1.2 02-Apr-1993  cgd fixed problem with 2 `/' chars back to back in temp files, which kills emacs
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9.2.1 04-Nov-1997  thorpej Pull up from trunk: __warn_references and __indr_reference semicolon fixups.
 1.13.12.3 13-Aug-2002  nathanw Catch up to -current.
 1.13.12.2 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.13.12.1 08-Oct-2001  nathanw Catch up to -current.
 1.21.6.1 17-Apr-2012  yamt sync with head
 1.12 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.11 07-Aug-2003  agc branches: 1.11.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.10 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.9 10-Aug-2002  yamt use more Xs for filename templates.
from OpenBSD.
 1.8 13-Oct-1998  kleink branches: 1.8.12;
Need an internal name for fdopen().
 1.7 01-Jun-1998  kleink Need <stdlib.h> for mkstemp() prototype.
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 02-Feb-1995  jtc branches: 1.5.2;
Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 28-Dec-1993  jtc #include <string.h> to bring function prototypes into scope.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.2.1 02-Mar-1995  jtc #include "namespace.h"
 1.8.12.1 13-Aug-2002  nathanw Catch up to -current.
 1.11.56.1 17-Apr-2012  yamt sync with head
 1.18 01-Sep-2019  uwe Refer to "w+" as "mode" as that's what fopen(3) calls it.
 1.17 30-Apr-2010  jruoho branches: 1.17.46;
Also tmpnam(3) and tempnam(3) are now obsolete in POSIX.
 1.16 22-Mar-2010  joerg Use .In for header files instead of .Ar Pa and variations.
 1.15 18-Jun-2005  lukem use "tempnam" instead of "tmpname"
 1.14 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.13 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.12 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.11 20-Aug-2002  wiz Drop superfluous Ns and fix a formatting glitch.
 1.10 10-Aug-2002  yamt - add description of the race.
- fix typo.
from OpenBSD.
 1.9 07-Feb-2002  ross Generate <>& symbolically.
 1.8 08-Jun-1998  lukem branches: 1.8.12;
Implement a new manual page category ``SECURITY CONSIDERATIONS''
(suggested by mycroft)
 1.7 28-Apr-1998  fair "System V" -> ".At V"
 1.6 28-Apr-1998  fair fix mdoc references and other mistakes
 1.5 05-Feb-1998  perry add LIBRARY section to man page
 1.4 24-Mar-1997  lukem * clarify that tempnam and tmpnam still have problems
* advise mkstemp() over mktemp(), tmpnam(), tempnam(), and indicate
link-time warning if latter 3 are used
* minor cleanups
 1.3 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8.12.4 27-Aug-2002  nathanw Catch up to -current.
 1.8.12.3 13-Aug-2002  nathanw Catch up to -current.
 1.8.12.2 22-Mar-2002  nathanw Catch up to -current.
 1.8.12.1 08-Mar-2002  nathanw Catch up to -current.
 1.17.46.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.15 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.14 07-Aug-2003  agc branches: 1.14.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.13 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.12 10-Aug-2002  yamt use more Xs for filename templates.
from OpenBSD.
 1.11 13-Oct-1998  kleink branches: 1.11.12;
Need internal names for snprintf() and vsnprintf().
 1.10 27-Jul-1998  mycroft Mention mkdtemp() in the warnings.
 1.9 04-Nov-1997  thorpej __warn_references and __indr_reference semicolon fixups. From
Chris Demetriou <cgd@pa.dec.com>.
 1.8 13-Jul-1997  christos branches: 1.8.2;
Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.7 16-Mar-1997  lukem add warn_refs for mktemp(), tempnam(), and tmpnam() since most code
use these incorrectly. mkstemp() is ok however. inspired by openbsd
 1.6 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.5 29-Mar-1994  cgd be reasonable and unique.
 1.4 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.3 01-Aug-1993  mycroft Add RCS identifiers.
 1.2 02-Apr-1993  cgd fixed problem with 2 `/' chars back to back in temp files, which kills emacs
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8.2.1 04-Nov-1997  thorpej Pull up from trunk: __warn_references and __indr_reference semicolon fixups.
 1.11.12.2 13-Aug-2002  nathanw Catch up to -current.
 1.11.12.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.14.56.1 17-Apr-2012  yamt sync with head
 1.10 30-Apr-2010  jruoho Add HISTORY.
 1.9 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.8 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.7 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.6 07-Feb-2002  ross Generate <>& symbolically.
 1.5 16-Sep-2001  wiz Mainly sort SEE ALSO, but also sort sections, and some punctuation and
paragraph fixes.
 1.4 05-Feb-1998  perry branches: 1.4.12;
add LIBRARY section to man page
 1.3 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.12.3 22-Mar-2002  nathanw Catch up to -current.
 1.4.12.2 08-Mar-2002  nathanw Catch up to -current.
 1.4.12.1 08-Oct-2001  nathanw Catch up to -current.
 1.17 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.16 25-Oct-2009  christos branches: 1.16.6;
revert some of dsl's changes to make things build on i386; he can undo what
he wants when he comes back.
 1.15 24-Oct-2009  dsl Remove a load of pointless casts - one that even lint doesn't bleat about.
 1.14 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.13 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.12 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.11 20-Sep-1999  lukem branches: 1.11.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.10 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.9 15-Nov-1998  christos delint
 1.8 07-Sep-1998  kleink Deploy stdio stream locking as necessary.
 1.7 03-Feb-1998  perry remove obsolete register declarations
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 29-Mar-1996  jtc Add explict function return types
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11.10.2 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.11.10.1 28-Jan-2002  nathanw Catch up to -current.
 1.16.6.1 17-Apr-2012  yamt sync with head
 1.9 08-Sep-2024  rillig fix a/an grammar in obvious cases
 1.8 16-Dec-2010  wiz branches: 1.8.58;
Observe the following spelling:
- wide character (noun)
- wide-character (adjective)

Inspired by jmc@OpenBSD.
 1.7 08-Sep-2003  wiz Use St -isoC-9X instead of St -isoC9X, to be in sync with groff.
 1.6 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.5 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.4 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.3 07-Feb-2002  ross Generate <>& symbolically.
 1.2 07-Dec-2001  wiz branches: 1.2.2;
Avoid Po/Pq.
 1.1 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.2.2.4 22-Mar-2002  nathanw Catch up to -current.
 1.2.2.3 08-Mar-2002  nathanw Catch up to -current.
 1.2.2.2 28-Jan-2002  nathanw Catch up to -current.
 1.2.2.1 07-Dec-2001  nathanw file ungetwc.3 was added on branch nathanw_sa on 2002-01-28 20:51:10 +0000
 1.8.58.1 02-Aug-2025  perseant Sync with HEAD
 1.3 12-Jun-2005  lukem Add missing __RCSID()
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 07-Dec-2001  yamt branches: 1.1.2;
- make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.1.2.3 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.1.2.2 28-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 07-Dec-2001  nathanw file ungetwc.c was added on branch nathanw_sa on 2002-01-28 20:51:11 +0000
 1.17 19-May-2013  christos don't cast malloc
 1.16 17-May-2013  joerg Provide explicit LC_C_LOCALE accessor and drop the various NULL checks.
Provide LC_GLOBAL_LOCALE in a way that works with all locale functions.
Merge constant data used by the initial global locale and the C locale.
Drop function call layer for _current_locale() and directly return the
locale reference, not a pointer to it. Use protected access for global
variables, so that libc references can avoid the GOT overhead.
 1.15 19-Apr-2013  joerg Add explicit locale versions for the printf family. Replace asprintf,
snprintf and sprintf with simple wrappers around the corresponding
va_list functions to reduce code duplication.
 1.14 15-Mar-2012  christos branches: 1.14.2;
- ansify, knf.
- no functional changes
 1.13 17-Jul-2011  joerg branches: 1.13.2;
Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.12 25-Oct-2009  christos revert some of dsl's changes to make things build on i386; he can undo what
he wants when he comes back.
 1.11 24-Oct-2009  dsl Remove a load of pointless casts - one that even lint doesn't bleat about.
 1.10 09-Feb-2005  kleink A little libc namespace housekeeping exercise:
* Make vfprintf_unlocked() an internal function, c.f. __svfscanf_unlocked().
* Add internal names for arc4random(), endnetpath(), fhstatvfs(),
fstatvfs(), mkstemp(), shquote(), statvfs(), taddr2uaddr(), uaddr2taddr(),
uuid_create_nil(), uuid_is_nil(), and wcwidth().
* Include namespace.h where supposed to.
 1.9 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.8 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.7 21-Jan-2000  mycroft branches: 1.7.6;
Initialize f._file for locking primitives.
 1.6 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.5 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.4 15-Nov-1998  christos delint
 1.3 15-Oct-1998  mycroft Make sure we free the buffer in all error cases.
Do the final realloc(3) to the size of the string, not the size of the buffer
allocated for the string (which is a noop).
 1.2 08-Sep-1998  kleink s/NULL/NUL/ where appropriate.
 1.1 28-Aug-1998  perry add asprintf and vasprintf, originally written by Todd Miller for OpenBSD
 1.7.6.3 02-May-2002  nathanw Call the _unlocked versions of vfprintf() and __svfscanf(); there's no point
in locking and unlocking a FILE object that only exists in the local scope.
This also has the nice side effect of making sprintf() usable for debugging
threaded code.
 1.7.6.2 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.7.6.1 28-Jan-2002  nathanw Catch up to -current.
 1.13.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.13.2.1 17-Apr-2012  yamt sync with head
 1.14.2.1 23-Jun-2013  tls resync from head
 1.6 28-Aug-2020  christos Allow vdprintf to work on non-blocking non-regular files (Rob Newberry)
 1.5 10-Jan-2017  christos include <sys/stat.h>
 1.4 17-May-2013  joerg branches: 1.4.10;
Provide explicit LC_C_LOCALE accessor and drop the various NULL checks.
Provide LC_GLOBAL_LOCALE in a way that works with all locale functions.
Merge constant data used by the initial global locale and the C locale.
Drop function call layer for _current_locale() and directly return the
locale reference, not a pointer to it. Use protected access for global
variables, so that libc references can avoid the GOT overhead.
 1.3 19-Apr-2013  joerg Add explicit locale versions for the printf family. Replace asprintf,
snprintf and sprintf with simple wrappers around the corresponding
va_list functions to reduce code duplication.
 1.2 17-Jul-2011  joerg branches: 1.2.2; 1.2.8;
Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.1 06-Sep-2010  christos add dprintf and vdprintf
 1.2.8.1 23-Jun-2013  tls resync from head
 1.2.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4.10.1 20-Mar-2017  pgoyette Sync with HEAD
 1.60 19-Apr-2013  joerg Add explicit locale versions for the printf family. Replace asprintf,
snprintf and sprintf with simple wrappers around the corresponding
va_list functions to reduce code duplication.
 1.59 15-Oct-2009  dsl branches: 1.59.6; 1.59.12;
Reverse previous, committed by mistake.
 1.58 14-Oct-2009  dsl Change a while () {} into a do {} while() so that fgets(buf, 1, file)
detects EOF on an empty file.
Fixes most of PR/41992
 1.57 03-Feb-2007  christos use vfwprintf.c
 1.56 02-Feb-2007  christos Instead of abusing stdio to get a signal-safe version of sprintf, provide one.
 1.55 26-Jan-2007  cbiere Fix for issue reported in PR lib/35401 as well as related overflow bugs.
 1.54 30-Oct-2006  christos branches: 1.54.2;
set n properly so that we can terminate.
 1.53 28-Oct-2006  christos Initialize decimal_point.
 1.52 28-Oct-2006  christos initialize floating_point as needed.
 1.51 27-Oct-2006  christos Add signal-safe versions of snprintf and vsnprintf
 1.50 16-Feb-2006  christos - s/notyet/WIDE_DOUBLE/
- Add a little more glue for WIDE_DOUBLE; not done yet.
- s/def FLOATING_POINT/ndef NO_FLOATING_POINT/ to reduce diffs with FreeBSD.
- fix memory leak where each double formatted leaked 24 by calling __freedtoa()
appropriately. the new gdtoa keeps a list of memory chunks allocated by
malloc(), and it must maintained properly by calling __freedtoa() on the
results of __dtoa() Hi Klaus!
- in vfwprintf() make cvt return char * and convert it using __mbsconv(),
instead of having it return wchar_t *.

This should fix the memory leaks people have been reporting (eg. in top etc.)
 1.49 29-Nov-2005  christos WARNS=4
 1.48 09-Feb-2005  kleink A little libc namespace housekeeping exercise:
* Make vfprintf_unlocked() an internal function, c.f. __svfscanf_unlocked().
* Add internal names for arc4random(), endnetpath(), fhstatvfs(),
fstatvfs(), mkstemp(), shquote(), statvfs(), taddr2uaddr(), uaddr2taddr(),
uuid_create_nil(), uuid_is_nil(), and wcwidth().
* Include namespace.h where supposed to.
 1.47 02-Jul-2004  christos remove __UNCONST definition; it is now in <sys/cdefs.h>
 1.46 03-Mar-2004  drochner branches: 1.46.4;
Don't zero a floating point variable on entry -- this causes the FPU to
be allocated needlessly by almost every program (at least on i386/amd64).
 1.45 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.44 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.43 26-May-2002  wiz __STDC__ is always defined on NetBSD.
 1.42 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.41 02-Dec-2001  kleink C99:
* Recognize %F.
* Convert {Infinity,NaN} to {"inf","nan"} for %[efg], and to
{"INF","NAN"} for %[EFG].
 1.40 28-Nov-2001  kleink Since we're returned the sign of a floating-point number by __dtoa(),
use that to decide whether to include a minus sign in the result.
Fixes printing -0.0, and thus PR lib/3137.
 1.39 27-Nov-2001  augustss Ugh, back out last commit. It makes vfprintf depend on -lm.
 1.38 27-Nov-2001  augustss Print sign of -0.0 correctly. Fixes PR 3137 (mine).
 1.37 04-Nov-2001  lukem fix WARNS=2 (-Wshadow) warnings
 1.36 28-Apr-2001  kleink * Move definitions of exact-width integer types from <machine/types.h>
to <sys/types.h> and <sys/stdint.h>.
* Add a new C99 <stdint.h> header, which provides integer types of
explicit width, related limits and integer constant macros.
* Extend <inttypes.h> to provide <stdint.h> definitions and format
macros for printf() and scanf().
* Add C99 strtoimax() and strtoumax() functions.
* Use the latter within scanf().
* Add C99 %j, %t and %z printf()/scanf() conversions for
intmax_t, pointer-type and size_t arguments.
 1.35 30-Dec-2000  itojun branches: 1.35.2;
initialize mbstate_t properly.
 1.34 23-Dec-2000  itojun make printf-variant work with stateful encodings.
 1.33 08-Jul-2000  sommerfeld Attach __format__ attributes to local __sbprintf function
 1.32 20-Sep-1999  lukem branches: 1.32.8;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.31 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.30 15-Nov-1998  christos This is ugly. There is a const castaway inside the print macro, so we cannot
use /* LINTED */ comments, since cpp will expand comments only at the macro
definition location, not at every expansion.
 1.29 13-Oct-1998  kleink Need internal names for isinf() and isnan().
 1.28 09-Sep-1998  kleink Perform stdio stream locking as appropriate.
 1.27 27-Jul-1998  mycroft Delint (partially).
 1.26 26-Jul-1998  mycroft Minor nit.
 1.25 26-Jul-1998  mycroft const poisoning.
 1.24 26-Jul-1998  mycroft const poisoning.
 1.23 03-Feb-1998  perry remove obsolete register declarations
 1.22 19-Dec-1997  kleink Change several functions to return -1 instead of EOF, which was semantically
wrong.
 1.21 29-Aug-1997  phil Remove the flag test when seeing if _double is zero or not. We
are only testing for the cvt problem, not for alternate forms.
This change makes %#e and %e both correctly print 0. It is just
a question of is it the proper number of zeros or not?
 1.20 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.19 03-May-1997  kleink Upon an attempt to write to a stream that can't be written to, set errno
to EBADF.
 1.18 02-Apr-1997  kleink RCSid police
 1.17 02-May-1995  jtc The C Standard says that printf's format string is a multi-byte
character string. NA1 says that the 99 characters required by the
Standard have representations in the initial state which are one byte
long and do not alter the state.

Thus we can safely break apart the format string with mbtowc() until
we reach a '%' character, and the process format directive characters
one by one.

We really shouldn't be using mbtowc(), rather mbrtowc() (which takes a
mbstate-t argument) but we don't have the NA1 functions implemented
yet. This is safe, because even when we do we're not likely to
support multi-byte character encodings that use shift states.
 1.16 22-Mar-1995  jtc Added "long long" support %ll{d,x,o,i}.
 1.15 25-Feb-1995  cgd when you have a pointer and want to assign to a quad, you must cast it
to long to quiet the compiler.
 1.14 25-Jan-1995  jtc branches: 1.14.2;
Fixed bug with '+' or ' ' flags and precision.
for example, printf("% 6.4d\n", 77) output one two many padding chars.
 1.13 20-Oct-1994  jtc Fix zero padding when using the # format modifier.
 1.12 30-Sep-1994  jtc The decimal point character is locale specific.
 1.11 19-Sep-1994  mycroft Move FLOATING_POINT definition into Makefile.inc.
 1.10 22-May-1994  cgd _VA_LIST_ -> _BSD_VA_LIST_
 1.9 04-Nov-1993  jtc Corrected and simplified floating point formatting.
Now conforms to ANSI C --- passes the fairly rigorous TCL "format.test".
 1.8 03-Nov-1993  jtc Trailing zeros should be printed with all floating point formats
except %g && %G --- ANSI X3.159-1989, Sect 7.9.6.1.
 1.7 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.6 01-Aug-1993  mycroft Add RCS identifiers.
 1.5 12-Jul-1993  mycroft Make declarations match prototypes.
 1.4 09-Jul-1993  cgd update for better FP routines, from AT&T & elsewhere
 1.3 18-Apr-1993  mycroft Fix error in last patch.
 1.2 18-Apr-1993  mycroft Make arguments match prototypes.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.14.2.1 02-Mar-1995  jtc #include "namespace.h"
 1.32.8.1 09-Dec-2001  he Pull up revision 1.40 (requested by kleink):
Print the sign prefix for -0.0; fixes PR#3137.
 1.35.2.6 21-Jun-2002  nathanw Catch up to -current.
 1.35.2.5 02-May-2002  nathanw Remove calls to FLOCKFILE() and FUNLOCKFILE() from vfprintf() and __svfscanf(),
rename those routines to vfprintf_unlocked() and __svfscanf_unlocked(),
and implement vfprintf() and __svfscanf() as small routines that do
FLOCKFILE()/foo_unlocked()/FUNLOCKFILE().
 1.35.2.4 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.35.2.3 28-Jan-2002  nathanw Catch up to -current.
 1.35.2.2 14-Nov-2001  nathanw Catch up to -current.
 1.35.2.1 08-Oct-2001  nathanw Catch up to -current.
 1.46.4.1 01-Jun-2005  riz Pull up revision 1.47 (requested by christos in ticket #1968):
remove __UNCONST definition; it is now in &lt;sys/cdefs.h&gt;
 1.54.2.1 07-May-2007  pavel Pull up following revision(s) (requested by manu in ticket #607):
lib/libc/arch/i386/gen/isnanl.c: revision 1.6
lib/libc/gdtoa/gdtoa.c: revision 1.2-1.3
lib/libc/arch/x86_64/gen/isnanl.c: revision 1.6
lib/libc/gdtoa/gdtoaimp.h: revision 1.6
sys/arch/m68k/include/ieee.h: revision 1.13
usr.bin/xlint/lint1/scan.l: revision 1.36-1.37
lib/libc/stdio/snprintf_ss.c: revision 1.4
lib/libc/arch/i386/gen/isfinitel.c: revision 1.2
lib/libc/stdio/vfscanf.c: revision 1.38
sys/arch/sparc/include/ieee.h: revision 1.11-1.12
lib/libc/gdtoa/dtoa.c: revision 1.4
lib/libc/stdio/Makefile.inc: revision 1.35
lib/libc/stdio/fvwrite.c: revision 1.17
lib/libc/arch/m68k/gen/fpclassifyl.c: revision 1.2
lib/libc/arch/i386/gen/isinfl.c: revision 1.6
lib/libc/arch/x86_64/gen/isinfl.c: revision 1.6
lib/libc/arch/x86_64/gen/isfinitel.c: revision 1.2
lib/libc/stdio/vfprintf.c: revision 1.55-1.57
lib/libc/stdio/vsnprintf_ss.c: revision 1.3
lib/libc/stdio/vfwprintf.c: revision 1.10
sys/arch/x86/include/ieee.h: revision 1.10
lib/libc/gdtoa/dmisc.c: revision 1.3
lib/libc/gdtoa/Makefile.inc: revision 1.5
sys/arch/hppa/include/ieee.h: revision 1.10
lib/libc/arch/x86_64/gen/fpclassifyl.c: revision 1.3
lib/libc/arch/i386/gen/fpclassifyl.c: revision 1.2
sys/sys/ieee754.h: revision 1.7
lib/libc/gdtoa/gdtoa.h: revision 1.7
include/stdio.h: revision 1.67-1.68
lib/libc/gdtoa/hdtoa.c: revision 1.1-1.4
lib/libc/gdtoa/ldtoa.c: revision 1.1-1.4
defined(_NETBSD_SOURCE) is equivalent to (!defined(_ANSI_SOURCE) &&
!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)), so there's no
need to check both of them.
Fix for issue reported in PR lib/35401 as well as related overflow bugs.
deal with hex doubles.
Instead of abusing stdio to get a signal-safe version of sprintf, provide one.
remove __SAFE
add long double and hex double support from freebsd.
make this compile.
add new prototypes.
add the new files to the build. Note I am not bumping libc now, because
these are not used yet.
Merge the int bit with the high fraction bit. Add constants/macros
needed by gdtoa.
add constants used by gdtoa
since the int bit is merged, do the explicit math.
ext_int bit is no more.
ext_int bit is no more.
- merge change from freebsd
- add support for building as vfprintf.c
- XXX: we strdup to simplify the freeing logic. This should be fixed for
efficiency in the vfprintf case.
use vfwprintf.c
enable wide doubles.
some int -> size_t
deal with sparc64 that has 112 bits of mantissa.
make extended precision gdtoa friendly.
int/size_t changes
make this gdtoa friendly.
remove dup definition
use dtoa() instead of returning empty when we don't have extended precision
information.
Fix previous, add forgotten pointer dereference in the call to dtoa().
Add a cheesy workaround marked XXX for the situation where the
strtod() implementation available in the environment does not
handle hex floats.
Discussed with and suggested by christos
From Christos: gdtoa fixes for m68k. M68k ports should build now, but
printing extended precision is a little off.
vax does not have <machine/ieee.h> or long double
It would be nice if the compiler provided something like __IEEE_MATH__
bring in FreeBSD's vfscanf() to gain multi-byte/collation support.
Unfortunately it is too difficult to make vfwscanf and this share
the same code like I did with printf, because for string parsing
the code is too different.
 1.59.12.1 23-Jun-2013  tls resync from head
 1.59.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.47 24-May-2022  andvar fix various typos in comments, docs and log messages.
 1.46 19-Apr-2022  rillig lib: remove CONSTCOND comment

Since 2021-01-31, lint doesn't need it anymore for the common pattern of
'do ... while (0)'.
 1.45 17-May-2013  joerg Provide explicit LC_C_LOCALE accessor and drop the various NULL checks.
Provide LC_GLOBAL_LOCALE in a way that works with all locale functions.
Merge constant data used by the initial global locale and the C locale.
Drop function call layer for _current_locale() and directly return the
locale reference, not a pointer to it. Use protected access for global
variables, so that libc references can avoid the GOT overhead.
 1.44 19-Apr-2013  joerg Add scanf_l and wscanf_l families.
 1.43 15-Mar-2012  christos branches: 1.43.2;
- ansify, knf.
- no functional changes
 1.42 13-Mar-2012  christos PR/45989: Martin Husemann: lint invocation does include -w only on i386

- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
builds)

approved by core@
 1.41 16-Dec-2010  wiz branches: 1.41.6;
Observe the following spelling:
- wide character (noun)
- wide-character (adjective)

Inspired by jmc@OpenBSD.
 1.40 30-Jan-2009  lukem sign-compare fix
 1.39 28-Aug-2008  christos branches: 1.39.6;
Ignore whitespace in format string from Andy Shevchenko
 1.38 01-Apr-2007  christos branches: 1.38.12;
bring in FreeBSD's vfscanf() to gain multi-byte/collation support.
Unfortunately it is too difficult to make vfwscanf and this share
the same code like I did with printf, because for string parsing
the code is too different.
 1.37 16-Feb-2006  christos branches: 1.37.4;
- s/notyet/WIDE_DOUBLE/
- Add a little more glue for WIDE_DOUBLE; not done yet.
- s/def FLOATING_POINT/ndef NO_FLOATING_POINT/ to reduce diffs with FreeBSD.
- fix memory leak where each double formatted leaked 24 by calling __freedtoa()
appropriately. the new gdtoa keeps a list of memory chunks allocated by
malloc(), and it must maintained properly by calling __freedtoa() on the
results of __dtoa() Hi Klaus!
- in vfwprintf() make cvt return char * and convert it using __mbsconv(),
instead of having it return wchar_t *.

This should fix the memory leaks people have been reporting (eg. in top etc.)
 1.36 30-Dec-2003  martin Add support for scanf "hh" format modifiers - we use it in int_fmtio.h
for SCNd8 and friends - so we should support it properly (and not only
by pure luck on alignment blind little endian archs - it used the
"h" code path, storing a 16bit int via a byte pointer).

This makes sparc64 pass regress/lib/libc/int_fmtio.
 1.35 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.34 27-May-2003  thorpej Fix handing of -ve hexadecimal numbers in the %i format. Fixes
PR lib/21691. Patch from Simon Burge.
 1.33 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.32 26-May-2002  wiz __STDC__ is always defined on NetBSD.
 1.31 24-May-2002  thorpej * Move the prototype of __svfscanf from <stdio.h> to libc/stdio/local.h.
* Add prototype for vfscanf to <stdio.h>.
* Remove #define of vfscanf to __svfscanf from <stdio.h>.
* Include local.h in libc files which need __svfscanf.
* Add vfscanf weak alias to __svfscanf.

Fixes standards/16997.

NOTE: libc minor not bumped -- ride on the bump to 12.84 made by
itojun today.
 1.30 07-Dec-2001  yamt branches: 1.30.2;
- make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.29 02-Dec-2001  kleink C99: Recognize %F here, too.
 1.28 28-Apr-2001  kleink * Move definitions of exact-width integer types from <machine/types.h>
to <sys/types.h> and <sys/stdint.h>.
* Add a new C99 <stdint.h> header, which provides integer types of
explicit width, related limits and integer constant macros.
* Extend <inttypes.h> to provide <stdint.h> definitions and format
macros for printf() and scanf().
* Add C99 strtoimax() and strtoumax() functions.
* Use the latter within scanf().
* Add C99 %j, %t and %z printf()/scanf() conversions for
intmax_t, pointer-type and size_t arguments.
 1.27 08-Mar-2000  kleink branches: 1.27.6;
Replace internal use of strto{,u}q() with strto{,u}ll().
 1.26 21-Jan-2000  wrstuden Need to include "reentrant.h" for FLOCKFILE macros.
 1.25 21-Jan-2000  mycroft Do file locking.
 1.24 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.23 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.22 15-Nov-1998  christos delint
 1.21 25-Oct-1998  kleink Don't return immediately if EOF encountered while matching format string white
space in the input stream since there may be `conversion' specifiers following
the (format string) white space that do not operate on the input stream,
i.e. %n; from Chris Torek.
 1.20 27-Jul-1998  mycroft Delint (partially).
 1.19 26-Jul-1998  mycroft const poisoning.
 1.18 03-Feb-1998  perry remove obsolete register declarations
 1.17 19-Dec-1997  kleink Change several functions to return -1 instead of EOF, which was semantically
wrong.
 1.16 13-Jul-1997  christos branches: 1.16.2;
Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.15 29-Mar-1996  jtc branches: 1.15.2;
Add explict function return types
 1.14 22-Mar-1995  jtc Added "long long" support %ll{d,x,o,i}.
 1.13 25-Feb-1995  cgd when you have a quad and want to assign to a pointer, you must say:
ptr = (ptr_type)(long)quad;
to quiet the compiler.
 1.12 02-Feb-1995  jtc branches: 1.12.2;
Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.11 30-Jan-1995  jtc Handle long doubles.

Like Plauger's implementation in "The Standard C Library", we use strtod(),
which will limit the range of values that can be converter properly if
long double has greater precision or range than double.

We will need a string to long double function to handle this properly, but
this change is better than the previous behavior of ignoring the existance
of long doubles.
 1.10 27-Jan-1995  jtc Added support for quad_t and u_quad_t's with the 'q' flag.
 1.9 26-Jan-1995  jtc Removed conflicting "backwards compatibility" code to make scanf
ANSI compliant.
 1.8 19-Sep-1994  mycroft Move FLOATING_POINT definition into Makefile.inc.
 1.7 22-May-1994  cgd _VA_LIST_ -> _BSD_VA_LIST_
 1.6 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.5 01-Aug-1993  mycroft Add RCS identifiers.
 1.4 12-Jul-1993  mycroft Make declarations match prototypes.
 1.3 09-Jul-1993  cgd update for better FP routines, from AT&T & elsewhere
 1.2 18-Apr-1993  mycroft Make arguments match prototypes.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.12.2.1 17-Feb-1995  jtc Make namespace safe by using "namespace.h".
 1.15.2.1 16-Sep-1996  jtc snapshot namespace cleanup
 1.16.2.1 06-Nov-1998  cgd pull up rev 1.21 from trunk (kleink)
 1.27.6.5 21-Jun-2002  nathanw Catch up to -current.
 1.27.6.4 02-May-2002  nathanw Remove calls to FLOCKFILE() and FUNLOCKFILE() from vfprintf() and __svfscanf(),
rename those routines to vfprintf_unlocked() and __svfscanf_unlocked(),
and implement vfprintf() and __svfscanf() as small routines that do
FLOCKFILE()/foo_unlocked()/FUNLOCKFILE().
 1.27.6.3 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.27.6.2 28-Jan-2002  nathanw Catch up to -current.
 1.27.6.1 08-Oct-2001  nathanw Catch up to -current.
 1.30.2.1 19-Jun-2003  grant Pull up revision 1.34 (requested by thorpej in ticket #1298):

Fix handing of -ve hexadecimal numbers in the %i format. Fixes
PR lib/21691. Patch from Simon Burge.
 1.37.4.1 07-May-2007  pavel Pull up following revision(s) (requested by manu in ticket #607):
lib/libc/arch/i386/gen/isnanl.c: revision 1.6
lib/libc/gdtoa/gdtoa.c: revision 1.2-1.3
lib/libc/arch/x86_64/gen/isnanl.c: revision 1.6
lib/libc/gdtoa/gdtoaimp.h: revision 1.6
sys/arch/m68k/include/ieee.h: revision 1.13
usr.bin/xlint/lint1/scan.l: revision 1.36-1.37
lib/libc/stdio/snprintf_ss.c: revision 1.4
lib/libc/arch/i386/gen/isfinitel.c: revision 1.2
lib/libc/stdio/vfscanf.c: revision 1.38
sys/arch/sparc/include/ieee.h: revision 1.11-1.12
lib/libc/gdtoa/dtoa.c: revision 1.4
lib/libc/stdio/Makefile.inc: revision 1.35
lib/libc/stdio/fvwrite.c: revision 1.17
lib/libc/arch/m68k/gen/fpclassifyl.c: revision 1.2
lib/libc/arch/i386/gen/isinfl.c: revision 1.6
lib/libc/arch/x86_64/gen/isinfl.c: revision 1.6
lib/libc/arch/x86_64/gen/isfinitel.c: revision 1.2
lib/libc/stdio/vfprintf.c: revision 1.55-1.57
lib/libc/stdio/vsnprintf_ss.c: revision 1.3
lib/libc/stdio/vfwprintf.c: revision 1.10
sys/arch/x86/include/ieee.h: revision 1.10
lib/libc/gdtoa/dmisc.c: revision 1.3
lib/libc/gdtoa/Makefile.inc: revision 1.5
sys/arch/hppa/include/ieee.h: revision 1.10
lib/libc/arch/x86_64/gen/fpclassifyl.c: revision 1.3
lib/libc/arch/i386/gen/fpclassifyl.c: revision 1.2
sys/sys/ieee754.h: revision 1.7
lib/libc/gdtoa/gdtoa.h: revision 1.7
include/stdio.h: revision 1.67-1.68
lib/libc/gdtoa/hdtoa.c: revision 1.1-1.4
lib/libc/gdtoa/ldtoa.c: revision 1.1-1.4
defined(_NETBSD_SOURCE) is equivalent to (!defined(_ANSI_SOURCE) &&
!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)), so there's no
need to check both of them.
Fix for issue reported in PR lib/35401 as well as related overflow bugs.
deal with hex doubles.
Instead of abusing stdio to get a signal-safe version of sprintf, provide one.
remove __SAFE
add long double and hex double support from freebsd.
make this compile.
add new prototypes.
add the new files to the build. Note I am not bumping libc now, because
these are not used yet.
Merge the int bit with the high fraction bit. Add constants/macros
needed by gdtoa.
add constants used by gdtoa
since the int bit is merged, do the explicit math.
ext_int bit is no more.
ext_int bit is no more.
- merge change from freebsd
- add support for building as vfprintf.c
- XXX: we strdup to simplify the freeing logic. This should be fixed for
efficiency in the vfprintf case.
use vfwprintf.c
enable wide doubles.
some int -> size_t
deal with sparc64 that has 112 bits of mantissa.
make extended precision gdtoa friendly.
int/size_t changes
make this gdtoa friendly.
remove dup definition
use dtoa() instead of returning empty when we don't have extended precision
information.
Fix previous, add forgotten pointer dereference in the call to dtoa().
Add a cheesy workaround marked XXX for the situation where the
strtod() implementation available in the environment does not
handle hex floats.
Discussed with and suggested by christos
From Christos: gdtoa fixes for m68k. M68k ports should build now, but
printing extended precision is a little off.
vax does not have <machine/ieee.h> or long double
It would be nice if the compiler provided something like __IEEE_MATH__
bring in FreeBSD's vfscanf() to gain multi-byte/collation support.
Unfortunately it is too difficult to make vfwscanf and this share
the same code like I did with printf, because for string parsing
the code is too different.
 1.38.12.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.39.6.2 28-Aug-2008  christos Ignore whitespace in format string from Andy Shevchenko
 1.39.6.1 28-Aug-2008  christos file vfscanf.c was added on branch christos-time_t on 2008-08-28 16:41:22 +0000
 1.41.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.41.6.1 17-Apr-2012  yamt sync with head
 1.43.2.1 23-Jun-2013  tls resync from head
 1.41 20-Jan-2024  christos Catch up with all the lint warnings since exit on warning was disabled.
Disable 'missing header declaration' and 'nested extern' warnings for now.
 1.40 04-Apr-2023  christos PR/57250: Martin Husemann: dtoa mishandles infinite doubles on 32bit big
endian machines. When long double support was added, the old code was kept
for the regular double code. This code was never used because WIDE_DOUBLE
was always defined in the Makefile. Remove that old code, and conditionalize
the WIDE_DOUBLE code based on if long doubles are different than doubles on
the specific platform.
 1.39 19-Apr-2022  rillig branches: 1.39.2;
lib: remove CONSTCOND comment

Since 2021-01-31, lint doesn't need it anymore for the common pattern of
'do ... while (0)'.
 1.38 12-Mar-2022  christos reallocarr returns errno. preserve it.
 1.37 12-Mar-2022  nia vfwprintf(3): use reallocarr
 1.36 11-Jul-2017  perseant branches: 1.36.8;
A more correct fix for PR standards/52282.
 1.35 10-Jul-2017  perseant Do not use thousands grouping when none is specified by the locale.
Fixes PR standards/52282.
 1.34 20-Jan-2014  yamt branches: 1.34.18;
vfwprintf: fix error propagation
PR/47660 (Julio Merino)
 1.33 23-Sep-2013  pooka Make compile with -DNO_FLOATING_POINT
 1.32 17-May-2013  joerg Provide explicit LC_C_LOCALE accessor and drop the various NULL checks.
Provide LC_GLOBAL_LOCALE in a way that works with all locale functions.
Merge constant data used by the initial global locale and the C locale.
Drop function call layer for _current_locale() and directly return the
locale reference, not a pointer to it. Use protected access for global
variables, so that libc references can avoid the GOT overhead.
 1.31 19-Apr-2013  joerg Add explicit locale versions for the printf family. Replace asprintf,
snprintf and sprintf with simple wrappers around the corresponding
va_list functions to reduce code duplication.
 1.30 27-Mar-2012  christos branches: 1.30.2;
- widen the internal read and write calls to match the syscalls
- add funopen2() which provides access to flush() and the wider calls.
- make use of the new flush call in fmemopen()
 1.29 21-Mar-2012  christos unsigned char portability casts
 1.28 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.27 13-Mar-2012  christos PR/45989: Martin Husemann: lint invocation does include -w only on i386

- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
builds)

approved by core@
 1.26 17-Feb-2012  christos remove unused variable
 1.25 17-Feb-2012  christos Fix: CVE-2012-0864 fprintf() positional argument abuse.
Described in: http://www.phrack.org/issues.html?issue=67&id=9#article
Reported by Stefan Cornelius / Red Hat Security Response Team

- convert internal positional arguments bookkeeping from int to size_t
- provide overflow protection in positional argument spec
- convert loops to memset
- fix memory leaks
- limit positional argument stack offset to the number of arguments required
by the printf to avoid coredump from va_arg() exhaustion.
 1.24 17-Aug-2011  christos branches: 1.24.2;
fix the rest of libc mi gcc-4.5 hacks. portmasters should fix the md ones.
 1.23 16-Dec-2010  wiz Observe the following spelling:
- wide character (noun)
- wide-character (adjective)

Inspired by jmc@OpenBSD.
 1.22 19-Nov-2010  christos PR/44113: Nicolas Joly: printf(3) should ignore zero padding for nan/inf
 1.21 31-Jul-2010  tnozaki initialize fake FILE, not fp.
 1.20 31-Jul-2010  christos undo unrelated diff.
 1.19 31-Jul-2010  tnozaki fix coredump vfwprintf(stderr) reported in current-user@
rework rev1.9, _FILEEXT_SETUP() doesn't care wcio_data. so initialize it.
 1.18 25-Oct-2009  christos revert some of dsl's changes to make things build on i386; he can undo what
he wants when he comes back.
 1.17 24-Oct-2009  dsl Remove a load of pointless casts - one that even lint doesn't bleat about.
 1.16 05-Aug-2009  dsl If the current locale doesn't define the 'thousands' grouping info
then use sane defaults (',' every 3 digits).
Fixes PR/40714
 1.15 20-Feb-2009  roy printf("%zi\n", (ssize_t)-1); now correcly prints -1 on i386

ok: christos
 1.14 30-Jan-2009  lukem branches: 1.14.2;
sign-compare fix
 1.13 05-Jun-2008  aymeric branches: 1.13.4; 1.13.6;
fix a "typo" which prevented %ls from working in printf() (NARROW case).
Among other things, nvi displays options correctly now.
 1.12 21-Mar-2008  christos branches: 1.12.2; 1.12.4;
Don't coredump on out of memory conditions. This solution leaks, but gdtoa
is too complicated to fix. Try printf %99999999999.9999999999f 2
 1.11 13-Mar-2008  christos Since _file is a short, check that the fd fits in it, otherwise bail with
EMFILE. We treat _file as an unsigned short to double our range, with a
special case for -1 (closed). Make a note of what we should do about stdio
if we ever bump libc. We could change _file in the future compatibly to an
int by putting it in the extension space but for now we don't bother.
 1.10 03-Feb-2007  christos branches: 1.10.4; 1.10.8;
- merge change from freebsd
- add support for building as vfprintf.c
- XXX: we strdup to simplify the freeing logic. This should be fixed for
efficiency in the vfprintf case.
 1.9 01-Oct-2006  tnozaki branches: 1.9.2;
fwprintf(stderr) may coredump, when LC_CTYPE locale is set none C/POSIX.
make sure to initialize struct __sfileext in FILE.
 1.8 10-May-2006  mrg quell GCC 4.1 uninitialised variable warnings.

XXX: we should audit the tree for which old ones are no longer needed
after getting the older compilers out of the tree..
 1.7 16-Feb-2006  christos - s/notyet/WIDE_DOUBLE/
- Add a little more glue for WIDE_DOUBLE; not done yet.
- s/def FLOATING_POINT/ndef NO_FLOATING_POINT/ to reduce diffs with FreeBSD.
- fix memory leak where each double formatted leaked 24 by calling __freedtoa()
appropriately. the new gdtoa keeps a list of memory chunks allocated by
malloc(), and it must maintained properly by calling __freedtoa() on the
results of __dtoa() Hi Klaus!
- in vfwprintf() make cvt return char * and convert it using __mbsconv(),
instead of having it return wchar_t *.

This should fix the memory leaks people have been reporting (eg. in top etc.)
 1.6 26-Jan-2006  kleink bcopy -> memcpy
 1.5 02-Dec-2005  yamt redo the previous (WARNS=4) differently. consitify rather than making
strings writable.
 1.4 29-Nov-2005  christos WARNS=4
 1.3 15-Jun-2005  he Initialize expsize to appease -Wuninitialized for sh3 and m68000.
Marked with XXXGCC -Wuninitialized [sh3,m68000].
 1.2 12-Jun-2005  lukem Ensure nconv isn't used in __mbsconv() before being initialized.
Appease gcc -Wuninitialized elsewhere.
 1.1 14-May-2005  christos Add the missing wide char support functions from freebsd.
XXX: long double support is missing until we get gdtoa, and add the
necessary wide functions.
 1.9.2.3 11-May-2009  bouyer Pull up following revision(s) (requested by cube in ticket #1313):
lib/libc/stdio/vfwprintf.c: revision 1.15
printf("%zi\n", (ssize_t)-1); now correcly prints -1 on i386
ok: christos
 1.9.2.2 08-Apr-2008  jdc Pull up revisions:
src/lib/libc/gdtoa/dmisc.c 1.4
src/lib/libc/gdtoa/gdtoa.c 1.4
src/lib/libc/gdtoa/gethex.c 1.4
src/lib/libc/gdtoa/misc.c 1.4
src/lib/libc/gdtoa/strtof_vaxf.c 1.4-1.5
src/lib/libc/gdtoa/strtopQ.c 1.4
src/lib/libc/gdtoa/strtopx.c 1.4
src/lib/libc/gdtoa/strtopxL.c 1.4
src/lib/libc/gdtoa/strtord.c 1.4
src/lib/libc/gdtoa/dtoa.c 1.5
src/lib/libc/gdtoa/strtod.c 1.5
src/lib/libc/gdtoa/g_Qfmt.c 1.3
src/lib/libc/gdtoa/g_xLfmt.c 1.3
src/lib/libc/gdtoa/g_xfmt.c 1.3
src/lib/libc/gdtoa/smisc.c 1.3
src/lib/libc/gdtoa/strtof.c 1.3
src/lib/libc/gdtoa/strtorQ.c 1.3
src/lib/libc/gdtoa/strtorx.c 1.3
src/lib/libc/gdtoa/strtorxL.c 1.3
src/lib/libc/gdtoa/g_ddfmt.c 1.2
src/lib/libc/gdtoa/g_dfmt.c 1.2
src/lib/libc/gdtoa/g_ffmt.c 1.2
src/lib/libc/gdtoa/strtoIQ.c 1.2
src/lib/libc/gdtoa/strtoId.c 1.2
src/lib/libc/gdtoa/strtoIdd.c 1.2
src/lib/libc/gdtoa/strtoIf.c 1.2
src/lib/libc/gdtoa/strtoIg.c 1.2
src/lib/libc/gdtoa/strtoIx.c 1.2
src/lib/libc/gdtoa/strtoIxL.c 1.2
src/lib/libc/gdtoa/strtodI.c 1.2
src/lib/libc/gdtoa/strtodnrp.c 1.2
src/lib/libc/gdtoa/strtopd.c 1.2
src/lib/libc/gdtoa/strtopdd.c 1.2
src/lib/libc/gdtoa/strtopf.c 1.2
src/lib/libc/gdtoa/strtordd.c 1.2
src/lib/libc/gdtoa/strtorf.c 1.2
src/lib/libc/gdtoa/sum.c 1.2
src/lib/libc/gdtoa/gdtoa.h 1.8
src/lib/libc/gdtoa/hdtoa.c 1.6
src/lib/libc/gdtoa/strtodg.c 1.6
src/lib/libc/stdio/vfwprintf.c 1.12
(requested by mjf ticket #1120).

Don't coredump on out of memory conditions. This solution leaks, but gdtoa
is too complicated to fix. Try printf %99999999999.9999999999f 2

Make this build again.
 1.9.2.1 07-May-2007  pavel branches: 1.9.2.1.2; 1.9.2.1.4;
Pull up following revision(s) (requested by manu in ticket #607):
lib/libc/arch/i386/gen/isnanl.c: revision 1.6
lib/libc/gdtoa/gdtoa.c: revision 1.2-1.3
lib/libc/arch/x86_64/gen/isnanl.c: revision 1.6
lib/libc/gdtoa/gdtoaimp.h: revision 1.6
sys/arch/m68k/include/ieee.h: revision 1.13
usr.bin/xlint/lint1/scan.l: revision 1.36-1.37
lib/libc/stdio/snprintf_ss.c: revision 1.4
lib/libc/arch/i386/gen/isfinitel.c: revision 1.2
lib/libc/stdio/vfscanf.c: revision 1.38
sys/arch/sparc/include/ieee.h: revision 1.11-1.12
lib/libc/gdtoa/dtoa.c: revision 1.4
lib/libc/stdio/Makefile.inc: revision 1.35
lib/libc/stdio/fvwrite.c: revision 1.17
lib/libc/arch/m68k/gen/fpclassifyl.c: revision 1.2
lib/libc/arch/i386/gen/isinfl.c: revision 1.6
lib/libc/arch/x86_64/gen/isinfl.c: revision 1.6
lib/libc/arch/x86_64/gen/isfinitel.c: revision 1.2
lib/libc/stdio/vfprintf.c: revision 1.55-1.57
lib/libc/stdio/vsnprintf_ss.c: revision 1.3
lib/libc/stdio/vfwprintf.c: revision 1.10
sys/arch/x86/include/ieee.h: revision 1.10
lib/libc/gdtoa/dmisc.c: revision 1.3
lib/libc/gdtoa/Makefile.inc: revision 1.5
sys/arch/hppa/include/ieee.h: revision 1.10
lib/libc/arch/x86_64/gen/fpclassifyl.c: revision 1.3
lib/libc/arch/i386/gen/fpclassifyl.c: revision 1.2
sys/sys/ieee754.h: revision 1.7
lib/libc/gdtoa/gdtoa.h: revision 1.7
include/stdio.h: revision 1.67-1.68
lib/libc/gdtoa/hdtoa.c: revision 1.1-1.4
lib/libc/gdtoa/ldtoa.c: revision 1.1-1.4
defined(_NETBSD_SOURCE) is equivalent to (!defined(_ANSI_SOURCE) &&
!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)), so there's no
need to check both of them.
Fix for issue reported in PR lib/35401 as well as related overflow bugs.
deal with hex doubles.
Instead of abusing stdio to get a signal-safe version of sprintf, provide one.
remove __SAFE
add long double and hex double support from freebsd.
make this compile.
add new prototypes.
add the new files to the build. Note I am not bumping libc now, because
these are not used yet.
Merge the int bit with the high fraction bit. Add constants/macros
needed by gdtoa.
add constants used by gdtoa
since the int bit is merged, do the explicit math.
ext_int bit is no more.
ext_int bit is no more.
- merge change from freebsd
- add support for building as vfprintf.c
- XXX: we strdup to simplify the freeing logic. This should be fixed for
efficiency in the vfprintf case.
use vfwprintf.c
enable wide doubles.
some int -> size_t
deal with sparc64 that has 112 bits of mantissa.
make extended precision gdtoa friendly.
int/size_t changes
make this gdtoa friendly.
remove dup definition
use dtoa() instead of returning empty when we don't have extended precision
information.
Fix previous, add forgotten pointer dereference in the call to dtoa().
Add a cheesy workaround marked XXX for the situation where the
strtod() implementation available in the environment does not
handle hex floats.
Discussed with and suggested by christos
From Christos: gdtoa fixes for m68k. M68k ports should build now, but
printing extended precision is a little off.
vax does not have <machine/ieee.h> or long double
It would be nice if the compiler provided something like __IEEE_MATH__
bring in FreeBSD's vfscanf() to gain multi-byte/collation support.
Unfortunately it is too difficult to make vfwscanf and this share
the same code like I did with printf, because for string parsing
the code is too different.
 1.9.2.1.4.2 11-May-2009  bouyer Pull up following revision(s) (requested by cube in ticket #1313):
lib/libc/stdio/vfwprintf.c: revision 1.15
printf("%zi\n", (ssize_t)-1); now correcly prints -1 on i386
ok: christos
 1.9.2.1.4.1 08-Apr-2008  jdc Pull up revisions:
src/lib/libc/gdtoa/dmisc.c 1.4
src/lib/libc/gdtoa/gdtoa.c 1.4
src/lib/libc/gdtoa/gethex.c 1.4
src/lib/libc/gdtoa/misc.c 1.4
src/lib/libc/gdtoa/strtof_vaxf.c 1.4-1.5
src/lib/libc/gdtoa/strtopQ.c 1.4
src/lib/libc/gdtoa/strtopx.c 1.4
src/lib/libc/gdtoa/strtopxL.c 1.4
src/lib/libc/gdtoa/strtord.c 1.4
src/lib/libc/gdtoa/dtoa.c 1.5
src/lib/libc/gdtoa/strtod.c 1.5
src/lib/libc/gdtoa/g_Qfmt.c 1.3
src/lib/libc/gdtoa/g_xLfmt.c 1.3
src/lib/libc/gdtoa/g_xfmt.c 1.3
src/lib/libc/gdtoa/smisc.c 1.3
src/lib/libc/gdtoa/strtof.c 1.3
src/lib/libc/gdtoa/strtorQ.c 1.3
src/lib/libc/gdtoa/strtorx.c 1.3
src/lib/libc/gdtoa/strtorxL.c 1.3
src/lib/libc/gdtoa/g_ddfmt.c 1.2
src/lib/libc/gdtoa/g_dfmt.c 1.2
src/lib/libc/gdtoa/g_ffmt.c 1.2
src/lib/libc/gdtoa/strtoIQ.c 1.2
src/lib/libc/gdtoa/strtoId.c 1.2
src/lib/libc/gdtoa/strtoIdd.c 1.2
src/lib/libc/gdtoa/strtoIf.c 1.2
src/lib/libc/gdtoa/strtoIg.c 1.2
src/lib/libc/gdtoa/strtoIx.c 1.2
src/lib/libc/gdtoa/strtoIxL.c 1.2
src/lib/libc/gdtoa/strtodI.c 1.2
src/lib/libc/gdtoa/strtodnrp.c 1.2
src/lib/libc/gdtoa/strtopd.c 1.2
src/lib/libc/gdtoa/strtopdd.c 1.2
src/lib/libc/gdtoa/strtopf.c 1.2
src/lib/libc/gdtoa/strtordd.c 1.2
src/lib/libc/gdtoa/strtorf.c 1.2
src/lib/libc/gdtoa/sum.c 1.2
src/lib/libc/gdtoa/gdtoa.h 1.8
src/lib/libc/gdtoa/hdtoa.c 1.6
src/lib/libc/gdtoa/strtodg.c 1.6
src/lib/libc/stdio/vfwprintf.c 1.12
(requested by mjf ticket #1120).

Don't coredump on out of memory conditions. This solution leaks, but gdtoa
is too complicated to fix. Try printf %99999999999.9999999999f 2

Make this build again.
 1.9.2.1.2.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.10.8.1 24-Mar-2008  keiichi sync with head.
 1.10.4.1 23-Mar-2008  matt sync with HEAD
 1.12.4.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.12.2.1 17-Jun-2008  yamt sync with head.
 1.13.6.2 05-Jun-2008  aymeric fix a "typo" which prevented %ls from working in printf() (NARROW case).
Among other things, nvi displays options correctly now.
 1.13.6.1 05-Jun-2008  aymeric file vfwprintf.c was added on branch christos-time_t on 2008-06-05 19:55:48 +0000
 1.13.4.2 05-Sep-2009  bouyer Pull up following revision(s) (requested by dsl in ticket #902):
lib/libc/stdio/vfwprintf.c: revision 1.16
If the current locale doesn't define the 'thousands' grouping info
then use sane defaults (',' every 3 digits).
Fixes PR/40714
 1.13.4.1 25-Feb-2009  snj branches: 1.13.4.1.2; 1.13.4.1.4;
Pull up following revision(s) (requested by roy in ticket #492):
lib/libc/stdio/vfwprintf.c: revision 1.15
printf("%zi\n", (ssize_t)-1); now correcly prints -1 on i386
ok: christos
 1.13.4.1.4.1 21-Apr-2010  matt sync to netbsd-5
 1.13.4.1.2.1 05-Sep-2009  bouyer Pull up following revision(s) (requested by dsl in ticket #902):
lib/libc/stdio/vfwprintf.c: revision 1.16
If the current locale doesn't define the 'thousands' grouping info
then use sane defaults (',' every 3 digits).
Fixes PR/40714
 1.14.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.24.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.24.2.1 17-Apr-2012  yamt sync with head
 1.30.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.30.2.1 23-Jun-2013  tls resync from head
 1.34.18.1 14-Mar-2018  bouyer Pull up following revision(s) (requested by martin in ticket #630):
lib/libc/stdio/vfwprintf.c: revision 1.35
lib/libc/stdio/vfwprintf.c: revision 1.36
tests/lib/libc/locale/t_sprintf.c: revision 1.2
Change t_sprintf to an expected failure, since we don't respect the empty
thousands separator of the C/POSIX locale (PR standards/52282).
Do not use thousands grouping when none is specified by the locale.
Fixes PR standards/52282.
A more correct fix for PR standards/52282.
 1.36.8.1 22-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1865):

lib/libc/stdio/Makefile.inc: revision 1.48
tests/lib/libc/stdio/t_printf.c: revision 1.9
lib/libc/stdio/vfwprintf.c: revision 1.40
lib/libc/include/extern.h: revision 1.27
tests/lib/libc/stdio/t_printf.c: revision 1.10

PR/57250: Martin Husemann: dtoa mishandles infinite doubles on 32bit big
endian machines. When long double support was added, the old code was kept
for the regular double code. This code was never used because WIDE_DOUBLE
was always defined in the Makefile. Remove that old code, and conditionalize
the WIDE_DOUBLE code based on if long doubles are different than doubles on
the specific platform.

Add a test for PR/57250 from Havard Eidnes

Fix the test for "inf" output, also include newline in printf format...
 1.39.2.1 17-Apr-2023  martin Pull up following revision(s) (requested by he in ticket #137):

lib/libc/stdio/Makefile.inc: revision 1.48
lib/libc/stdio/vfwprintf.c: revision 1.40
lib/libc/include/extern.h: revision 1.27

PR/57250: Martin Husemann: dtoa mishandles infinite doubles on 32bit big
endian machines. When long double support was added, the old code was kept
for the regular double code. This code was never used because WIDE_DOUBLE
was always defined in the Makefile. Remove that old code, and conditionalize
the WIDE_DOUBLE code based on if long doubles are different than doubles on
the specific platform.
 1.13 19-Apr-2022  rillig lib: remove CONSTCOND comment

Since 2021-01-31, lint doesn't need it anymore for the common pattern of
'do ... while (0)'.
 1.12 12-Jun-2014  justin gcc cannot always work out initialization here
 1.11 23-Sep-2013  pooka branches: 1.11.2;
Make compile with -DNO_FLOATING_POINT
 1.10 17-May-2013  joerg Provide explicit LC_C_LOCALE accessor and drop the various NULL checks.
Provide LC_GLOBAL_LOCALE in a way that works with all locale functions.
Merge constant data used by the initial global locale and the C locale.
Drop function call layer for _current_locale() and directly return the
locale reference, not a pointer to it. Use protected access for global
variables, so that libc references can avoid the GOT overhead.
 1.9 19-Apr-2013  joerg Add scanf_l and wscanf_l families.
 1.8 15-Mar-2012  christos branches: 1.8.2;
- ansify, knf.
- no functional changes
 1.7 13-Mar-2012  christos PR/45989: Martin Husemann: lint invocation does include -w only on i386

- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
builds)

approved by core@
 1.6 21-Feb-2009  christos branches: 1.6.6;
fix sign comparison warning in debug build.
 1.5 11-Jan-2009  christos branches: 1.5.2;
merge christos-time_t
 1.4 16-Nov-2008  christos PR/39347: floating and long double conversions were ifdef'ed out because
we did not have wcstold and wcstof back then. But this was done incorrectly
because we did not move the argument vector. Enable them now.
 1.3 28-Aug-2008  christos branches: 1.3.6;
Ignore whitespace in format string from Andy Shevchenko
 1.2 12-Jun-2005  lukem branches: 1.2.20;
Appease gcc -Wuninitialized
 1.1 14-May-2005  christos Add the missing wide char support functions from freebsd.
XXX: long double support is missing until we get gdtoa, and add the
necessary wide functions.
 1.2.20.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.3.6.2 04-Jan-2009  christos merge with head.
 1.3.6.1 28-Aug-2008  christos file vfwscanf.c was added on branch christos-time_t on 2009-01-04 17:02:20 +0000
 1.5.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.6.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6.6.1 17-Apr-2012  yamt sync with head
 1.8.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.8.2.1 23-Jun-2013  tls resync from head
 1.11.2.1 10-Aug-2014  tls Rebase.
 1.14 04-Feb-2018  mrg fixes for GCC 6:

- -Wstrict-prototypes is not available for C++, so don't try to
ignore it for C++.
- remove many _DIAGASSERT() checks against not NULL for functions
with arguments with nonnull attributes. in two cases, leave
code behind that should set defaults to "(null)".
- use -Wno-error=frame-address for i386 mcount, as it seems valid
to assume the caller will have a frame.fair
 1.13 19-Apr-2013  joerg Add explicit locale versions for the printf family. Replace asprintf,
snprintf and sprintf with simple wrappers around the corresponding
va_list functions to reduce code duplication.
 1.12 15-Mar-2012  christos branches: 1.12.2;
- ansify, knf.
- no functional changes
 1.11 17-Jul-2011  joerg branches: 1.11.2;
Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.10 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.9 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.8 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.7 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.6 29-Mar-1996  jtc Add explict function return types
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 22-May-1994  cgd _VA_LIST_ -> _BSD_VA_LIST_
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.11.2.1 17-Apr-2012  yamt sync with head
 1.12.2.1 23-Jun-2013  tls resync from head
 1.16 04-Feb-2018  mrg fixes for GCC 6:

- -Wstrict-prototypes is not available for C++, so don't try to
ignore it for C++.
- remove many _DIAGASSERT() checks against not NULL for functions
with arguments with nonnull attributes. in two cases, leave
code behind that should set defaults to "(null)".
- use -Wno-error=frame-address for i386 mcount, as it seems valid
to assume the caller will have a frame.fair
 1.15 19-Apr-2013  joerg Add scanf_l and wscanf_l families.
 1.14 15-Mar-2012  christos branches: 1.14.2;
- ansify, knf.
- no functional changes
 1.13 17-Jul-2011  joerg branches: 1.13.2;
Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.12 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.11 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.10 24-May-2002  thorpej * Move the prototype of __svfscanf from <stdio.h> to libc/stdio/local.h.
* Add prototype for vfscanf to <stdio.h>.
* Remove #define of vfscanf to __svfscanf from <stdio.h>.
* Include local.h in libc files which need __svfscanf.
* Add vfscanf weak alias to __svfscanf.

Fixes standards/16997.

NOTE: libc minor not bumped -- ride on the bump to 12.84 made by
itojun today.
 1.9 20-Sep-1999  lukem branches: 1.9.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.8 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.7 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.6 29-Mar-1996  jtc Add explict function return types
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 22-May-1994  cgd _VA_LIST_ -> _BSD_VA_LIST_
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9.10.2 22-Jun-2002  thorpej Need "reentrant.h"
 1.9.10.1 21-Jun-2002  nathanw Catch up to -current.
 1.13.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.13.2.1 17-Apr-2012  yamt sync with head
 1.14.2.1 23-Jun-2013  tls resync from head
 1.29 12-Jan-2017  christos undo SSP damage from -Wsystem-headers
 1.28 29-Sep-2014  christos branches: 1.28.2;
Return EOVERFLOW like FreeBSD does if the buffer size exceeds INT_MAX
(well FreeBSD documents INT_MAX + 1, but in the code it is INT_MAX).
 1.27 17-May-2013  joerg branches: 1.27.6;
Provide explicit LC_C_LOCALE accessor and drop the various NULL checks.
Provide LC_GLOBAL_LOCALE in a way that works with all locale functions.
Merge constant data used by the initial global locale and the C locale.
Drop function call layer for _current_locale() and directly return the
locale reference, not a pointer to it. Use protected access for global
variables, so that libc references can avoid the GOT overhead.
 1.26 19-Apr-2013  joerg Add explicit locale versions for the printf family. Replace asprintf,
snprintf and sprintf with simple wrappers around the corresponding
va_list functions to reduce code duplication.
 1.25 15-Mar-2012  christos branches: 1.25.2;
- ansify, knf.
- no functional changes
 1.24 13-Mar-2012  christos PR/45989: Martin Husemann: lint invocation does include -w only on i386

- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
builds)

approved by core@
 1.23 17-Jul-2011  joerg branches: 1.23.2; 1.23.4;
Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.22 26-Oct-2007  christos make _FORTIFY_SOURCE play nicely with lint
 1.21 03-Jun-2007  christos branches: 1.21.4;
Make these work with _FORTIFY_SOURCE, by overriding the fortified definitions
 1.20 09-Feb-2005  kleink A little libc namespace housekeeping exercise:
* Make vfprintf_unlocked() an internal function, c.f. __svfscanf_unlocked().
* Add internal names for arc4random(), endnetpath(), fhstatvfs(),
fstatvfs(), mkstemp(), shquote(), statvfs(), taddr2uaddr(), uaddr2taddr(),
uuid_create_nil(), uuid_is_nil(), and wcwidth().
* Include namespace.h where supposed to.
 1.19 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.18 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.17 05-Jan-2003  kristerw Fix two bugs:

1. snprintf(foo, 0. "XXX") is guaranteed not to write in foo by the
standard (ISO/IEC 9899 7.19.6.5) but our implementation handles this
as if the buffer has a size of (size_t)-1.

2. snprintf(NULL, 0, "XXX") leaks memory since cantwrite() allocates
memory if _bf._base == NULL, and this buffer is never freed
(PR 16483).
 1.16 07-Dec-2001  yamt branches: 1.16.2;
- make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.15 19-Oct-2000  kleink branches: 1.15.2;
Actually EINVAL fits the circumstances better.
 1.14 19-Oct-2000  kleink C99: Passing a null pointer as the buffer argument to snprintf() and
vsnprintf() is permitted when the size argument is zero as well; mostly
from Peter Seebach in PR standards/9603.
 1.13 22-Jan-2000  mycroft branches: 1.13.4;
Delint.
Remove trailing ; from uses of __weak_alias(). The macro inserts this if
needed.
 1.12 21-Jan-2000  mycroft Initialize f._file for locking primitives.
 1.11 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.10 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.9 13-Oct-1998  kleink Need internal names for snprintf() and vsnprintf().
 1.8 19-Dec-1997  kleink Change several functions to return -1 instead of EOF, which was semantically
wrong.
 1.7 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.6 29-Mar-1996  jtc Add explict function return types
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 22-May-1994  cgd _VA_LIST_ -> _BSD_VA_LIST_
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.13.4.1 19-Oct-2000  he Pull up revisions 1.14-1.15 (requested by kleink):
C99 alignment: a buffer size of 0 is permitted. Also, when
size is 0, a null buffer pointer may be passed. Fixes PR#9603.
 1.15.2.4 08-Jan-2003  thorpej Sync with HEAD.
 1.15.2.3 07-May-2002  nathanw One more routine to use vfprintf_unlocked()
 1.15.2.2 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.15.2.1 28-Jan-2002  nathanw Catch up to -current.
 1.16.2.1 10-Jan-2003  jmc Pull up revisions 1.16-1.17 (requested by kristerw in ticket #1059)
Fix two bugs:
1. snprintf(foo, 0. XXX) is guaranteed not to write in foo by the
standard (ISO/IEC 9899 7.19.6.5) but our implementation handles this
as if the buffer has a size of (size_t)-1.
2. snprintf(NULL, 0, XXX) leaks memory since cantwrite() allocates
memory if _bf._base == NULL, and this buffer is never freed
(PR 16483).
 1.21.4.1 06-Nov-2007  matt sync with HEAD
 1.23.4.1 03-Nov-2014  msaitoh Pull up following revision(s) (requested by christos in ticket #1161):
lib/libc/stdio/printf.3: revision 1.64 via patch
lib/libc/stdio/vsnprintf.c: revision 1.28 via patch
lib/libc/stdio/vsnprintf_ss.c: revision 1.13 via patch
Return EOVERFLOW like FreeBSD does if the buffer size exceeds INT_MAX
(well FreeBSD documents INT_MAX + 1, but in the code it is INT_MAX).
Return EOVERFLOW like FreeBSD does if the buffer size exceeds INT_MAX
(well FreeBSD documents INT_MAX + 1, but in the code it is INT_MAX).
 1.23.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.23.2.1 17-Apr-2012  yamt sync with head
 1.25.2.1 23-Jun-2013  tls resync from head
 1.27.6.1 30-Sep-2014  martin Pull up following revision(s) (requested by christos in ticket #122):
lib/libc/stdio/printf.3: revision 1.64
lib/libc/stdio/vsnprintf.c: revision 1.28
lib/libc/stdio/vsnprintf_ss.c: revision 1.13
Return EOVERFLOW like FreeBSD does if the buffer size exceeds INT_MAX
(well FreeBSD documents INT_MAX + 1, but in the code it is INT_MAX).
 1.28.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.14 19-Apr-2022  rillig lib: remove CONSTCOND comment

Since 2021-01-31, lint doesn't need it anymore for the common pattern of
'do ... while (0)'.
 1.13 29-Sep-2014  christos Return EOVERFLOW like FreeBSD does if the buffer size exceeds INT_MAX
(well FreeBSD documents INT_MAX + 1, but in the code it is INT_MAX).
 1.12 15-Mar-2012  christos branches: 1.12.10;
- ansify, knf.
- no functional changes
 1.11 13-Mar-2012  christos PR/45989: Martin Husemann: lint invocation does include -w only on i386

- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
builds)

approved by core@
 1.10 17-Jul-2011  joerg branches: 1.10.2; 1.10.4;
Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.9 17-Dec-2009  christos PR/42466: Yasuoka Masahiko: vsnprintf_ss() causes infinite loop
 1.8 25-Oct-2009  christos revert some of dsl's changes to make things build on i386; he can undo what
he wants when he comes back.
 1.7 24-Oct-2009  dsl Remove a load of pointless casts - one that even lint doesn't bleat about.
 1.6 03-Feb-2007  christos chech the correct fmt in the assertion.
 1.5 03-Feb-2007  christos the buffer len is called slen.
 1.4 03-Feb-2007  christos protect buffer size from overflow.
 1.3 02-Feb-2007  christos Instead of abusing stdio to get a signal-safe version of sprintf, provide one.
 1.2 22-Nov-2006  christos branches: 1.2.2;
Don't expose _ss functions for 4.0. Requested by core.
 1.1 27-Oct-2006  christos Add signal-safe versions of snprintf and vsnprintf
 1.2.2.1 07-May-2007  pavel Pull up following revision(s) (requested by manu in ticket #607):
lib/libc/arch/i386/gen/isnanl.c: revision 1.6
lib/libc/gdtoa/gdtoa.c: revision 1.2-1.3
lib/libc/arch/x86_64/gen/isnanl.c: revision 1.6
lib/libc/gdtoa/gdtoaimp.h: revision 1.6
sys/arch/m68k/include/ieee.h: revision 1.13
usr.bin/xlint/lint1/scan.l: revision 1.36-1.37
lib/libc/stdio/snprintf_ss.c: revision 1.4
lib/libc/arch/i386/gen/isfinitel.c: revision 1.2
lib/libc/stdio/vfscanf.c: revision 1.38
sys/arch/sparc/include/ieee.h: revision 1.11-1.12
lib/libc/gdtoa/dtoa.c: revision 1.4
lib/libc/stdio/Makefile.inc: revision 1.35
lib/libc/stdio/fvwrite.c: revision 1.17
lib/libc/arch/m68k/gen/fpclassifyl.c: revision 1.2
lib/libc/arch/i386/gen/isinfl.c: revision 1.6
lib/libc/arch/x86_64/gen/isinfl.c: revision 1.6
lib/libc/arch/x86_64/gen/isfinitel.c: revision 1.2
lib/libc/stdio/vfprintf.c: revision 1.55-1.57
lib/libc/stdio/vsnprintf_ss.c: revision 1.3
lib/libc/stdio/vfwprintf.c: revision 1.10
sys/arch/x86/include/ieee.h: revision 1.10
lib/libc/gdtoa/dmisc.c: revision 1.3
lib/libc/gdtoa/Makefile.inc: revision 1.5
sys/arch/hppa/include/ieee.h: revision 1.10
lib/libc/arch/x86_64/gen/fpclassifyl.c: revision 1.3
lib/libc/arch/i386/gen/fpclassifyl.c: revision 1.2
sys/sys/ieee754.h: revision 1.7
lib/libc/gdtoa/gdtoa.h: revision 1.7
include/stdio.h: revision 1.67-1.68
lib/libc/gdtoa/hdtoa.c: revision 1.1-1.4
lib/libc/gdtoa/ldtoa.c: revision 1.1-1.4
defined(_NETBSD_SOURCE) is equivalent to (!defined(_ANSI_SOURCE) &&
!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)), so there's no
need to check both of them.
Fix for issue reported in PR lib/35401 as well as related overflow bugs.
deal with hex doubles.
Instead of abusing stdio to get a signal-safe version of sprintf, provide one.
remove __SAFE
add long double and hex double support from freebsd.
make this compile.
add new prototypes.
add the new files to the build. Note I am not bumping libc now, because
these are not used yet.
Merge the int bit with the high fraction bit. Add constants/macros
needed by gdtoa.
add constants used by gdtoa
since the int bit is merged, do the explicit math.
ext_int bit is no more.
ext_int bit is no more.
- merge change from freebsd
- add support for building as vfprintf.c
- XXX: we strdup to simplify the freeing logic. This should be fixed for
efficiency in the vfprintf case.
use vfwprintf.c
enable wide doubles.
some int -> size_t
deal with sparc64 that has 112 bits of mantissa.
make extended precision gdtoa friendly.
int/size_t changes
make this gdtoa friendly.
remove dup definition
use dtoa() instead of returning empty when we don't have extended precision
information.
Fix previous, add forgotten pointer dereference in the call to dtoa().
Add a cheesy workaround marked XXX for the situation where the
strtod() implementation available in the environment does not
handle hex floats.
Discussed with and suggested by christos
From Christos: gdtoa fixes for m68k. M68k ports should build now, but
printing extended precision is a little off.
vax does not have <machine/ieee.h> or long double
It would be nice if the compiler provided something like __IEEE_MATH__
bring in FreeBSD's vfscanf() to gain multi-byte/collation support.
Unfortunately it is too difficult to make vfwscanf and this share
the same code like I did with printf, because for string parsing
the code is too different.
 1.10.4.1 03-Nov-2014  msaitoh Pull up following revision(s) (requested by christos in ticket #1161):
lib/libc/stdio/printf.3: revision 1.64 via patch
lib/libc/stdio/vsnprintf.c: revision 1.28 via patch
lib/libc/stdio/vsnprintf_ss.c: revision 1.13 via patch
Return EOVERFLOW like FreeBSD does if the buffer size exceeds INT_MAX
(well FreeBSD documents INT_MAX + 1, but in the code it is INT_MAX).
Return EOVERFLOW like FreeBSD does if the buffer size exceeds INT_MAX
(well FreeBSD documents INT_MAX + 1, but in the code it is INT_MAX).
 1.10.2.1 17-Apr-2012  yamt sync with head
 1.12.10.1 30-Sep-2014  martin Pull up following revision(s) (requested by christos in ticket #122):
lib/libc/stdio/printf.3: revision 1.64
lib/libc/stdio/vsnprintf.c: revision 1.28
lib/libc/stdio/vsnprintf_ss.c: revision 1.13
Return EOVERFLOW like FreeBSD does if the buffer size exceeds INT_MAX
(well FreeBSD documents INT_MAX + 1, but in the code it is INT_MAX).
 1.19 17-May-2013  joerg Provide explicit LC_C_LOCALE accessor and drop the various NULL checks.
Provide LC_GLOBAL_LOCALE in a way that works with all locale functions.
Merge constant data used by the initial global locale and the C locale.
Drop function call layer for _current_locale() and directly return the
locale reference, not a pointer to it. Use protected access for global
variables, so that libc references can avoid the GOT overhead.
 1.18 19-Apr-2013  joerg Add explicit locale versions for the printf family. Replace asprintf,
snprintf and sprintf with simple wrappers around the corresponding
va_list functions to reduce code duplication.
 1.17 15-Mar-2012  christos branches: 1.17.2;
- ansify, knf.
- no functional changes
 1.16 17-Jul-2011  joerg branches: 1.16.2;
Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.15 03-Jun-2007  christos Make these work with _FORTIFY_SOURCE, by overriding the fortified definitions
 1.14 09-Feb-2005  kleink A little libc namespace housekeeping exercise:
* Make vfprintf_unlocked() an internal function, c.f. __svfscanf_unlocked().
* Add internal names for arc4random(), endnetpath(), fhstatvfs(),
fstatvfs(), mkstemp(), shquote(), statvfs(), taddr2uaddr(), uaddr2taddr(),
uuid_create_nil(), uuid_is_nil(), and wcwidth().
* Include namespace.h where supposed to.
 1.13 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.12 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.11 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.10 21-Jan-2000  mycroft branches: 1.10.6;
Initialize f._file for locking primitives.
 1.9 20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.8 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.7 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.6 29-Mar-1996  jtc Add explict function return types
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 22-May-1994  cgd _VA_LIST_ -> _BSD_VA_LIST_
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.10.6.3 02-May-2002  nathanw Call the _unlocked versions of vfprintf() and __svfscanf(); there's no point
in locking and unlocking a FILE object that only exists in the local scope.
This also has the nice side effect of making sprintf() usable for debugging
threaded code.
 1.10.6.2 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.10.6.1 28-Jan-2002  nathanw Catch up to -current.
 1.16.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.16.2.1 17-Apr-2012  yamt sync with head
 1.17.2.1 23-Jun-2013  tls resync from head
 1.21 17-May-2013  joerg Provide explicit LC_C_LOCALE accessor and drop the various NULL checks.
Provide LC_GLOBAL_LOCALE in a way that works with all locale functions.
Merge constant data used by the initial global locale and the C locale.
Drop function call layer for _current_locale() and directly return the
locale reference, not a pointer to it. Use protected access for global
variables, so that libc references can avoid the GOT overhead.
 1.20 19-Apr-2013  joerg Add scanf_l and wscanf_l families.
 1.19 27-Mar-2012  christos branches: 1.19.2;
- widen the internal read and write calls to match the syscalls
- add funopen2() which provides access to flush() and the wider calls.
- make use of the new flush call in fmemopen()
 1.18 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.17 13-Mar-2012  christos PR/45989: Martin Husemann: lint invocation does include -w only on i386

- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
builds)

approved by core@
 1.16 17-Jul-2011  joerg branches: 1.16.2;
Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.15 11-Jan-2010  joerg Use a proper char */size_t pair in __sfileext to keep track of the line
buffer for fgetln and fgetwln. Simplifies code by dropping the INT_MAX
related logic. Drop conditionals around FREELB, free(NULL) is valid.
 1.14 29-Nov-2005  christos WARNS=4
 1.13 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.12 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.11 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.10 20-Sep-1999  lukem branches: 1.10.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.9 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.8 15-Nov-1998  christos delint
 1.7 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.6 29-Mar-1996  jtc Add explict function return types
 1.5 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.4 22-May-1994  cgd _VA_LIST_ -> _BSD_VA_LIST_
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.10.10.5 02-May-2002  nathanw Call the _unlocked versions of vfprintf() and __svfscanf(); there's no point
in locking and unlocking a FILE object that only exists in the local scope.
This also has the nice side effect of making sprintf() usable for debugging
threaded code.
 1.10.10.4 07-Feb-2002  nathanw Revert previous; this will be done a different way.
 1.10.10.3 07-Feb-2002  nathanw sscanf() and vsscanf() construct private FILE structures; be sure to
initialize the flockfile() locks there, too.
 1.10.10.2 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.10.10.1 28-Jan-2002  nathanw Catch up to -current.
 1.16.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.16.2.1 17-Apr-2012  yamt sync with head
 1.19.2.1 23-Jun-2013  tls resync from head
 1.6 19-May-2013  christos don't cast malloc
 1.5 17-May-2013  joerg Provide explicit LC_C_LOCALE accessor and drop the various NULL checks.
Provide LC_GLOBAL_LOCALE in a way that works with all locale functions.
Merge constant data used by the initial global locale and the C locale.
Drop function call layer for _current_locale() and directly return the
locale reference, not a pointer to it. Use protected access for global
variables, so that libc references can avoid the GOT overhead.
 1.4 19-Apr-2013  joerg Add explicit locale versions for the printf family. Replace asprintf,
snprintf and sprintf with simple wrappers around the corresponding
va_list functions to reduce code duplication.
 1.3 15-Mar-2012  christos branches: 1.3.2;
- ansify, knf.
- no functional changes
 1.2 17-Aug-2011  christos branches: 1.2.2;
fix the rest of libc mi gcc-4.5 hacks. portmasters should fix the md ones.
 1.1 14-May-2005  christos Add the missing wide char support functions from freebsd.
XXX: long double support is missing until we get gdtoa, and add the
necessary wide functions.
 1.2.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.2.1 17-Apr-2012  yamt sync with head
 1.3.2.1 23-Jun-2013  tls resync from head
 1.12 17-May-2013  joerg Provide explicit LC_C_LOCALE accessor and drop the various NULL checks.
Provide LC_GLOBAL_LOCALE in a way that works with all locale functions.
Merge constant data used by the initial global locale and the C locale.
Drop function call layer for _current_locale() and directly return the
locale reference, not a pointer to it. Use protected access for global
variables, so that libc references can avoid the GOT overhead.
 1.11 22-Apr-2013  joerg Add new line at the end.
 1.10 19-Apr-2013  joerg Add scanf_l and wscanf_l families.
 1.9 27-Mar-2012  christos branches: 1.9.2;
- widen the internal read and write calls to match the syscalls
- add funopen2() which provides access to flush() and the wider calls.
- make use of the new flush call in fmemopen()
 1.8 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.7 13-Mar-2012  christos PR/45989: Martin Husemann: lint invocation does include -w only on i386

- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
builds)

approved by core@
 1.6 11-Jan-2010  joerg branches: 1.6.6;
Use a proper char */size_t pair in __sfileext to keep track of the line
buffer for fgetln and fgetwln. Simplifies code by dropping the INT_MAX
related logic. Drop conditionals around FREELB, free(NULL) is valid.
 1.5 11-Jan-2009  christos merge christos-time_t
 1.4 16-Nov-2008  christos Nobody tested this? Initialize wcio for wide char i/o.
NB: Pullup to 5.0.
 1.3 02-Dec-2005  yamt branches: 1.3.26; 1.3.28;
remove an unnecessary __UNCONST.
 1.2 29-Nov-2005  christos WARNS=4
 1.1 14-May-2005  christos Add the missing wide char support functions from freebsd.
XXX: long double support is missing until we get gdtoa, and add the
necessary wide functions.
 1.3.28.1 04-Jan-2009  christos merge with head.
 1.3.26.1 13-Dec-2008  bouyer Pull up following revision(s) (requested by tsutsui in ticket #180):
lib/libc/stdio/vswscanf.c: revision 1.4
Nobody tested this? Initialize wcio for wide char i/o.
NB: Pullup to 5.0.
 1.6.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6.6.1 17-Apr-2012  yamt sync with head
 1.9.2.1 23-Jun-2013  tls resync from head
 1.3 19-Apr-2013  joerg Add explicit locale versions for the printf family. Replace asprintf,
snprintf and sprintf with simple wrappers around the corresponding
va_list functions to reduce code duplication.
 1.2 15-Mar-2012  christos branches: 1.2.2;
- ansify, knf.
- no functional changes
 1.1 14-May-2005  christos branches: 1.1.44;
Add the missing wide char support functions from freebsd.
XXX: long double support is missing until we get gdtoa, and add the
necessary wide functions.
 1.1.44.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.44.1 17-Apr-2012  yamt sync with head
 1.2.2.1 23-Jun-2013  tls resync from head
 1.3 19-Apr-2013  joerg Add scanf_l and wscanf_l families.
 1.2 15-Mar-2012  christos branches: 1.2.2;
- ansify, knf.
- no functional changes
 1.1 14-May-2005  christos branches: 1.1.44;
Add the missing wide char support functions from freebsd.
XXX: long double support is missing until we get gdtoa, and add the
necessary wide functions.
 1.1.44.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.44.1 17-Apr-2012  yamt sync with head
 1.2.2.1 23-Jun-2013  tls resync from head
 1.15 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.14 13-Mar-2012  christos PR/45989: Martin Husemann: lint invocation does include -w only on i386

- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
builds)

approved by core@
 1.13 07-Aug-2003  agc branches: 1.13.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.12 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.11 07-Dec-2001  yamt - make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.
 1.10 20-Sep-1999  lukem branches: 1.10.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.9 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.8 03-Feb-1998  perry remove obsolete register declarations
 1.7 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.6 03-May-1997  kleink Upon an attempt to write to a stream that can't be written to, set errno
to EBADF.
 1.5 29-Mar-1996  jtc Add explict function return types
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.10.10.2 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.10.10.1 28-Jan-2002  nathanw Catch up to -current.
 1.13.56.1 17-Apr-2012  yamt sync with head
 1.4 19-Apr-2022  rillig lib: remove CONSTCOND comment

Since 2021-01-31, lint doesn't need it anymore for the common pattern of
'do ... while (0)'.
 1.3 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.2 07-Dec-2001  yamt branches: 1.2.2;
g/c #if 0.
 1.1 07-Dec-2001  yamt add files forgotten in my previous commit.
 1.2.2.2 28-Jan-2002  nathanw Catch up to -current.
 1.2.2.1 07-Dec-2001  nathanw file wcio.h was added on branch nathanw_sa on 2002-01-28 20:51:16 +0000
 1.9 16-Feb-2021  riastradh Correct floating-point terminology.

Might want to harmonize the printf(3) and wprintf(3) descriptions of
`%a'.
 1.8 16-Dec-2010  wiz Observe the following spelling:
- wide character (noun)
- wide-character (adjective)

Inspired by jmc@OpenBSD.
 1.7 30-Apr-2010  jruoho Put SECURITY CONSIDERATIONS as the last section.
 1.6 30-Apr-2010  jruoho Fix the mess in the sections; someone went to sleep in the middle of a
sentence...
 1.5 05-Apr-2010  joerg Fix escape sequences
 1.4 11-Jan-2009  christos merge christos-time_t
 1.3 11-Dec-2008  yamt move a description of return values into the RETURN VALUES section.
 1.2 03-Jun-2005  wiz branches: 1.2.28;
Sort options.
 1.1 14-May-2005  christos Add the missing wide char support functions from freebsd.
XXX: long double support is missing until we get gdtoa, and add the
necessary wide functions.
 1.2.28.1 04-Jan-2009  christos merge with head.
 1.3 19-Apr-2013  joerg Add explicit locale versions for the printf family. Replace asprintf,
snprintf and sprintf with simple wrappers around the corresponding
va_list functions to reduce code duplication.
 1.2 15-Mar-2012  christos branches: 1.2.2;
- ansify, knf.
- no functional changes
 1.1 14-May-2005  christos branches: 1.1.44;
Add the missing wide char support functions from freebsd.
XXX: long double support is missing until we get gdtoa, and add the
necessary wide functions.
 1.1.44.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.44.1 17-Apr-2012  yamt sync with head
 1.2.2.1 23-Jun-2013  tls resync from head
 1.3 16-Dec-2010  wiz Observe the following spelling:
- wide character (noun)
- wide-character (adjective)

Inspired by jmc@OpenBSD.
 1.2 14-May-2010  joerg Fix markup
 1.1 14-May-2005  christos Add the missing wide char support functions from freebsd.
XXX: long double support is missing until we get gdtoa, and add the
necessary wide functions.
 1.3 19-Apr-2013  joerg Add scanf_l and wscanf_l families.
 1.2 15-Mar-2012  christos branches: 1.2.2;
- ansify, knf.
- no functional changes
 1.1 14-May-2005  christos branches: 1.1.44;
Add the missing wide char support functions from freebsd.
XXX: long double support is missing until we get gdtoa, and add the
necessary wide functions.
 1.1.44.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.44.1 17-Apr-2012  yamt sync with head
 1.2.2.1 23-Jun-2013  tls resync from head
 1.12 15-Mar-2012  christos - ansify, knf.
- no functional changes
 1.11 07-Aug-2003  agc branches: 1.11.56;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.10 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.9 20-Sep-1999  lukem branches: 1.9.10;
back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.8 16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.7 03-Feb-1998  perry remove obsolete register declarations
 1.6 13-Jul-1997  christos Fix RCSID's
Fix gcc warnings.
Add prototypes for functions that were declared in more than one place
to local.h or extern.h and use that instead.
 1.5 29-Mar-1996  jtc Add explict function return types
 1.4 02-Feb-1995  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.3 26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 02-Feb-1995  jtc imported from 44lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9.10.1 06-Feb-2002  nathanw #include "reentrant.h" before "local.h" so that the thread types used
in fileext.h are avaliable.
 1.11.56.1 17-Apr-2012  yamt sync with head

RSS XML Feed