mirror of
https://github.com/GnoConsortium/gno.git
synced 2024-11-19 11:30:51 +00:00
162 lines
4.8 KiB
Groff
162 lines
4.8 KiB
Groff
|
.\" Copyright (c) 1990, 1991, 1993
|
||
|
.\" The Regents of the University of California. All rights reserved.
|
||
|
.\"
|
||
|
.\" This code is derived from software contributed to Berkeley by
|
||
|
.\" Chris Torek.
|
||
|
.\" Redistribution and use in source and binary forms, with or without
|
||
|
.\" modification, are permitted provided that the following conditions
|
||
|
.\" are met:
|
||
|
.\" 1. Redistributions of source code must retain the above copyright
|
||
|
.\" notice, this list of conditions and the following disclaimer.
|
||
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||
|
.\" notice, this list of conditions and the following disclaimer in the
|
||
|
.\" documentation and/or other materials provided with the distribution.
|
||
|
.\" 3. All advertising materials mentioning features or use of this software
|
||
|
.\" must display the following acknowledgement:
|
||
|
.\" This product includes software developed by the University of
|
||
|
.\" California, Berkeley and its contributors.
|
||
|
.\" 4. Neither the name of the University nor the names of its contributors
|
||
|
.\" may be used to endorse or promote products derived from this software
|
||
|
.\" without specific prior written permission.
|
||
|
.\"
|
||
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||
|
.\" SUCH DAMAGE.
|
||
|
.\"
|
||
|
.\" @(#)funopen.3 8.1 (Berkeley) 6/9/93
|
||
|
.\"
|
||
|
.TH FUNOPEN 3 "17 September 1997" GNO "Library Routines"
|
||
|
.SH NAME
|
||
|
.BR funopen ,
|
||
|
.BR fropen ,
|
||
|
.BR fwopen
|
||
|
\- open a stream
|
||
|
.SH SYNOPSIS
|
||
|
#include <stdio.h>
|
||
|
.sp 1
|
||
|
FILE *\fBfunopen\fR (void *\fIcookie\fR, int (*\fIreadfn\fR)(void *, char *, int), int (*\fIwritefn\fR)(void *, const char *, int), fpos_t (*\fIseekfn\fR)(void *, fpos_t, int), int (*\fIclosefn\fR)(void *));
|
||
|
.sp 1
|
||
|
FILE *\fBfropen\fR (void *\fIcookie\fR, int (*\fIreadfn\fR)(void *, char *, int));
|
||
|
.sp 1
|
||
|
FILE *\fBfwopen\fR (void *\fIcookie\fR, int (*\fIwritefn\fR)(void *, char *, int));
|
||
|
.SH DESCRIPTION
|
||
|
The
|
||
|
.BR funopen
|
||
|
function
|
||
|
associates a stream with up to four I/O functions.
|
||
|
Either
|
||
|
.I readfn
|
||
|
or
|
||
|
.I writefn
|
||
|
must be specified;
|
||
|
the others can be given as an appropriately-typed
|
||
|
.BR NULL
|
||
|
pointer.
|
||
|
These I/O
|
||
|
functions will be used to read, write, seek and
|
||
|
close the new stream.
|
||
|
.LP
|
||
|
In general, omitting a function means that any attempt to perform the
|
||
|
associated operation on the resulting stream will fail.
|
||
|
If the close function is omitted, closing the stream will flush
|
||
|
any buffered output and then succeed.
|
||
|
.LP
|
||
|
The calling conventions of
|
||
|
.IR readfn ,
|
||
|
.IR writefn ,
|
||
|
.I seekfn
|
||
|
and
|
||
|
.I closefn
|
||
|
must match those, respectively, of
|
||
|
.BR read (2),
|
||
|
.BR write (2),
|
||
|
.BR seek (2),
|
||
|
and
|
||
|
.BR close (2)
|
||
|
with the single exception that they are passed the
|
||
|
.I cookie
|
||
|
argument specified to
|
||
|
.BR funopen
|
||
|
in place of the traditional file descriptor argument.
|
||
|
.LP
|
||
|
Read and write I/O
|
||
|
functions are allowed to change the underlying buffer
|
||
|
on fully buffered or line buffered streams by calling
|
||
|
.BR setvbuf (3).
|
||
|
They are also not required to completely fill or empty the buffer.
|
||
|
They are not, however, allowed to change streams from unbuffered to buffered
|
||
|
or to change the state of the line buffering flag.
|
||
|
They must also be prepared to have read or write calls occur on buffers other
|
||
|
than the one most recently specified.
|
||
|
.LP
|
||
|
All user I/O
|
||
|
functions can report an error by returning \-1.
|
||
|
Additionally, all of the functions should set the external variable
|
||
|
.IR errno
|
||
|
appropriately if an error occurs.
|
||
|
.LP
|
||
|
An error on
|
||
|
.BR closefn
|
||
|
does not keep the stream open.
|
||
|
.LP
|
||
|
As a convenience, the include file
|
||
|
.BR <stdio.h>
|
||
|
defines the macros
|
||
|
.BR fropen
|
||
|
and
|
||
|
.BR fwopen
|
||
|
as calls to
|
||
|
.BR funopen
|
||
|
with only a read or write function specified.
|
||
|
.SH RETURN VALUES
|
||
|
Upon successful completion,
|
||
|
.BR funopen
|
||
|
returns a
|
||
|
.BR FILE
|
||
|
pointer.
|
||
|
Otherwise,
|
||
|
.BR NULL
|
||
|
is returned and the global variable
|
||
|
.IR errno
|
||
|
is set to indicate the error.
|
||
|
.SH ERRORS
|
||
|
.RS
|
||
|
.IP \fBEINVAL\fR
|
||
|
The
|
||
|
.BR funopen
|
||
|
function
|
||
|
was called without either a read or write function.
|
||
|
The
|
||
|
.BR funopen
|
||
|
function
|
||
|
may also fail and set
|
||
|
.IR errno
|
||
|
for any of the errors
|
||
|
specified for the routine
|
||
|
.BR malloc (3).
|
||
|
.RE
|
||
|
.SH SEE ALSO
|
||
|
.BR fcntl (2),
|
||
|
.BR open (2),
|
||
|
.BR fclose (3),
|
||
|
.BR fopen (3),
|
||
|
.BR fseek (3),
|
||
|
.BR setbuf (3)
|
||
|
.SH HISTORY
|
||
|
The
|
||
|
.BR funopen
|
||
|
functions first appeared in 4.4BSD.
|
||
|
.SH BUGS
|
||
|
The
|
||
|
.BR funopen
|
||
|
function
|
||
|
may not be portable to systems other than BSD.
|