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