summaryrefslogtreecommitdiff
path: root/usr/src/man/man3c
diff options
context:
space:
mode:
authorJerry Jelinek <jerry.jelinek@joyent.com>2020-03-27 11:29:00 +0000
committerJerry Jelinek <jerry.jelinek@joyent.com>2020-03-27 11:29:00 +0000
commit6dcfbbc68f881fbf5c20d25817a0221dfb135170 (patch)
tree40307666f6d7711499061d8c4be75029a6d851e9 /usr/src/man/man3c
parentb0624b90ec9a0c04cca626925beee3ae403457ce (diff)
parentcd62a92d4a964bfe61d35ba2301b69e65e22a509 (diff)
downloadillumos-joyent-6dcfbbc68f881fbf5c20d25817a0221dfb135170.tar.gz
[illumos-gate merge]
commit cd62a92d4a964bfe61d35ba2301b69e65e22a509 7092 Want support for stdio memory streams 12360 fwrite can loop forever on zero byte write 12392 ftello64 doesn't handle ungetc() correctly when unbuffered commit 1470234269f4edea4cbf270cb2475e4988b788d5 12359 Want a means to set the umem mtbf at runtine commit 0ac311bae7f6f50d9ba506b52bd8860f2d68d4ce 12358 Need mbrtowc variant that indicates consumed zero bytes commit d726994754c938f91b6fd7e96b5cab3829615c58 12357 getc/putc_unlocked need to set orientation
Diffstat (limited to 'usr/src/man/man3c')
-rw-r--r--usr/src/man/man3c/Makefile5
-rw-r--r--usr/src/man/man3c/fclose.3c10
-rw-r--r--usr/src/man/man3c/ferror.3c177
-rw-r--r--usr/src/man/man3c/fflush.3c15
-rw-r--r--usr/src/man/man3c/fmemopen.3c222
-rw-r--r--usr/src/man/man3c/fputc.3c14
-rw-r--r--usr/src/man/man3c/fputwc.3c19
-rw-r--r--usr/src/man/man3c/freopen.3c16
-rw-r--r--usr/src/man/man3c/fseek.3c34
-rw-r--r--usr/src/man/man3c/ftell.3c36
-rw-r--r--usr/src/man/man3c/fwrite.3c24
-rw-r--r--usr/src/man/man3c/open_memstream.3c195
-rw-r--r--usr/src/man/man3c/stdio.3c26
13 files changed, 608 insertions, 185 deletions
diff --git a/usr/src/man/man3c/Makefile b/usr/src/man/man3c/Makefile
index c1eb9bbbde..726125d3e9 100644
--- a/usr/src/man/man3c/Makefile
+++ b/usr/src/man/man3c/Makefile
@@ -140,6 +140,7 @@ MANFILES= __fbufsize.3c \
floating_to_decimal.3c \
flock.3c \
flockfile.3c \
+ fmemopen.3c \
fmtmsg.3c \
fnmatch.3c \
fopen.3c \
@@ -271,6 +272,7 @@ MANFILES= __fbufsize.3c \
newlocale.3c \
nl_langinfo.3c \
offsetof.3c \
+ open_memstream.3c \
opendir.3c \
perror.3c \
pfmt.3c \
@@ -1054,6 +1056,7 @@ MANLINKS= FD_CLR.3c \
ntohl.3c \
ntohll.3c \
ntohs.3c \
+ open_wmemstream.3c \
openlog.3c \
pclose.3c \
port_dissociate.3c \
@@ -2081,6 +2084,8 @@ freelocale.3c := LINKSRC = newlocale.3c
nl_langinfo_l.3c := LINKSRC = nl_langinfo.3c
+open_wmemstream.3c := LINKSRC = open_memstream.3c
+
fdopendir.3c := LINKSRC = opendir.3c
errno.3c := LINKSRC = perror.3c
diff --git a/usr/src/man/man3c/fclose.3c b/usr/src/man/man3c/fclose.3c
index 6d30cb6afe..3b48527eb9 100644
--- a/usr/src/man/man3c/fclose.3c
+++ b/usr/src/man/man3c/fclose.3c
@@ -44,11 +44,10 @@
.\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
.\" Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved.
.\"
-.TH FCLOSE 3C "Nov 1, 2003"
+.TH FCLOSE 3C "March 25, 2020"
.SH NAME
fclose \- close a stream
.SH SYNOPSIS
-.LP
.nf
#include <stdio.h>
@@ -56,7 +55,6 @@ fclose \- close a stream
.fi
.SH DESCRIPTION
-.LP
The \fBfclose()\fR function causes the stream pointed to by \fIstream\fR to be
flushed and the associated file to be closed. Any unwritten buffered data for
the stream is written to the file; any unread buffered data is discarded. The
@@ -78,11 +76,9 @@ behavior.
The \fBfclose()\fR function is performed automatically for all open files upon
calling \fBexit\fR(2).
.SH RETURN VALUES
-.LP
Upon successful completion, \fBfclose()\fR returns \fB0\fR. Otherwise, it
returns \fBEOF\fR and sets \fBerrno\fR to indicate the error.
.SH ERRORS
-.LP
The \fBfclose()\fR function will fail if:
.sp
.ne 2
@@ -133,6 +129,8 @@ The \fBfclose()\fR function was interrupted by a signal.
The process is a member of a background process group attempting to write to
its controlling terminal, \fBTOSTOP\fR is set, the process is neither ignoring
nor blocking \fBSIGTTOU\fR and the process group of the process is orphaned.
+\fIstream\fR was created by \fBopen_wmemstream\fR(3C) and a wide-character or
+byte sequence buffered is invalid in the current locale.
.RE
.sp
@@ -169,7 +167,6 @@ limits of the device.
.RE
.SH ATTRIBUTES
-.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp
@@ -186,7 +183,6 @@ MT-Level MT-Safe
.TE
.SH SEE ALSO
-.LP
\fBclose\fR(2), \fBexit\fR(2), \fBgetrlimit\fR(2), \fBulimit\fR(2),
\fBfcloseall\fR(3C), \fBfopen\fR(3C), \fBstdio\fR(3C),
\fBattributes\fR(5), \fBstandards\fR(5)
diff --git a/usr/src/man/man3c/ferror.3c b/usr/src/man/man3c/ferror.3c
index 97ffb7046c..19af21773a 100644
--- a/usr/src/man/man3c/ferror.3c
+++ b/usr/src/man/man3c/ferror.3c
@@ -1,73 +1,104 @@
-'\" te
-.\" Copyright 1989 AT&T Copyright (c) 2005, Sun Microsystems, Inc. All Rights Reserved
-.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
-.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
-.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
-.TH FERROR 3C "Feb 17, 2005"
-.SH NAME
-ferror, feof, clearerr, fileno \- stream status inquiries
-.SH SYNOPSIS
-.LP
-.nf
-#include <stdio.h>
-
-\fBint\fR \fBferror\fR(\fBFILE *\fR\fIstream\fR);
-.fi
-
-.LP
-.nf
-\fBint\fR \fBfeof\fR(\fBFILE *\fR\fIstream\fR);
-.fi
-
-.LP
-.nf
-\fBvoid\fR \fBclearerr\fR(\fBFILE *\fR\fIstream\fR);
-.fi
-
-.LP
-.nf
-\fBint\fR \fBfileno\fR(\fBFILE *\fR\fIstream\fR);
-.fi
-
-.SH DESCRIPTION
-.sp
-.LP
-The \fBferror()\fR function returns a non-zero value when an error has
-previously occurred reading from or writing to the named \fIstream\fR (see
-\fBIntro\fR(3)). It returns \fB0\fR otherwise.
-.sp
-.LP
-The \fBfeof()\fR function returns a non-zero value when \fBEOF\fR has
-previously been detected reading the named input \fIstream\fR. It returns
-\fB0\fR otherwise.
-.sp
-.LP
-The \fBclearerr()\fR function resets the error indicator and \fBEOF\fR
-indicator to 0 on the named \fIstream\fR.
-.sp
-.LP
-The \fBfileno()\fR function returns the integer file descriptor associated with
-the named \fIstream\fR; see \fBopen\fR(2).
-.SH ATTRIBUTES
-.sp
-.LP
-See \fBattributes\fR(5) for descriptions of the following attributes:
-.sp
-
-.sp
-.TS
-box;
-c | c
-l | l .
-ATTRIBUTE TYPE ATTRIBUTE VALUE
-_
-Interface Stability Standard
-_
-MT-Level MT-Safe
-.TE
-
-.SH SEE ALSO
-.sp
-.LP
-\fBopen\fR(2), \fBIntro\fR(3), \fBfopen\fR(3C), \fBstdio\fR(3C),
-\fBattributes\fR(5), \fBstandards\fR(5)
+.\"
+.\"
+.\" The contents of this file are subject to the terms of the
+.\" Common Development and Distribution License (the "License").
+.\" You may not use this file except in compliance with the License.
+.\"
+.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+.\" or http://www.opensolaris.org/os/licensing.
+.\" See the License for the specific language governing permissions
+.\" and limitations under the License.
+.\"
+.\" When distributing Covered Code, include this CDDL HEADER in each
+.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+.\" If applicable, add the following below this CDDL HEADER, with the
+.\" fields enclosed by brackets "[]" replaced with your own identifying
+.\" information: Portions Copyright [yyyy] [name of copyright owner]
+.\"
+.\" Copyright 1989 AT&T
+.\" Copyright (c) 2005, Sun Microsystems, Inc. All Rights Reserved
+.\" Copyright 2020 Robert Mustacchi
+.\"
+.Dd "March 25, 2020"
+.Dt FERROR 3C
+.Os
+.Sh NAME
+.Nm ferror ,
+.Nm feof ,
+.Nm clearerr ,
+.Nm fileno
+.Nd stream status inquiries
+.Sh SYNOPSIS
+.In stdio.h
+.Ft int
+.Fo ferror
+.Fa "FILE *stream"
+.Fc
+.Ft int
+.Fo feof
+.Fa "FILE *stream"
+.Fc
+.Ft void
+.Fo clearerr
+.Fa "FILE *stream"
+.Fc
+.Ft int
+.Fo fileno
+.Fa "FILE *stream"
+.Fc
+.Sh DESCRIPTION
+The
+.Fn ferror
+function returns a non-zero value when an error has
+previously occurred reading from or writing to the named
+.Fa stream
+.Po
+see
+.Xr Intro 3
+.Pc .
+It returns
+.Sy 0
+otherwise.
+.Pp
+The
+.Fn feof
+function returns a non-zero value when
+.Sy EOF
+has previously been detected reading the named input
+.Fa stream .
+It returns
+.Sy 0
+otherwise.
+.Pp
+The
+.Fn clearerr
+function resets the error indicator and
+.Sy EOF
+indicator to 0 on the named
+.Fa stream .
+.Pp
+The
+.Fn fileno
+function returns the integer file descriptor associated with
+the named
+.Fa stream ;
+see
+.Xr open 2 .
+Streams that are not associated with a file descriptor such as those
+that were created through the
+.Xr fmemopen 3C
+or
+.Xr open_memstream 3C
+functions will return
+.Sy -1 .
+.Sh INTERFACE STABILITY
+.Sy Standard
+.Sh MT-LEVEL
+.Sy MT-Safe
+.Sh SEE ALSO
+.Xr Intro 2 ,
+.Xr open 2 ,
+.Xr fmemopen 3C ,
+.Xr fopen 3C ,
+.Xr open_memstream 3C ,
+.Xr stdio 3C
diff --git a/usr/src/man/man3c/fflush.3c b/usr/src/man/man3c/fflush.3c
index 7e71eedfd7..ffadc8399e 100644
--- a/usr/src/man/man3c/fflush.3c
+++ b/usr/src/man/man3c/fflush.3c
@@ -43,11 +43,10 @@
.\" Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
.\" Portions Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved.
.\"
-.TH FFLUSH 3C "Nov 1, 2003"
+.TH FFLUSH 3C "March 25, 2020"
.SH NAME
fflush \- flush a stream
.SH SYNOPSIS
-.LP
.nf
#include <stdio.h>
@@ -55,8 +54,6 @@ fflush \- flush a stream
.fi
.SH DESCRIPTION
-.sp
-.LP
If \fIstream\fR points to an output stream or an update stream in which the
most recent operation was not input, \fBfflush()\fR causes any unwritten data
for that stream to be written to the file, and the \fBst_ctime\fR and
@@ -78,13 +75,9 @@ on all streams for which the behavior is defined above.
An input stream, seekable or non-seekable, can be flushed by explicitly calling
\fBfflush()\fR with a non-null argument specifying that stream.
.SH RETURN VALUES
-.sp
-.LP
Upon successful completion, \fBfflush()\fR returns \fB0\fR. Otherwise, it
returns \fBEOF\fR and sets \fBerrno\fR to indicate the error.
.SH ERRORS
-.sp
-.LP
The \fBfflush()\fR function will fail if:
.sp
.ne 2
@@ -135,6 +128,8 @@ The \fBfflush()\fR function was interrupted by a signal.
The process is a member of a background process group attempting to write to
its controlling terminal, \fBTOSTOP\fR is set, the process is neither ignoring
nor blocking \fBSIGTTOU\fR, and the process group of the process is orphaned.
+\fIstream\fR was created by \fBopen_wmemstream\fR(3C) and a wide-character or
+byte sequence buffered is invalid in the current locale.
.RE
.sp
@@ -171,8 +166,6 @@ limits of the device.
.RE
.SH ATTRIBUTES
-.sp
-.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp
@@ -189,6 +182,4 @@ MT-Level MT-Safe
.TE
.SH SEE ALSO
-.sp
-.LP
\fBgetrlimit\fR(2), \fBulimit\fR(2), \fBattributes\fR(5), \fBstandards\fR(5)
diff --git a/usr/src/man/man3c/fmemopen.3c b/usr/src/man/man3c/fmemopen.3c
new file mode 100644
index 0000000000..20145e5617
--- /dev/null
+++ b/usr/src/man/man3c/fmemopen.3c
@@ -0,0 +1,222 @@
+.\"
+.\" This file and its contents are supplied under the terms of the
+.\" Common Development and Distribution License ("CDDL"), version 1.0.
+.\" You may only use this file in accordance with the terms of version
+.\" 1.0 of the CDDL.
+.\"
+.\" A full copy of the text of the CDDL should have accompanied this
+.\" source. A copy of the CDDL is also available via the Internet at
+.\" http://www.illumos.org/license/CDDL.
+.\"
+.\"
+.\" Copyright 2020 Robert Mustacchi
+.\"
+.Dd March 25, 2020
+.Dt FMEMOPEN 3C
+.Os
+.Sh NAME
+.Nm fmemopen
+.Nd open a memory stream
+.Sh SYNOPSIS
+.In stdio.h
+.Ft "FILE *"
+.Fo fmemopen
+.Fa "void *restrict buf"
+.Fa "size_t size"
+.Fa "const char *restrict mode"
+.Fc
+.Sh DESCRIPTION
+The
+.Fn fmemopen
+function provides a means of associating a file stream with a
+corresponding memory buffer of a fixed size.
+The resulting stream can then be used just like any other stream, and
+when done should be released by calling the
+.Xr fclose 3C
+function.
+.Pp
+The stream can either dynamically allocate memory or it can use an
+existing memory buffer.
+If
+.Fa buf
+is
+.Dv NULL ,
+then a buffer
+.Fa size
+bytes long will be allocated for the stream and initialized to zero.
+This buffer will be allocated as though a call to
+.Xr malloc 3C
+and will be freed when
+.Xr fclose 3C
+is called.
+When using this mode, the stream must be created for update
+.Po
+indicated by a
+.Sq +
+character in the
+.Fa mode
+argument
+.Pc .
+Otherwise, it is assumed that
+.Fa buf
+is at least
+.Fa size
+bytes long.
+.Pp
+The
+.Fa mode
+argument determines whether the stream is opened for read, write, or
+append.
+The
+.Fa mode
+argument accepts all the same values as
+.Xr fopen 3C .
+.Pp
+The resulting stream behaves in a similar way to a stream backed by a
+file.
+The stream can be read and written to.
+The stream is seekeable and can either be byte or wide-character
+oriented.
+A NUL byte has no special meaning when reading.
+.Pp
+The stream logically tracks three different values:
+.Bl -enum -offset indent
+.It
+The current position in the stream.
+.It
+The current size of the stream.
+.It
+The maximum size of the stream.
+.El
+.Pp
+The current position is where reads or writes take place.
+When the stream is opened for read or write
+.Pq r, r+, w, w+
+then the initial position is set to zero.
+If the stream is opened for update
+.Pq a, a+
+then the initial position is set to the first NUL byte in the buffer.
+.Pp
+The current size of the stream represents the length of the stream.
+Like a file, this starts at a specific size and then can grow over time.
+Unlike a file, where the maximum size is determined by the file system,
+the maximum size here is determined at the creation of the stream.
+.Pp
+This size is used when using
+.Dv SEEK_END
+as an argument to functions like
+.Xr fseek 3C .
+Reads cannot advance beyond the current size of the stream and
+attempting to read beyond it is considered hitting the end-of-file.
+Writes beyond the end of the current size will cause the current size to
+increase, though it cannot increase beyond the maximum size.
+.Pp
+The initial size of the stream varies.
+It is set depending on the mode and works as follows:
+.Bl -tag -width Sy -offset indent
+.It Sy r, r+
+The size is set to the
+.Fa size
+argument.
+.It Sy w, w+
+The initial size is set to zero.
+.It Sy a, a+
+The initial size is set according to the following rules:
+.Bl -enum
+.It
+If
+.Fa buf
+is a
+.Dv NULL
+pointer, the current size is set to zero.
+.It
+If a NUL byte is found in the first
+.Fa size
+bytes of
+.Fa buf ,
+then the current size is set to the first NUL byte.
+.It
+The position is set to the
+.Fa size
+argument
+.Pq the maximum size
+if no NUL byte was found in
+.Fa buf .
+.El
+.El
+.Pp
+The maximum size of the stream is determined by the
+.Fa size
+argument.
+Writes beyond this size are dropped.
+Attempts to seek beyond the maximum size will result in an error.
+.Pp
+If the stream was open for writing or update, when the stream is flushed
+or closed, a NUL byte will be written to terminate the stream based on
+the current position and size of the stream.
+If the stream was open for update, if the stream is flushed or closed
+and the last write changed the current buffer size, a NUL byte will be
+written if there is still space for it within the buffer.
+.Pp
+By default, all streams are buffered.
+This means that writes beyond the size of the memory buffer could fail,
+but not be seen until the stream is flushed or closed.
+To detect errors right away, one can explicitly disable buffering with
+the
+.Xr setvbuf 3C
+function or perform explicit buffer flushes with the
+.Xr fflush 3C
+function.
+.Sh RETURN VALUES
+Upon successful completion, the
+.Fn fmemopen
+function returns a pointer to a stream.
+Otherwise,
+.Dv NULL
+is returned and
+.Dv errno
+is set to indicate the error.
+.Sh ERRORS
+The
+.Fn fmemopen
+function will fail if:
+.Bl -tag -width Er
+.It Er EINVAL
+The value of
+.Fa mode
+is invalid.
+.Pp
+The
+.Fa size
+argument was zero.
+.Pp
+The
+.Fa buf
+argument is
+.Dv NULL
+and the
+.Fa mode
+argument does not contain a
+.Sq +
+character.
+.It Er EMFILE
+.Brq FOPEN_MAX
+streams are currently open in the calling process.
+.Pp
+.Brq STREAM_MAX
+streams are currently open in the calling process.
+.It Er ENOMEM
+The system was unable to allocate memory for the stream or its backing
+buffer.
+.El
+.Sh MT-LEVEL
+.Sy MT-Safe
+.Sh INTERFACE STABILITY
+.Sy Committed
+.Sh SEE ALSO
+.Xr fclose 3C ,
+.Xr fflush 3C ,
+.Xr fopen 3C ,
+.Xr fseek 3C ,
+.Xr malloc 3C ,
+.Xr open_memstream 3C
diff --git a/usr/src/man/man3c/fputc.3c b/usr/src/man/man3c/fputc.3c
index 11f4d8f711..2cd811282d 100644
--- a/usr/src/man/man3c/fputc.3c
+++ b/usr/src/man/man3c/fputc.3c
@@ -43,12 +43,11 @@
.\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
.\" Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
.\"
-.TH FPUTC 3C "May 13, 2017"
+.TH FPUTC 3C "March 25, 2020"
.SH NAME
fputc, putc, putc_unlocked, putchar, putchar_unlocked, putw \- put a byte on a
stream
.SH SYNOPSIS
-.LP
.nf
#include <stdio.h>
@@ -81,7 +80,6 @@ stream
.fi
.SH DESCRIPTION
-.LP
The \fBfputc()\fR function writes the byte specified by \fIc\fR (converted to
an \fBunsigned char\fR) to the output stream pointed to by \fIstream\fR, at the
position indicated by the associated file-position indicator for the stream (if
@@ -125,7 +123,6 @@ update between the successful execution of \fBputw()\fR and the next successful
completion of a call to \fBfflush\fR(3C) or \fBfclose\fR(3C) on the same stream
or a call to \fBexit\fR(3C) or \fBabort\fR(3C).
.SH RETURN VALUES
-.LP
Upon successful completion, \fBfputc()\fR, \fBputc()\fR, \fBputc_unlocked()\fR,
\fBputchar()\fR, and \fBputchar_unlocked()\fR return the value that was
written. Otherwise, these functions return EOF, the error indicator for the
@@ -140,7 +137,6 @@ sets \fBerrno\fR to indicate the error.
An unsuccessful completion will occur, for example, if the file associated with
\fIstream\fR is not open for writing or if the output file cannot grow.
.SH ERRORS
-.LP
The \fBfputc()\fR, \fBputc()\fR, \fBputc_unlocked()\fR, \fBputchar()\fR,
\fBputchar_unlocked()\fR, and \fBputw()\fR functions will fail if either the
\fIstream\fR is unbuffered or the \fIstream\fR's buffer needs to be flushed,
@@ -204,7 +200,9 @@ was transferred.
A physical I/O error has occurred, or the process is a member of a background
process group attempting to write to its controlling terminal, \fBTOSTOP\fR is
set, the process is neither ignoring nor blocking \fBSIGTTOU\fR and the process
-group of the process is orphaned. This error may also be returned under
+group of the process is orphaned. \fIstream\fR was created by
+\fBopen_wmemstream\fR(3C) and a wide-character or byte sequence buffered is
+invalid in the current locale. This error may also be returned under
implementation-dependent conditions.
.RE
@@ -252,7 +250,6 @@ capabilities of the device.
.RE
.SH USAGE
-.LP
Functions exist for the \fBputc()\fR, \fBputc_unlocked()\fR, \fBputchar()\fR,
and \fBputchar_unlocked()\fR macros. To get the function form, the macro name
must be undefined (for example, \fB#undef putc\fR).
@@ -276,7 +273,6 @@ in the context of either multibyte character streams or wide-character streams.
Application programmers are encouraged to use one of the character-based output
functions instead.
.SH ATTRIBUTES
-.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp
@@ -295,14 +291,12 @@ MT-Level See \fBNOTES\fR below.
.TE
.SH SEE ALSO
-.LP
\fBgetrlimit\fR(2), \fBulimit\fR(2) \fBwrite\fR(2), \fBIntro\fR(3),
\fBabort\fR(3C), \fBexit\fR(3C), \fBfclose\fR(3C), \fBferror\fR(3C),
\fBfflush\fR(3C), \fBflockfile\fR(3C), \fBprintf\fR(3C),
\fBputc\fR(3C), \fBputs\fR(3C), \fBsetbuf\fR(3C), \fBstdio\fR(3C),
\fBattributes\fR(5), \fBstandards\fR(5)
.SH NOTES
-.LP
The \fBfputc()\fR, \fBputc()\fR, \fBputchar()\fR, and \fBputw()\fR routines are
MT-Safe in multithreaded applications. The \fBputc_unlocked()\fR and
\fBputchar_unlocked()\fR routines are unsafe in multithreaded applications.
diff --git a/usr/src/man/man3c/fputwc.3c b/usr/src/man/man3c/fputwc.3c
index d4bd72f32b..0a9353c91a 100644
--- a/usr/src/man/man3c/fputwc.3c
+++ b/usr/src/man/man3c/fputwc.3c
@@ -43,11 +43,10 @@
.\" Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
.\" Portions Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved.
.\"
-.TH FPUTWC 3C "Nov 1, 2003"
+.TH FPUTWC 3C "March 25, 2020"
.SH NAME
fputwc, putwc, putwchar \- put wide-character code on a stream
.SH SYNOPSIS
-.LP
.nf
#include <stdio.h>
#include <wchar.h>
@@ -68,8 +67,6 @@ fputwc, putwc, putwchar \- put wide-character code on a stream
.fi
.SH DESCRIPTION
-.sp
-.LP
The \fBfputwc()\fR function writes the character corresponding to the
wide-character code \fIwc\fR to the output stream pointed to by \fIstream\fR,
at the position indicated by the associated file-position indicator for the
@@ -94,14 +91,10 @@ The call \fBputwchar(\fR\fIwc\fR\fB)\fR is equivalent to
\fBputwc(\fR\fIwc,\fR\fB stdout)\fR\fI\&.\fR The \fBputwchar()\fR routine is
implemented as a macro.
.SH RETURN VALUES
-.sp
-.LP
Upon successful completion, \fBfputwc()\fR, \fBputwc()\fR, and \fBputwchar()\fR
return \fIwc\fR. Otherwise, they return \fBWEOF\fR, the error indicator for the
stream is set, and \fBerrno\fR is set to indicate the error.
.SH ERRORS
-.sp
-.LP
The \fBfputwc()\fR, \fBputwc()\fR, and \fBputwchar()\fR functions will fail if
either the stream is unbuffered or data in the \fIstream\fR's buffer needs to
be written, and:
@@ -156,7 +149,9 @@ was transferred.
A physical I/O error has occurred, or the process is a member of a background
process group attempting to write to its controlling terminal, \fBTOSTOP\fR is
set, the process is neither ignoring nor blocking \fBSIGTTOU\fR, and the
-process group of the process is orphaned.
+process group of the process is orphaned. \fIstream\fR was created by
+\fBopen_wmemstream\fR(3C) and a wide-character or byte sequence buffered is
+invalid in the current locale.
.RE
.sp
@@ -211,8 +206,6 @@ The wide-character code \fIwc\fR does not correspond to a valid character.
.RE
.SH USAGE
-.sp
-.LP
Functions exist for the \fBputwc()\fR and \fBputwchar()\fR macros. To get the
function form, the macro name must be undefined (for example, \fB#undef
putc\fR).
@@ -223,8 +216,6 @@ more than once. In particular, \fBputwc(\fR\fIwc\fR\fB, \fR\fI*f++\fR\fB)\fR
does not work sensibly. The \fBfputwc()\fR function should be used instead
when evaluating the \fIstream\fR argument has side effects.
.SH ATTRIBUTES
-.sp
-.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp
@@ -241,8 +232,6 @@ MT-Level MT-Safe
.TE
.SH SEE ALSO
-.sp
-.LP
\fBexit\fR(2), \fBulimit\fR(2), \fBabort\fR(3C), \fBfclose\fR(3C),
\fBferror\fR(3C), \fBfflush\fR(3C), \fBfopen\fR(3C), \fBsetbuf\fR(3C),
\fBattributes\fR(5), \fBstandards\fR(5)
diff --git a/usr/src/man/man3c/freopen.3c b/usr/src/man/man3c/freopen.3c
index bcf4124cb2..a53cd77706 100644
--- a/usr/src/man/man3c/freopen.3c
+++ b/usr/src/man/man3c/freopen.3c
@@ -43,11 +43,10 @@
.\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
.\" Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved.
.\"
-.TH FREOPEN 3C "Jul 24, 2002"
+.TH FREOPEN 3C "March 25, 2020"
.SH NAME
freopen \- open a stream
.SH SYNOPSIS
-.LP
.nf
#include <stdio.h>
@@ -55,7 +54,6 @@ freopen \- open a stream
.fi
.SH DESCRIPTION
-.LP
The \fBfreopen()\fR function first attempts to flush the stream and close any
file descriptor associated with \fIstream\fR. Failure to flush or close the
file successfully is ignored. The error and end-of-file indicators for the
@@ -71,9 +69,10 @@ pointed to by \fIfilename\fR and associates the stream pointed to by
If \fIfilename\fR is a null pointer and the application conforms to SUSv3 (see
\fBstandards\fR(5)), the \fBfreopen()\fR function attempts to change the mode
of the stream to that specified by \fImode\fR, as though the name of the file
-currently associated with the \fIstream\fR had been used. The following
-changes of mode are permitted, depending upon the access mode of the file
-descriptor underlying the stream:
+currently associated with the \fIstream\fR had been used. This behavior
+is not supported by streams that are backed by memory, such as
+\fRfmemopen\fB(3C). The following changes of mode are permitted, depending upon
+the access mode of the file descriptor underlying the stream:
.RS +4
.TP
.ie t \(bu
@@ -113,12 +112,10 @@ The largest value that can be represented correctly in an object of type
\fBoff_t\fR will be established as the offset maximum in the open file
description.
.SH RETURN VALUES
-.LP
Upon successful completion, \fBfreopen()\fR returns the value of \fIstream\fR.
Otherwise, a null pointer is returned and \fBerrno\fR is set to indicate the
error.
.SH ERRORS
-.LP
The \fBfreopen()\fR function will fail if:
.sp
.ne 2
@@ -321,7 +318,6 @@ The file is a pure procedure (shared text) file that is being executed and
.RE
.SH USAGE
-.LP
The \fBfreopen()\fR function is typically used to attach the preopened
\fIstreams\fR associated with \fBstdin\fR, \fBstdout\fR and \fBstderr\fR to
other files. By default \fBstderr\fR is unbuffered, but the use of
@@ -331,7 +327,6 @@ other files. By default \fBstderr\fR is unbuffered, but the use of
The \fBfreopen()\fR function has a transitional interface for 64-bit file
offsets. See \fBlf64\fR(5).
.SH ATTRIBUTES
-.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp
@@ -348,6 +343,5 @@ MT-Level MT-Safe
.TE
.SH SEE ALSO
-.LP
\fBfclose\fR(3C), \fBfdopen\fR(3C), \fBfopen\fR(3C), \fBstdio\fR(3C),
\fBattributes\fR(5), \fBlf64\fR(5), \fBstandards\fR(5)
diff --git a/usr/src/man/man3c/fseek.3c b/usr/src/man/man3c/fseek.3c
index 5c2789be00..fbcdaac52c 100644
--- a/usr/src/man/man3c/fseek.3c
+++ b/usr/src/man/man3c/fseek.3c
@@ -44,11 +44,10 @@
.\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
.\" Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
.\"
-.TH FSEEK 3C "May 13, 2017"
+.TH FSEEK 3C "March 25, 2020"
.SH NAME
fseek, fseeko \- reposition a file-position indicator in a stream
.SH SYNOPSIS
-.LP
.nf
#include <stdio.h>
@@ -61,7 +60,6 @@ fseek, fseeko \- reposition a file-position indicator in a stream
.fi
.SH DESCRIPTION
-.LP
The \fBfseek()\fR function sets the file-position indicator for the stream
pointed to by \fIstream\fR. The \fBfseeko()\fR function is identical to
\fBfseek()\fR except for the type of \fIoffset\fR.
@@ -101,7 +99,8 @@ Set position to \fBEOF\fR plus \fIoffset\fR.
.LP
If the stream is to be used with wide character input/output functions,
\fIoffset\fR must either be 0 or a value returned by an earlier call to
-\fBftell\fR(3C) on the same stream and \fIwhence\fR must be \fBSEEK_SET\fR.
+\fBftell\fR(3C) on the same stream and \fIwhence\fR must be \fBSEEK_SET\fR. This
+constraint does not hold for streams created by \fBopen_wmemstream\fR(3C).
.sp
.LP
A successful call to \fBfseek()\fR clears the end-of-file indicator for the
@@ -129,12 +128,32 @@ If the stream is writable and buffered data had not been written to the
underlying file, \fBfseek()\fR will cause the unwritten data to be written to
the file and mark the \fBst_ctime\fR and \fBst_mtime\fR fields of the file for
update.
+.SS \fBopen_wmemstream\fR(3C)
+When using a stream based on
+.B open_wmemstream\fR(3C),
+the
+.B fseek()
+and
+.B fseeko()
+functions no longer operate in terms of bytes. Instead, like the stream itself,
+the values used in
+.I offset
+are measured in units of wide characters, the underlying data unit of the
+stream. The values returned by
+.B ftell(3C)
+or
+.B ftello(3C)
+are also in these same units, allowing them to be used in the same way. These
+streams do not have the constraints of other wide character streams and may the
+full range of values in
+.I whence
+and
+.I offset,
+the same as would be done for a normal byte-oriented stream.
.SH RETURN VALUES
-.LP
The \fBfseek()\fR and \fBfseeko()\fR functions return \fB0\fR on success;
otherwise, they returned \fB\(mi1\fR and set \fBerrno\fR to indicate the error.
.SH ERRORS
-.LP
The \fBfseek()\fR and \fBfseeko()\fR functions will fail if, either the
\fIstream\fR is unbuffered or the \fIstream\fR's buffer needed to be flushed,
and the call to \fBfseek()\fR or \fBfseeko()\fR causes an underlying
@@ -269,7 +288,6 @@ correctly in an object of type \fBoff_t\fR.
.RE
.SH USAGE
-.LP
Although on the UNIX system an offset returned by \fBftell()\fR or
\fBftello()\fR (see \fBftell\fR(3C)) is measured in bytes, and it is
permissible to seek to positions relative to that offset, portability to
@@ -281,7 +299,6 @@ necessarily measured in bytes.
The \fBfseeko()\fR function has a transitional interface for 64-bit file
offsets. See \fBlf64\fR(5).
.SH ATTRIBUTES
-.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp
@@ -298,7 +315,6 @@ MT-Level MT-Safe
.TE
.SH SEE ALSO
-.LP
\fBgetrlimit\fR(2), \fBulimit\fR(2), \fBftell\fR(3C),
\fBrewind\fR(3C), \fBungetc\fR(3C), \fBungetwc\fR(3C), \fBattributes\fR(5),
\fBlf64\fR(5), \fBstandards\fR(5)
diff --git a/usr/src/man/man3c/ftell.3c b/usr/src/man/man3c/ftell.3c
index 82670a4feb..7228f12304 100644
--- a/usr/src/man/man3c/ftell.3c
+++ b/usr/src/man/man3c/ftell.3c
@@ -43,11 +43,10 @@
.\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
.\" Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved.
.\"
-.TH FTELL 3C "Jul 24, 2002"
+.TH FTELL 3C "March 25, 2020"
.SH NAME
ftell, ftello \- return a file offset in a stream
.SH SYNOPSIS
-.LP
.nf
#include <stdio.h>
@@ -60,21 +59,28 @@ ftell, ftello \- return a file offset in a stream
.fi
.SH DESCRIPTION
-.sp
-.LP
The \fBftell()\fR function obtains the current value of the file-position
indicator for the stream pointed to by \fIstream\fR. The \fBftello()\fR
function is identical to \fBftell()\fR except for the return type.
+.PP
+Normally the value returned is measured in bytes. However, when
+.I stream
+has been created with
+.B open_wmemstream(3C)
+then the offset of the stream is measured in wide characters. This behavior is
+consistent with how
+.B fseek(3C)
+and
+.B fseeko(3C)
+treat the offset into the stream.
.SH RETURN VALUES
-.sp
-.LP
Upon successful completion, the \fBftell()\fR and \fBftello()\fR functions
return the current value of the file-position indicator for the stream measured
-in bytes from the beginning of the file. Otherwise, they return \fB\(mi1\fR and
-sets \fBerrno\fR to indicate the error.
+in bytes from the beginning of the file, or wide characters for streams created
+by
+.B open_wmemstream(3C).
+Otherwise, they return \fB\(mi1\fR and sets \fBerrno\fR to indicate the error.
.SH ERRORS
-.sp
-.LP
The \fBftell()\fR and \fBftello()\fR functions will fail if:
.sp
.ne 2
@@ -122,13 +128,9 @@ The current file offset cannot be represented correctly in an object of type
.RE
.SH USAGE
-.sp
-.LP
The \fBftello()\fR function has a transitional interface for 64-bit file
offsets. See \fBlf64\fR(5).
.SH ATTRIBUTES
-.sp
-.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp
@@ -145,7 +147,5 @@ MT-Level MT-Safe
.TE
.SH SEE ALSO
-.sp
-.LP
-\fBlseek\fR(2), \fBfopen\fR(3C), \fBfseek\fR(3C), \fBattributes\fR(5), ,
-\fBstandards\fR(5), \fBlf64\fR(5)
+\fBlseek\fR(2), \fBfopen\fR(3C), \fBfseek\fR(3C), \fBopen_wmemstream\fR(3C),
+\fBattributes\fR(5), \fBstandards\fR(5), \fBlf64\fR(5)
diff --git a/usr/src/man/man3c/fwrite.3c b/usr/src/man/man3c/fwrite.3c
index 0027f2a426..92f13cd98f 100644
--- a/usr/src/man/man3c/fwrite.3c
+++ b/usr/src/man/man3c/fwrite.3c
@@ -44,11 +44,10 @@
.\" Copyright (c) 1997, The Open Group. All Rights Reserved.
.\" Portions Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved.
.\"
-.TH FWRITE 3C "Jul 24, 2002"
+.TH FWRITE 3C "March 25, 2020"
.SH NAME
fwrite \- binary output
.SH SYNOPSIS
-.LP
.nf
#include <stdio.h>
@@ -56,8 +55,6 @@ fwrite \- binary output
.fi
.SH DESCRIPTION
-.sp
-.LP
The \fBfwrite()\fR function writes, from the array pointed to by \fIptr\fR, up
to \fInitems\fR elements whose size is specified by \fIsize\fR, to the stream
pointed to by \fIstream\fR. For each object, \fIsize\fR calls are made to the
@@ -72,28 +69,26 @@ The \fBst_ctime\fR and \fBst_mtime\fR fields of the file will be marked for
update between the successful execution of \fBfwrite()\fR and the next
successful completion of a call to \fBfflush\fR(3C) or \fBfclose\fR(3C) on the
same stream or a call to \fBexit\fR(2) or \fBabort\fR(3C).
-.SH RETURN VALUES
.sp
.LP
+When using the \fBfwrite()\fR function on a stream that was created with
+\fBopen_wmemstream\fR(3C), there are additional constraints on the
+binary data that can be written due to the nature of the stream. Please
+see \fBopen_wmemstream\fR(3C) for additional information.
+.SH RETURN VALUES
The \fBfwrite()\fR function returns the number of elements successfully
written, which might be less than \fInitems\fR if a write error is encountered.
If \fIsize\fR or \fInitems\fR is 0, \fBfwrite()\fR returns 0 and the state of
the stream remains unchanged. Otherwise, if a write error occurs, the error
indicator for the stream is set and \fBerrno\fR is set to indicate the error.
.SH ERRORS
-.sp
-.LP
Refer to \fBfputc\fR(3C).
.SH USAGE
-.sp
-.LP
Because of possible differences in element length and byte ordering, files
written using \fBfwrite()\fR are application-dependent, and possibly cannot be
read using \fBfread\fR(3C) by a different application or by the same
application on a different processor.
.SH ATTRIBUTES
-.sp
-.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp
@@ -110,8 +105,7 @@ MT-Level MT-Safe
.TE
.SH SEE ALSO
-.sp
-.LP
\fBwrite\fR(2), \fBfclose\fR(3C), \fBferror\fR(3C), \fBfopen\fR(3C),
-\fBfread\fR(3C), \fBgetc\fR(3C), \fBgets\fR(3C), \fBprintf\fR(3C),
-\fBputc\fR(3C), \fBputs\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)
+\fBfread\fR(3C), \fBgetc\fR(3C), \fBgets\fR(3C), \fBopen_wmemstream\fR(3C),
+\fBprintf\fR(3C), \fBputc\fR(3C), \fBputs\fR(3C), \fBattributes\fR(5),
+\fBstandards\fR(5)
diff --git a/usr/src/man/man3c/open_memstream.3c b/usr/src/man/man3c/open_memstream.3c
new file mode 100644
index 0000000000..9dc9315328
--- /dev/null
+++ b/usr/src/man/man3c/open_memstream.3c
@@ -0,0 +1,195 @@
+.\"
+.\" This file and its contents are supplied under the terms of the
+.\" Common Development and Distribution License ("CDDL"), version 1.0.
+.\" You may only use this file in accordance with the terms of version
+.\" 1.0 of the CDDL.
+.\"
+.\" A full copy of the text of the CDDL should have accompanied this
+.\" source. A copy of the CDDL is also available via the Internet at
+.\" http://www.illumos.org/license/CDDL.
+.\"
+.\"
+.\" Copyright 2020 Robert Mustacchi
+.\"
+.Dd March 25, 2020
+.Dt OPEN_MEMSTREAM 3C
+.Os
+.Sh NAME
+.Nm open_memstream ,
+.Nm open_wmemstream
+.Nd open a memory stream
+.Sh SYNOPSIS
+.In stdio.h
+.Ft "FILE *"
+.Fo open_memstream
+.Fa "char **bufp"
+.Fa "size_t *sizep"
+.Fc
+.In wchar.h
+.Ft "FILE *"
+.Fo open_wmemstream
+.Fa "wchar_t **bufp"
+.Fa "size_t *sizep"
+.Fc
+.Sh DESCRIPTION
+The
+.Fn open_memstream
+and
+.Fn open_wmemstream
+functions create an I/O stream that is backed by a dynamic memory buffer
+which will grow as needed.
+The stream is seekable and writable.
+The stream is not readable.
+The stream is byte-oriented in the case of the
+.Fn open_memstream
+function or it is wide-oriented in the case of the
+.Fn open_wmemstream
+function.
+.Pp
+Memory for the stream is dynamically allocated and reallocated as though
+a call to
+.Xr malloc 3C .
+As the stream is written to, flushed, or closed, the underlying buffer
+will be grown automatically as required.
+After the stream is flushed or closed, the
+.Fa bufp
+argument will be filled in with a pointer to the current buffer.
+The
+.Fa sizep
+argument will be filled in with the smaller of the current buffer length
+and the current position in bytes
+.Pq Fn open_memstream
+or wide characters
+.Pq Fn open_wmemstream ,
+excluding a NUL character.
+Note, because the current position is taken into account, the actual
+size of the buffer may be larger than is found in
+.Fa sizep ;
+however data should not be accessed beyond the indicated size.
+The values stored in the
+.Fa bufp
+and
+.Fa sizep
+arguments are only valid until the next write operation on the stream
+or a call to
+.Xr fclose 3C .
+.Pp
+The stream maintains both the current position and the current length of
+the stream.
+Both the initial position and length of the buffer are set to zero.
+Whenever a write at the current position exceeds the current length of the
+buffer, the current length is increased and a NUL character,
+.Sq \e0
+.Pq Fn open_memstream
+or NUL wide character,
+.Sq L\e0
+.Pq Fn open_wmemstream
+will be added to the buffer.
+If the stream is seeked beyond the current length and a subsequent write
+occurs, intervening characters will be filled with the corresponding NUL
+character for the stream.
+.Pp
+To release the stream, the caller must call the
+.Xr fclose 3C
+function.
+The corresponding dynamically allocated memory will be disassociated
+from the stream and will become owned by the caller.
+The caller must eventually release the memory buffer pointed to in the
+.Fa bufp
+argument with a call to
+.Xr free 3C .
+.Ss Fn open_wmemstream , Xr fseek 3C , Xr fsetops 3C, and Xr ftell 3C
+The specification for the
+.Fn open_wmemstream
+function causes the
+.Xr fseek 3C
+and
+.Xr ftell 3C
+families of functions to operate differently.
+Traditionally, these functions always return units in bytes, regardless
+of whether the underlying stream is byte- or wide-oriented.
+However, when used against a stream created by the
+.Fn open_wmemstream
+function these now count in terms of units of wide characters.
+While this is different from the traditional behavior, this does mean
+that the units will be the same as tracked in
+.Fa sizep .
+.Ss Fn open_wmemstream and byte-oriented functions
+Unlike other streams, streams created by
+.Fn open_wmemstream
+are not only wide-oriented, but operate in terms of the
+.Vt wchar_t
+data type.
+When normal bytes are written to the stream, an implicit multi-byte
+conversion state is maintained.
+Writing byte sequences that don't correspond to valid byte sequences in
+the locale can cause I/O errors to occur when using write functions such
+as
+.Xr fputc 3C
+or
+.Xr fwrite 3C ,
+or when buffered data is flushed through functions like
+.Xr fflush 3C
+or
+.Xr fclose 3C .
+.Pp
+The same problem can occur when explicitly using wide characters, for
+example,
+.Xr fputwc 3C ,
+if the
+wide character represents a code point that is not valid in the current
+locale.
+To avoid these errors when flushing or closing, one can disable
+buffering by passing
+.Dv _IONBF
+as the buffering type with
+.Xr setvbuf 3C .
+.Pp
+It is not recommended to change the locale of such a stream while
+writing a byte sequence that represents valid wide characters.
+The behavior of using byte-oriented functions is not standardized and
+not all systems will behave the same way.
+.Sh RETURN VALUES
+Upon successful completion, the
+.Fn open_memstream
+and
+.Fn open_wmemstream
+functions returns a pointer to a stream.
+Otherwise,
+.Dv NULL
+is returned and
+.Dv errno
+is set to indicate the error.
+.Sh ERRORS
+The
+.Fn fmemopen
+function will fail if:
+.Bl -tag -width Er
+.It Er EINVAL
+Either of the
+.Fa bufp
+or
+.Fa sizep
+arguments are
+.Dv NULL .
+.It Er EMFILE
+.Brq FOPEN_MAX
+streams are currently open in the calling process.
+.Pp
+.Brq STREAM_MAX
+streams are currently open in the calling process.
+.It Er ENOMEM
+The system was unable to allocate memory for the stream or its backing
+memory buffer.
+.El
+.Sh MT-LEVEL
+.Sy MT-Safe
+.Sh INTERFACE STABILITY
+.Sy Committed
+.Sh SEE ALSO
+.Xr fclose 3C ,
+.Xr fflush 3C ,
+.Xr fmemopen 3C ,
+.Xr free 3C ,
+.Xr malloc 3C ,
+.Xr setvbuf 3C
diff --git a/usr/src/man/man3c/stdio.3c b/usr/src/man/man3c/stdio.3c
index ce4b9d1f12..f7dce6dfa7 100644
--- a/usr/src/man/man3c/stdio.3c
+++ b/usr/src/man/man3c/stdio.3c
@@ -3,11 +3,11 @@
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
-.TH STDIO 3C "May 18, 2005"
+.\" Copyright 2020 Robert Mustacchi
+.TH STDIO 3C "March 25, 2020"
.SH NAME
stdio, stdin, stdout, stderr \- standard buffered input/output package
.SH SYNOPSIS
-.LP
.nf
#include <stdio.h>
.fi
@@ -28,8 +28,6 @@ stdio, stdin, stdout, stderr \- standard buffered input/output package
.fi
.SH DESCRIPTION
-.sp
-.LP
The standard I/O functions described in section 3C of this manual constitute an
efficient, user-level \fBI/O\fR buffering scheme. The in-line macros
\fBgetc()\fR and \fBputc()\fR handle characters quickly. The macros
@@ -45,6 +43,8 @@ A file with associated buffering is called a \fIstream\fR (see \fBIntro\fR(3))
and is declared to be a pointer to a defined type \fBFILE\fR. The
\fBfopen\fR(3C) function creates certain descriptive data for a stream and
returns a pointer to designate the stream in all further transactions.
+Streams to memory may also be created through the \fBfmemopen\fR(3C),
+\fBopen_memstream\fR(3C), and \fBopen_wmemstream\fR(3C) functions.
Normally, there are three open streams with constant pointers declared in the
\fB<stdio.h>\fR header and associated with the standard open files:
.sp
@@ -113,7 +113,10 @@ a buffer intended to hold a file's pathname.
The integer constant \fBFOPEN_MAX\fR specifies the minimum number of files that
the implementation guarantees can be open simultaneously. Note that no more
than 255 files may be opened using \fBfopen()\fR, and only file descriptors 0
-through 255 can be used in a stream.
+through 255 can be used in a stream. This restriction only holds for the 32-bit
+compilation environment. The 64-bit environment may use more streams and the use
+of more than 255 may be enabled in a 32-bit environment through the use of
+\fBextendedFILE\fR(5).
.sp
.LP
The functions and constants mentioned in the entries of section 3S of this
@@ -140,8 +143,6 @@ The \fBsetbuf()\fR or \fBsetvbuf()\fR functions (both described on the
\fBsetbuf\fR(3C) manual page) may be used to change the stream's buffering
strategy.
.SS "Interactions of Other FILE-Type C Functions"
-.sp
-.LP
A single open file description can be accessed both through streams and through
file descriptors. Either a file descriptor or a stream will be called a
\fIhandle\fR on the open file description to which it refers; an open file
@@ -290,8 +291,6 @@ are followed, it is implementation defined whether, and under what conditions,
all input is seen exactly once.
.RE
.SS "Use of stdio in Multithreaded Applications"
-.sp
-.LP
All the \fBstdio\fR functions are safe unless they have the \fB_unlocked\fR
suffix. Each \fBFILE\fR pointer has its own lock to guarantee that only one
thread can access it. In the case that output needs to be synchronized, the
@@ -329,18 +328,15 @@ funlockfile(iop);
.in -2
.SH RETURN VALUES
-.sp
-.LP
Invalid stream pointers usually cause grave disorder, possibly including
program termination. Individual function descriptions describe the possible
error conditions.
.SH SEE ALSO
-.sp
-.LP
\fBclose\fR(2), \fBlseek\fR(2), \fBopen\fR(2), \fBpipe\fR(2), \fBread\fR(2),
\fBwrite\fR(2), \fBctermid\fR(3C), \fBcuserid\fR(3C), \fBfclose\fR(3C),
-\fBferror\fR(3C), \fBfopen\fR(3C), \fBfread\fR(3C), \fBfseek\fR(3C),
-\fBflockfile\fR(3C), \fBgetc\fR(3C), \fBgets\fR(3C), \fBpopen\fR(3C),
+\fBferror\fR(3C), \fBfmemopen\fR(3C), \fBfopen\fR(3C), \fBfread\fR(3C),
+\fBfseek\fR(3C), \fBflockfile\fR(3C), \fBgetc\fR(3C), \fBgets\fR(3C),
+\fBopen_memstream(3C)\fR, \fBopen_wmemstream(3C(\fR, \fBpopen\fR(3C),
\fBprintf\fR(3C), \fBputc\fR(3C), \fBputs\fR(3C), \fBscanf\fR(3C),
\fBsetbuf\fR(3C), \fBsystem\fR(3C), \fBtmpfile\fR(3C), \fBtmpnam\fR(3C),
\fBungetc\fR(3C)