1*877a840cSConrad Meyer.\" Copyright (c) 2016, EMC / Isilon Storage Division 2*877a840cSConrad Meyer.\" All rights reserved. 3*877a840cSConrad Meyer.\" 4*877a840cSConrad Meyer.\" Redistribution and use in source and binary forms, with or without 5*877a840cSConrad Meyer.\" modification, are permitted provided that the following conditions 6*877a840cSConrad Meyer.\" are met: 7*877a840cSConrad Meyer.\" 1. Redistributions of source code must retain the above copyright 8*877a840cSConrad Meyer.\" notice, this list of conditions and the following disclaimer. 9*877a840cSConrad Meyer.\" 2. Redistributions in binary form must reproduce the above copyright 10*877a840cSConrad Meyer.\" notice, this list of conditions and the following disclaimer in the 11*877a840cSConrad Meyer.\" documentation and/or other materials provided with the distribution. 12*877a840cSConrad Meyer.\" 13*877a840cSConrad Meyer.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 14*877a840cSConrad Meyer.\" IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15*877a840cSConrad Meyer.\" THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16*877a840cSConrad Meyer.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR 17*877a840cSConrad Meyer.\" CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18*877a840cSConrad Meyer.\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19*877a840cSConrad Meyer.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 20*877a840cSConrad Meyer.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 21*877a840cSConrad Meyer.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 22*877a840cSConrad Meyer.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 23*877a840cSConrad Meyer.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24*877a840cSConrad Meyer.\" 25*877a840cSConrad Meyer.\" $FreeBSD$ 26*877a840cSConrad Meyer.\" 27*877a840cSConrad Meyer.Dd May 9, 2016 28*877a840cSConrad Meyer.Dt FOPENCOOKIE 3 29*877a840cSConrad Meyer.Os 30*877a840cSConrad Meyer.Sh NAME 31*877a840cSConrad Meyer.Nm fopencookie 32*877a840cSConrad Meyer.Nd open a stream 33*877a840cSConrad Meyer.Sh LIBRARY 34*877a840cSConrad Meyer.Lb libc 35*877a840cSConrad Meyer.Sh SYNOPSIS 36*877a840cSConrad Meyer.In stdio.h 37*877a840cSConrad Meyer.Ft typedef ssize_t 38*877a840cSConrad Meyer.Fn (cookie_read_function_t) "void *cookie" "char *buf" "size_t size" 39*877a840cSConrad Meyer.Ft typedef ssize_t 40*877a840cSConrad Meyer.Fn (cookie_write_function_t) "void *cookie" "const char *buf" "size_t size" 41*877a840cSConrad Meyer.Ft typedef int 42*877a840cSConrad Meyer.Fn (cookie_seek_function_t) "void *cookie" "off64_t *offset" "int whence" 43*877a840cSConrad Meyer.Ft typedef int 44*877a840cSConrad Meyer.Fn (cookie_close_function_t) "void *cookie" 45*877a840cSConrad Meyer.Bd -literal 46*877a840cSConrad Meyertypedef struct { 47*877a840cSConrad Meyer cookie_read_function_t *read; 48*877a840cSConrad Meyer cookie_write_function_t *write; 49*877a840cSConrad Meyer cookie_seek_function_t *seek; 50*877a840cSConrad Meyer cookie_close_function_t *close; 51*877a840cSConrad Meyer} cookie_io_functions_t; 52*877a840cSConrad Meyer.Ed 53*877a840cSConrad Meyer.Ft FILE * 54*877a840cSConrad Meyer.Fn fopencookie "void *cookie" "const char *mode" "cookie_io_functions_t io_funcs" 55*877a840cSConrad Meyer.Sh DESCRIPTION 56*877a840cSConrad MeyerThe 57*877a840cSConrad Meyer.Nm 58*877a840cSConrad Meyerfunction 59*877a840cSConrad Meyerassociates a stream with up to four 60*877a840cSConrad Meyer.Dq Tn I/O No functions . 61*877a840cSConrad MeyerThese 62*877a840cSConrad Meyer.Tn I/O 63*877a840cSConrad Meyerfunctions will be used to read, write, seek and 64*877a840cSConrad Meyerclose the new stream. 65*877a840cSConrad Meyer.Pp 66*877a840cSConrad MeyerIn general, omitting a function means that any attempt to perform the 67*877a840cSConrad Meyerassociated operation on the resulting stream will fail. 68*877a840cSConrad MeyerIf the write function is omitted, data written to the stream is discarded. 69*877a840cSConrad MeyerIf the close function is omitted, closing the stream will flush 70*877a840cSConrad Meyerany buffered output and then succeed. 71*877a840cSConrad Meyer.Pp 72*877a840cSConrad MeyerThe calling conventions of 73*877a840cSConrad Meyer.Fa read , 74*877a840cSConrad Meyer.Fa write , 75*877a840cSConrad Meyerand 76*877a840cSConrad Meyer.Fa close 77*877a840cSConrad Meyermust match those, respectively, of 78*877a840cSConrad Meyer.Xr read 2 , 79*877a840cSConrad Meyer.Xr write 2 , 80*877a840cSConrad Meyerand 81*877a840cSConrad Meyer.Xr close 2 82*877a840cSConrad Meyerwith the single exception that they are passed the 83*877a840cSConrad Meyer.Fa cookie 84*877a840cSConrad Meyerargument specified to 85*877a840cSConrad Meyer.Nm 86*877a840cSConrad Meyerin place of the traditional file descriptor argument. 87*877a840cSConrad MeyerThe 88*877a840cSConrad Meyer.Fa seek 89*877a840cSConrad Meyerfunction updates the current stream offset using 90*877a840cSConrad Meyer.Fa *offset 91*877a840cSConrad Meyerand 92*877a840cSConrad Meyer.Fa whence . 93*877a840cSConrad MeyerIf 94*877a840cSConrad Meyer.Fa *offset 95*877a840cSConrad Meyeris non-NULL, it updates 96*877a840cSConrad Meyer.Fa *offset 97*877a840cSConrad Meyerwith the current stream offset. 98*877a840cSConrad Meyer.Pp 99*877a840cSConrad Meyer.Nm 100*877a840cSConrad Meyeris implemented as a thin shim around the 101*877a840cSConrad Meyer.Xr funopen 3 102*877a840cSConrad Meyerinterface. 103*877a840cSConrad MeyerLimitations, possibilities, and requirements of that interface apply to 104*877a840cSConrad Meyer.Nm . 105*877a840cSConrad Meyer.Sh RETURN VALUES 106*877a840cSConrad MeyerUpon successful completion, 107*877a840cSConrad Meyer.Nm 108*877a840cSConrad Meyerreturns a 109*877a840cSConrad Meyer.Dv FILE 110*877a840cSConrad Meyerpointer. 111*877a840cSConrad MeyerOtherwise, 112*877a840cSConrad Meyer.Dv NULL 113*877a840cSConrad Meyeris returned and the global variable 114*877a840cSConrad Meyer.Va errno 115*877a840cSConrad Meyeris set to indicate the error. 116*877a840cSConrad Meyer.Sh ERRORS 117*877a840cSConrad Meyer.Bl -tag -width Er 118*877a840cSConrad Meyer.It Bq Er EINVAL 119*877a840cSConrad MeyerA bogus 120*877a840cSConrad Meyer.Fa mode 121*877a840cSConrad Meyerwas provided to 122*877a840cSConrad Meyer.Nm . 123*877a840cSConrad Meyer.It Bq Er ENOMEM 124*877a840cSConrad MeyerThe 125*877a840cSConrad Meyer.Nm 126*877a840cSConrad Meyerfunction 127*877a840cSConrad Meyermay fail and set 128*877a840cSConrad Meyer.Va errno 129*877a840cSConrad Meyerfor any of the errors 130*877a840cSConrad Meyerspecified for the 131*877a840cSConrad Meyer.Xr malloc 3 132*877a840cSConrad Meyerroutine. 133*877a840cSConrad Meyer.El 134*877a840cSConrad Meyer.Sh SEE ALSO 135*877a840cSConrad Meyer.Xr fcntl 2 , 136*877a840cSConrad Meyer.Xr open 2 , 137*877a840cSConrad Meyer.Xr fclose 3 , 138*877a840cSConrad Meyer.Xr fopen 3 , 139*877a840cSConrad Meyer.Xr fseek 3 , 140*877a840cSConrad Meyer.Xr funopen 3 141*877a840cSConrad Meyer.Sh HISTORY 142*877a840cSConrad MeyerThe 143*877a840cSConrad Meyer.Fn funopen 144*877a840cSConrad Meyerfunctions first appeared in 145*877a840cSConrad Meyer.Bx 4.4 . 146*877a840cSConrad MeyerThe 147*877a840cSConrad Meyer.Nm 148*877a840cSConrad Meyerfunction first appeared in 149*877a840cSConrad Meyer.Fx 11 . 150*877a840cSConrad Meyer.Sh BUGS 151*877a840cSConrad MeyerThe 152*877a840cSConrad Meyer.Nm 153*877a840cSConrad Meyerfunction is a nonstandard glibc extension and may not be portable to systems 154*877a840cSConrad Meyerother than 155*877a840cSConrad Meyer.Fx 156*877a840cSConrad Meyerand Linux. 157