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.\" 30877a840cSConrad Meyer.Dd May 9, 2016 3158f0484fSRodney W. Grimes.Dt FUNOPEN 3 3258f0484fSRodney W. Grimes.Os 3358f0484fSRodney W. Grimes.Sh NAME 3458f0484fSRodney W. Grimes.Nm funopen , 3558f0484fSRodney W. Grimes.Nm fropen , 3658f0484fSRodney W. Grimes.Nm fwopen 3758f0484fSRodney W. Grimes.Nd open a stream 3825bb73e0SAlexey Zelkin.Sh LIBRARY 3925bb73e0SAlexey Zelkin.Lb libc 4058f0484fSRodney W. Grimes.Sh SYNOPSIS 4132eef9aeSRuslan Ermilov.In stdio.h 4258f0484fSRodney W. Grimes.Ft FILE * 4323f0c1fcSBruce 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 *)" 4458f0484fSRodney W. Grimes.Ft FILE * 4558f0484fSRodney W. Grimes.Fn fropen "void *cookie" "int (*readfn)(void *, char *, int)" 4658f0484fSRodney W. Grimes.Ft FILE * 47e295af15SPaul Traina.Fn fwopen "void *cookie" "int (*writefn)(void *, const char *, int)" 4858f0484fSRodney W. Grimes.Sh DESCRIPTION 4958f0484fSRodney W. GrimesThe 5058f0484fSRodney W. Grimes.Fn funopen 5158f0484fSRodney W. Grimesfunction 5258f0484fSRodney W. Grimesassociates a stream with up to four 5358f0484fSRodney W. Grimes.Dq Tn I/O No functions . 5458f0484fSRodney W. GrimesEither 5558f0484fSRodney W. Grimes.Fa readfn 5658f0484fSRodney W. Grimesor 5758f0484fSRodney W. Grimes.Fa writefn 5858f0484fSRodney W. Grimesmust be specified; 5958f0484fSRodney W. Grimesthe others can be given as an appropriately-typed 6058f0484fSRodney W. Grimes.Dv NULL 6158f0484fSRodney W. Grimespointer. 6258f0484fSRodney W. GrimesThese 6358f0484fSRodney W. Grimes.Tn I/O 6458f0484fSRodney W. Grimesfunctions will be used to read, write, seek and 6558f0484fSRodney W. Grimesclose the new stream. 6658f0484fSRodney W. Grimes.Pp 6758f0484fSRodney W. GrimesIn general, omitting a function means that any attempt to perform the 6858f0484fSRodney W. Grimesassociated operation on the resulting stream will fail. 6958f0484fSRodney W. GrimesIf the close function is omitted, closing the stream will flush 7058f0484fSRodney W. Grimesany buffered output and then succeed. 7158f0484fSRodney W. Grimes.Pp 7258f0484fSRodney W. GrimesThe calling conventions of 7358f0484fSRodney W. Grimes.Fa readfn , 7458f0484fSRodney W. Grimes.Fa writefn , 7558f0484fSRodney W. Grimes.Fa seekfn 7658f0484fSRodney W. Grimesand 7758f0484fSRodney W. Grimes.Fa closefn 7858f0484fSRodney W. Grimesmust match those, respectively, of 7958f0484fSRodney W. Grimes.Xr read 2 , 8058f0484fSRodney W. Grimes.Xr write 2 , 81bf351925SAndrey A. Chernov.Xr lseek 2 , 8258f0484fSRodney W. Grimesand 8358f0484fSRodney W. Grimes.Xr close 2 8458f0484fSRodney W. Grimeswith the single exception that they are passed the 8558f0484fSRodney W. Grimes.Fa cookie 8658f0484fSRodney W. Grimesargument specified to 8758f0484fSRodney W. Grimes.Fn funopen 8858f0484fSRodney W. Grimesin place of the traditional file descriptor argument. 8958f0484fSRodney W. Grimes.Pp 9058f0484fSRodney W. GrimesRead and write 9158f0484fSRodney W. Grimes.Tn I/O 9258f0484fSRodney W. Grimesfunctions are allowed to change the underlying buffer 9358f0484fSRodney W. Grimeson fully buffered or line buffered streams by calling 9458f0484fSRodney W. Grimes.Xr setvbuf 3 . 9558f0484fSRodney W. GrimesThey are also not required to completely fill or empty the buffer. 9658f0484fSRodney W. GrimesThey are not, however, allowed to change streams from unbuffered to buffered 9758f0484fSRodney W. Grimesor to change the state of the line buffering flag. 9858f0484fSRodney W. GrimesThey must also be prepared to have read or write calls occur on buffers other 9958f0484fSRodney W. Grimesthan the one most recently specified. 10058f0484fSRodney W. Grimes.Pp 10158f0484fSRodney W. GrimesAll user 10258f0484fSRodney W. Grimes.Tn I/O 10358f0484fSRodney W. Grimesfunctions can report an error by returning \-1. 10458f0484fSRodney W. GrimesAdditionally, all of the functions should set the external variable 10558f0484fSRodney W. Grimes.Va errno 10658f0484fSRodney W. Grimesappropriately if an error occurs. 10758f0484fSRodney W. Grimes.Pp 10858f0484fSRodney W. GrimesAn error on 10958f0484fSRodney W. Grimes.Fn closefn 11058f0484fSRodney W. Grimesdoes not keep the stream open. 11158f0484fSRodney W. Grimes.Pp 11258f0484fSRodney W. GrimesAs a convenience, the include file 113fe08efe6SRuslan Ermilov.In stdio.h 11458f0484fSRodney W. Grimesdefines the macros 11558f0484fSRodney W. Grimes.Fn fropen 11658f0484fSRodney W. Grimesand 11758f0484fSRodney W. Grimes.Fn fwopen 11858f0484fSRodney W. Grimesas calls to 11958f0484fSRodney W. Grimes.Fn funopen 12058f0484fSRodney W. Grimeswith only a read or write function specified. 12158f0484fSRodney W. Grimes.Sh RETURN VALUES 12258f0484fSRodney W. GrimesUpon successful completion, 12358f0484fSRodney W. Grimes.Fn funopen 12458f0484fSRodney W. Grimesreturns a 12558f0484fSRodney W. Grimes.Dv FILE 12658f0484fSRodney W. Grimespointer. 12758f0484fSRodney W. GrimesOtherwise, 12858f0484fSRodney W. Grimes.Dv NULL 12958f0484fSRodney W. Grimesis returned and the global variable 13058f0484fSRodney W. Grimes.Va errno 13158f0484fSRodney W. Grimesis set to indicate the error. 13258f0484fSRodney W. Grimes.Sh ERRORS 13303fc6303SAlexey Zelkin.Bl -tag -width Er 13458f0484fSRodney W. Grimes.It Bq Er EINVAL 13558f0484fSRodney W. GrimesThe 13658f0484fSRodney W. Grimes.Fn funopen 13758f0484fSRodney W. Grimesfunction 13858f0484fSRodney W. Grimeswas called without either a read or write function. 13958f0484fSRodney W. GrimesThe 14058f0484fSRodney W. Grimes.Fn funopen 14158f0484fSRodney W. Grimesfunction 14258f0484fSRodney W. Grimesmay also fail and set 14358f0484fSRodney W. Grimes.Va errno 14458f0484fSRodney W. Grimesfor any of the errors 14558f0484fSRodney W. Grimesspecified for the routine 14658f0484fSRodney W. Grimes.Xr malloc 3 . 14758f0484fSRodney W. Grimes.El 14858f0484fSRodney W. Grimes.Sh SEE ALSO 14958f0484fSRodney W. Grimes.Xr fcntl 2 , 15058f0484fSRodney W. Grimes.Xr open 2 , 15158f0484fSRodney W. Grimes.Xr fclose 3 , 15258f0484fSRodney W. Grimes.Xr fopen 3 , 153877a840cSConrad Meyer.Xr fopencookie 3 , 15458f0484fSRodney W. Grimes.Xr fseek 3 , 15558f0484fSRodney W. Grimes.Xr setbuf 3 15658f0484fSRodney W. Grimes.Sh HISTORY 15758f0484fSRodney W. GrimesThe 15858f0484fSRodney W. Grimes.Fn funopen 1597bdf80e5SMike Pritchardfunctions first appeared in 1607bdf80e5SMike Pritchard.Bx 4.4 . 16158f0484fSRodney W. Grimes.Sh BUGS 16258f0484fSRodney W. GrimesThe 16358f0484fSRodney W. Grimes.Fn funopen 16458f0484fSRodney W. Grimesfunction 16558f0484fSRodney W. Grimesmay not be portable to systems other than 16658f0484fSRodney W. Grimes.Bx . 1676eb5892cSTim J. Robbins.Pp 1686eb5892cSTim J. RobbinsThe 1696eb5892cSTim J. Robbins.Fn funopen 1706eb5892cSTim J. Robbinsinterface erroneously assumes that 1716eb5892cSTim J. Robbins.Vt fpos_t 1726eb5892cSTim J. Robbinsis an integral type; see 1736eb5892cSTim J. Robbins.Xr fseek 3 1746eb5892cSTim J. Robbinsfor a discussion of this issue. 175