xref: /freebsd/lib/libc/stdio/funopen.3 (revision fbbd9655e5107c68e4e0146ff22b73d7350475bc)
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.
14*fbbd9655SWarner Losh.\" 3. Neither the name of the University nor the names of its contributors
1558f0484fSRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
1658f0484fSRodney W. Grimes.\"    without specific prior written permission.
1758f0484fSRodney W. Grimes.\"
1858f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1958f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2058f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2158f0484fSRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2258f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2358f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2458f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2558f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2658f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2758f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2858f0484fSRodney W. Grimes.\" SUCH DAMAGE.
2958f0484fSRodney W. Grimes.\"
3058f0484fSRodney W. Grimes.\"     @(#)funopen.3	8.1 (Berkeley) 6/9/93
317f3dea24SPeter Wemm.\" $FreeBSD$
3258f0484fSRodney W. Grimes.\"
33877a840cSConrad Meyer.Dd May 9, 2016
3458f0484fSRodney W. Grimes.Dt FUNOPEN 3
3558f0484fSRodney W. Grimes.Os
3658f0484fSRodney W. Grimes.Sh NAME
3758f0484fSRodney W. Grimes.Nm funopen ,
3858f0484fSRodney W. Grimes.Nm fropen ,
3958f0484fSRodney W. Grimes.Nm fwopen
4058f0484fSRodney W. Grimes.Nd open a stream
4125bb73e0SAlexey Zelkin.Sh LIBRARY
4225bb73e0SAlexey Zelkin.Lb libc
4358f0484fSRodney W. Grimes.Sh SYNOPSIS
4432eef9aeSRuslan Ermilov.In stdio.h
4558f0484fSRodney W. Grimes.Ft FILE *
4623f0c1fcSBruce Evans.Fn funopen "const void *cookie" "int (*readfn)(void *, char *, int)" "int (*writefn)(void *, const char *, int)" "fpos_t (*seekfn)(void *, fpos_t, int)" "int (*closefn)(void *)"
4758f0484fSRodney W. Grimes.Ft FILE *
4858f0484fSRodney W. Grimes.Fn fropen "void *cookie" "int (*readfn)(void *, char *, int)"
4958f0484fSRodney W. Grimes.Ft FILE *
50e295af15SPaul Traina.Fn fwopen "void *cookie" "int (*writefn)(void *, const char *, int)"
5158f0484fSRodney W. Grimes.Sh DESCRIPTION
5258f0484fSRodney W. GrimesThe
5358f0484fSRodney W. Grimes.Fn funopen
5458f0484fSRodney W. Grimesfunction
5558f0484fSRodney W. Grimesassociates a stream with up to four
5658f0484fSRodney W. Grimes.Dq Tn I/O No functions .
5758f0484fSRodney W. GrimesEither
5858f0484fSRodney W. Grimes.Fa readfn
5958f0484fSRodney W. Grimesor
6058f0484fSRodney W. Grimes.Fa writefn
6158f0484fSRodney W. Grimesmust be specified;
6258f0484fSRodney W. Grimesthe others can be given as an appropriately-typed
6358f0484fSRodney W. Grimes.Dv NULL
6458f0484fSRodney W. Grimespointer.
6558f0484fSRodney W. GrimesThese
6658f0484fSRodney W. Grimes.Tn I/O
6758f0484fSRodney W. Grimesfunctions will be used to read, write, seek and
6858f0484fSRodney W. Grimesclose the new stream.
6958f0484fSRodney W. Grimes.Pp
7058f0484fSRodney W. GrimesIn general, omitting a function means that any attempt to perform the
7158f0484fSRodney W. Grimesassociated operation on the resulting stream will fail.
7258f0484fSRodney W. GrimesIf the close function is omitted, closing the stream will flush
7358f0484fSRodney W. Grimesany buffered output and then succeed.
7458f0484fSRodney W. Grimes.Pp
7558f0484fSRodney W. GrimesThe calling conventions of
7658f0484fSRodney W. Grimes.Fa readfn ,
7758f0484fSRodney W. Grimes.Fa writefn ,
7858f0484fSRodney W. Grimes.Fa seekfn
7958f0484fSRodney W. Grimesand
8058f0484fSRodney W. Grimes.Fa closefn
8158f0484fSRodney W. Grimesmust match those, respectively, of
8258f0484fSRodney W. Grimes.Xr read 2 ,
8358f0484fSRodney W. Grimes.Xr write 2 ,
84bf351925SAndrey A. Chernov.Xr lseek 2 ,
8558f0484fSRodney W. Grimesand
8658f0484fSRodney W. Grimes.Xr close 2
8758f0484fSRodney W. Grimeswith the single exception that they are passed the
8858f0484fSRodney W. Grimes.Fa cookie
8958f0484fSRodney W. Grimesargument specified to
9058f0484fSRodney W. Grimes.Fn funopen
9158f0484fSRodney W. Grimesin place of the traditional file descriptor argument.
9258f0484fSRodney W. Grimes.Pp
9358f0484fSRodney W. GrimesRead and write
9458f0484fSRodney W. Grimes.Tn I/O
9558f0484fSRodney W. Grimesfunctions are allowed to change the underlying buffer
9658f0484fSRodney W. Grimeson fully buffered or line buffered streams by calling
9758f0484fSRodney W. Grimes.Xr setvbuf 3 .
9858f0484fSRodney W. GrimesThey are also not required to completely fill or empty the buffer.
9958f0484fSRodney W. GrimesThey are not, however, allowed to change streams from unbuffered to buffered
10058f0484fSRodney W. Grimesor to change the state of the line buffering flag.
10158f0484fSRodney W. GrimesThey must also be prepared to have read or write calls occur on buffers other
10258f0484fSRodney W. Grimesthan the one most recently specified.
10358f0484fSRodney W. Grimes.Pp
10458f0484fSRodney W. GrimesAll user
10558f0484fSRodney W. Grimes.Tn I/O
10658f0484fSRodney W. Grimesfunctions can report an error by returning \-1.
10758f0484fSRodney W. GrimesAdditionally, all of the functions should set the external variable
10858f0484fSRodney W. Grimes.Va errno
10958f0484fSRodney W. Grimesappropriately if an error occurs.
11058f0484fSRodney W. Grimes.Pp
11158f0484fSRodney W. GrimesAn error on
11258f0484fSRodney W. Grimes.Fn closefn
11358f0484fSRodney W. Grimesdoes not keep the stream open.
11458f0484fSRodney W. Grimes.Pp
11558f0484fSRodney W. GrimesAs a convenience, the include file
116fe08efe6SRuslan Ermilov.In stdio.h
11758f0484fSRodney W. Grimesdefines the macros
11858f0484fSRodney W. Grimes.Fn fropen
11958f0484fSRodney W. Grimesand
12058f0484fSRodney W. Grimes.Fn fwopen
12158f0484fSRodney W. Grimesas calls to
12258f0484fSRodney W. Grimes.Fn funopen
12358f0484fSRodney W. Grimeswith only a read or write function specified.
12458f0484fSRodney W. Grimes.Sh RETURN VALUES
12558f0484fSRodney W. GrimesUpon successful completion,
12658f0484fSRodney W. Grimes.Fn funopen
12758f0484fSRodney W. Grimesreturns a
12858f0484fSRodney W. Grimes.Dv FILE
12958f0484fSRodney W. Grimespointer.
13058f0484fSRodney W. GrimesOtherwise,
13158f0484fSRodney W. Grimes.Dv NULL
13258f0484fSRodney W. Grimesis returned and the global variable
13358f0484fSRodney W. Grimes.Va errno
13458f0484fSRodney W. Grimesis set to indicate the error.
13558f0484fSRodney W. Grimes.Sh ERRORS
13603fc6303SAlexey Zelkin.Bl -tag -width Er
13758f0484fSRodney W. Grimes.It Bq Er EINVAL
13858f0484fSRodney W. GrimesThe
13958f0484fSRodney W. Grimes.Fn funopen
14058f0484fSRodney W. Grimesfunction
14158f0484fSRodney W. Grimeswas called without either a read or write function.
14258f0484fSRodney W. GrimesThe
14358f0484fSRodney W. Grimes.Fn funopen
14458f0484fSRodney W. Grimesfunction
14558f0484fSRodney W. Grimesmay also fail and set
14658f0484fSRodney W. Grimes.Va errno
14758f0484fSRodney W. Grimesfor any of the errors
14858f0484fSRodney W. Grimesspecified for the routine
14958f0484fSRodney W. Grimes.Xr malloc 3 .
15058f0484fSRodney W. Grimes.El
15158f0484fSRodney W. Grimes.Sh SEE ALSO
15258f0484fSRodney W. Grimes.Xr fcntl 2 ,
15358f0484fSRodney W. Grimes.Xr open 2 ,
15458f0484fSRodney W. Grimes.Xr fclose 3 ,
15558f0484fSRodney W. Grimes.Xr fopen 3 ,
156877a840cSConrad Meyer.Xr fopencookie 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 .
1706eb5892cSTim J. Robbins.Pp
1716eb5892cSTim J. RobbinsThe
1726eb5892cSTim J. Robbins.Fn funopen
1736eb5892cSTim J. Robbinsinterface erroneously assumes that
1746eb5892cSTim J. Robbins.Vt fpos_t
1756eb5892cSTim J. Robbinsis an integral type; see
1766eb5892cSTim J. Robbins.Xr fseek 3
1776eb5892cSTim J. Robbinsfor a discussion of this issue.
178