xref: /freebsd/lib/libc/stdio/funopen.3 (revision 7bdf80e5714a8b59a2bfda90f367be4612df033e)
158f0484fSRodney W. Grimes.\" Copyright (c) 1990, 1991, 1993
258f0484fSRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
358f0484fSRodney W. Grimes.\"
458f0484fSRodney W. Grimes.\" This code is derived from software contributed to Berkeley by
558f0484fSRodney W. Grimes.\" Chris Torek.
658f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
758f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions
858f0484fSRodney W. Grimes.\" are met:
958f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
1058f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
1158f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
1258f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
1358f0484fSRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
1458f0484fSRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software
1558f0484fSRodney W. Grimes.\"    must display the following acknowledgement:
1658f0484fSRodney W. Grimes.\"	This product includes software developed by the University of
1758f0484fSRodney W. Grimes.\"	California, Berkeley and its contributors.
1858f0484fSRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors
1958f0484fSRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
2058f0484fSRodney W. Grimes.\"    without specific prior written permission.
2158f0484fSRodney W. Grimes.\"
2258f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2358f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2458f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2558f0484fSRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2658f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2758f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2858f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2958f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3058f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3158f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3258f0484fSRodney W. Grimes.\" SUCH DAMAGE.
3358f0484fSRodney W. Grimes.\"
3458f0484fSRodney W. Grimes.\"     @(#)funopen.3	8.1 (Berkeley) 6/9/93
3558f0484fSRodney W. Grimes.\"
3658f0484fSRodney W. Grimes.Dd June 9, 1993
3758f0484fSRodney W. Grimes.Dt FUNOPEN 3
3858f0484fSRodney W. Grimes.Os
3958f0484fSRodney W. Grimes.Sh NAME
4058f0484fSRodney W. Grimes.Nm funopen ,
4158f0484fSRodney W. Grimes.Nm fropen ,
4258f0484fSRodney W. Grimes.Nm fwopen
4358f0484fSRodney W. Grimes.Nd open a stream
4458f0484fSRodney W. Grimes.Sh SYNOPSIS
4558f0484fSRodney W. Grimes.Fd #include <stdio.h>
4658f0484fSRodney W. Grimes.Ft FILE *
47270d3d75SMike Pritchard.Fn funopen "void  *cookie" "int  (*readfn)(void *, char *, int)" "int (*writefn)(void *, const char *, int)" "fpos_t (*seekfn)(void *, fpos_t, int)" "int (*closefn)(void *)"
4858f0484fSRodney W. Grimes.Ft FILE *
4958f0484fSRodney W. Grimes.Fn fropen "void  *cookie" "int  (*readfn)(void *, char *, int)"
5058f0484fSRodney W. Grimes.Ft FILE *
5158f0484fSRodney W. Grimes.Fn fwopen "void  *cookie" "int  (*writefn)(void *, char *, int)"
5258f0484fSRodney W. Grimes.Sh DESCRIPTION
5358f0484fSRodney W. GrimesThe
5458f0484fSRodney W. Grimes.Fn funopen
5558f0484fSRodney W. Grimesfunction
5658f0484fSRodney W. Grimesassociates a stream with up to four
5758f0484fSRodney W. Grimes.Dq Tn I/O No functions .
5858f0484fSRodney W. GrimesEither
5958f0484fSRodney W. Grimes.Fa readfn
6058f0484fSRodney W. Grimesor
6158f0484fSRodney W. Grimes.Fa writefn
6258f0484fSRodney W. Grimesmust be specified;
6358f0484fSRodney W. Grimesthe others can be given as an appropriately-typed
6458f0484fSRodney W. Grimes.Dv NULL
6558f0484fSRodney W. Grimespointer.
6658f0484fSRodney W. GrimesThese
6758f0484fSRodney W. Grimes.Tn I/O
6858f0484fSRodney W. Grimesfunctions will be used to read, write, seek and
6958f0484fSRodney W. Grimesclose the new stream.
7058f0484fSRodney W. Grimes.Pp
7158f0484fSRodney W. GrimesIn general, omitting a function means that any attempt to perform the
7258f0484fSRodney W. Grimesassociated operation on the resulting stream will fail.
7358f0484fSRodney W. GrimesIf the close function is omitted, closing the stream will flush
7458f0484fSRodney W. Grimesany buffered output and then succeed.
7558f0484fSRodney W. Grimes.Pp
7658f0484fSRodney W. GrimesThe calling conventions of
7758f0484fSRodney W. Grimes.Fa readfn ,
7858f0484fSRodney W. Grimes.Fa writefn ,
7958f0484fSRodney W. Grimes.Fa seekfn
8058f0484fSRodney W. Grimesand
8158f0484fSRodney W. Grimes.Fa closefn
8258f0484fSRodney W. Grimesmust match those, respectively, of
8358f0484fSRodney W. Grimes.Xr read 2 ,
8458f0484fSRodney W. Grimes.Xr write 2 ,
8558f0484fSRodney W. Grimes.Xr seek 2 ,
8658f0484fSRodney W. Grimesand
8758f0484fSRodney W. Grimes.Xr close 2
8858f0484fSRodney W. Grimeswith the single exception that they are passed the
8958f0484fSRodney W. Grimes.Fa cookie
9058f0484fSRodney W. Grimesargument specified to
9158f0484fSRodney W. Grimes.Fn funopen
9258f0484fSRodney W. Grimesin place of the traditional file descriptor argument.
9358f0484fSRodney W. Grimes.Pp
9458f0484fSRodney W. GrimesRead and write
9558f0484fSRodney W. Grimes.Tn I/O
9658f0484fSRodney W. Grimesfunctions are allowed to change the underlying buffer
9758f0484fSRodney W. Grimeson fully buffered or line buffered streams by calling
9858f0484fSRodney W. Grimes.Xr setvbuf 3 .
9958f0484fSRodney W. GrimesThey are also not required to completely fill or empty the buffer.
10058f0484fSRodney W. GrimesThey are not, however, allowed to change streams from unbuffered to buffered
10158f0484fSRodney W. Grimesor to change the state of the line buffering flag.
10258f0484fSRodney W. GrimesThey must also be prepared to have read or write calls occur on buffers other
10358f0484fSRodney W. Grimesthan the one most recently specified.
10458f0484fSRodney W. Grimes.Pp
10558f0484fSRodney W. GrimesAll user
10658f0484fSRodney W. Grimes.Tn I/O
10758f0484fSRodney W. Grimesfunctions can report an error by returning \-1.
10858f0484fSRodney W. GrimesAdditionally, all of the functions should set the external variable
10958f0484fSRodney W. Grimes.Va errno
11058f0484fSRodney W. Grimesappropriately if an error occurs.
11158f0484fSRodney W. Grimes.Pp
11258f0484fSRodney W. GrimesAn error on
11358f0484fSRodney W. Grimes.Fn closefn
11458f0484fSRodney W. Grimesdoes not keep the stream open.
11558f0484fSRodney W. Grimes.Pp
11658f0484fSRodney W. GrimesAs a convenience, the include file
11758f0484fSRodney W. Grimes.Aq Pa stdio.h
11858f0484fSRodney W. Grimesdefines the macros
11958f0484fSRodney W. Grimes.Fn fropen
12058f0484fSRodney W. Grimesand
12158f0484fSRodney W. Grimes.Fn fwopen
12258f0484fSRodney W. Grimesas calls to
12358f0484fSRodney W. Grimes.Fn funopen
12458f0484fSRodney W. Grimeswith only a read or write function specified.
12558f0484fSRodney W. Grimes.Sh RETURN VALUES
12658f0484fSRodney W. GrimesUpon successful completion,
12758f0484fSRodney W. Grimes.Fn funopen
12858f0484fSRodney W. Grimesreturns a
12958f0484fSRodney W. Grimes.Dv FILE
13058f0484fSRodney W. Grimespointer.
13158f0484fSRodney W. GrimesOtherwise,
13258f0484fSRodney W. Grimes.Dv NULL
13358f0484fSRodney W. Grimesis returned and the global variable
13458f0484fSRodney W. Grimes.Va errno
13558f0484fSRodney W. Grimesis set to indicate the error.
13658f0484fSRodney W. Grimes.Sh ERRORS
13758f0484fSRodney W. Grimes.Bl -tag -width [EINVAL]
13858f0484fSRodney W. Grimes.It Bq Er EINVAL
13958f0484fSRodney W. GrimesThe
14058f0484fSRodney W. Grimes.Fn funopen
14158f0484fSRodney W. Grimesfunction
14258f0484fSRodney W. Grimeswas called without either a read or write function.
14358f0484fSRodney W. GrimesThe
14458f0484fSRodney W. Grimes.Fn funopen
14558f0484fSRodney W. Grimesfunction
14658f0484fSRodney W. Grimesmay also fail and set
14758f0484fSRodney W. Grimes.Va errno
14858f0484fSRodney W. Grimesfor any of the errors
14958f0484fSRodney W. Grimesspecified for the routine
15058f0484fSRodney W. Grimes.Xr malloc 3 .
15158f0484fSRodney W. Grimes.El
15258f0484fSRodney W. Grimes.Sh SEE ALSO
15358f0484fSRodney W. Grimes.Xr fcntl 2 ,
15458f0484fSRodney W. Grimes.Xr open 2 ,
15558f0484fSRodney W. Grimes.Xr fclose 3 ,
15658f0484fSRodney W. Grimes.Xr fopen 3 ,
15758f0484fSRodney W. Grimes.Xr fseek 3 ,
15858f0484fSRodney W. Grimes.Xr setbuf 3
15958f0484fSRodney W. Grimes.Sh HISTORY
16058f0484fSRodney W. GrimesThe
16158f0484fSRodney W. Grimes.Fn funopen
1627bdf80e5SMike Pritchardfunctions first appeared in
1637bdf80e5SMike Pritchard.Bx 4.4 .
16458f0484fSRodney W. Grimes.Sh BUGS
16558f0484fSRodney W. GrimesThe
16658f0484fSRodney W. Grimes.Fn funopen
16758f0484fSRodney W. Grimesfunction
16858f0484fSRodney W. Grimesmay not be portable to systems other than
16958f0484fSRodney W. Grimes.Bx .
170