1877a840cSConrad Meyer.\" Copyright (c) 2016, EMC / Isilon Storage Division 2877a840cSConrad Meyer.\" All rights reserved. 3877a840cSConrad Meyer.\" 4877a840cSConrad Meyer.\" Redistribution and use in source and binary forms, with or without 5877a840cSConrad Meyer.\" modification, are permitted provided that the following conditions 6877a840cSConrad Meyer.\" are met: 7877a840cSConrad Meyer.\" 1. Redistributions of source code must retain the above copyright 8877a840cSConrad Meyer.\" notice, this list of conditions and the following disclaimer. 9877a840cSConrad Meyer.\" 2. Redistributions in binary form must reproduce the above copyright 10877a840cSConrad Meyer.\" notice, this list of conditions and the following disclaimer in the 11877a840cSConrad Meyer.\" documentation and/or other materials provided with the distribution. 12877a840cSConrad Meyer.\" 13877a840cSConrad Meyer.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 14877a840cSConrad Meyer.\" IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15877a840cSConrad Meyer.\" THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16877a840cSConrad Meyer.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR 17877a840cSConrad Meyer.\" CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18877a840cSConrad Meyer.\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19877a840cSConrad Meyer.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 20877a840cSConrad Meyer.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 21877a840cSConrad Meyer.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 22877a840cSConrad Meyer.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 23877a840cSConrad Meyer.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24877a840cSConrad Meyer.\" 25877a840cSConrad Meyer.Dd May 9, 2016 26877a840cSConrad Meyer.Dt FOPENCOOKIE 3 27877a840cSConrad Meyer.Os 28877a840cSConrad Meyer.Sh NAME 29877a840cSConrad Meyer.Nm fopencookie 30877a840cSConrad Meyer.Nd open a stream 31877a840cSConrad Meyer.Sh LIBRARY 32877a840cSConrad Meyer.Lb libc 33877a840cSConrad Meyer.Sh SYNOPSIS 34877a840cSConrad Meyer.In stdio.h 35877a840cSConrad Meyer.Ft typedef ssize_t 36*2a105685SEnji Cooper.Fn (*cookie_read_function_t) "void *cookie" "char *buf" "size_t size" 37877a840cSConrad Meyer.Ft typedef ssize_t 38*2a105685SEnji Cooper.Fn (*cookie_write_function_t) "void *cookie" "const char *buf" "size_t size" 39877a840cSConrad Meyer.Ft typedef int 40*2a105685SEnji Cooper.Fn (*cookie_seek_function_t) "void *cookie" "off64_t *offset" "int whence" 41877a840cSConrad Meyer.Ft typedef int 42*2a105685SEnji Cooper.Fn (*cookie_close_function_t) "void *cookie" 43877a840cSConrad Meyer.Bd -literal 44877a840cSConrad Meyertypedef struct { 45877a840cSConrad Meyer cookie_read_function_t *read; 46877a840cSConrad Meyer cookie_write_function_t *write; 47877a840cSConrad Meyer cookie_seek_function_t *seek; 48877a840cSConrad Meyer cookie_close_function_t *close; 49877a840cSConrad Meyer} cookie_io_functions_t; 50877a840cSConrad Meyer.Ed 51877a840cSConrad Meyer.Ft FILE * 52877a840cSConrad Meyer.Fn fopencookie "void *cookie" "const char *mode" "cookie_io_functions_t io_funcs" 53877a840cSConrad Meyer.Sh DESCRIPTION 54877a840cSConrad MeyerThe 55877a840cSConrad Meyer.Nm 56877a840cSConrad Meyerfunction 57877a840cSConrad Meyerassociates a stream with up to four 58877a840cSConrad Meyer.Dq Tn I/O No functions . 59877a840cSConrad MeyerThese 60877a840cSConrad Meyer.Tn I/O 61877a840cSConrad Meyerfunctions will be used to read, write, seek and 62877a840cSConrad Meyerclose the new stream. 63877a840cSConrad Meyer.Pp 64877a840cSConrad MeyerIn general, omitting a function means that any attempt to perform the 65877a840cSConrad Meyerassociated operation on the resulting stream will fail. 66877a840cSConrad MeyerIf the write function is omitted, data written to the stream is discarded. 67877a840cSConrad MeyerIf the close function is omitted, closing the stream will flush 68877a840cSConrad Meyerany buffered output and then succeed. 69877a840cSConrad Meyer.Pp 70877a840cSConrad MeyerThe calling conventions of 71877a840cSConrad Meyer.Fa read , 72877a840cSConrad Meyer.Fa write , 73877a840cSConrad Meyerand 74877a840cSConrad Meyer.Fa close 75877a840cSConrad Meyermust match those, respectively, of 76877a840cSConrad Meyer.Xr read 2 , 77877a840cSConrad Meyer.Xr write 2 , 78877a840cSConrad Meyerand 79877a840cSConrad Meyer.Xr close 2 80877a840cSConrad Meyerwith the single exception that they are passed the 81877a840cSConrad Meyer.Fa cookie 82877a840cSConrad Meyerargument specified to 83877a840cSConrad Meyer.Nm 84877a840cSConrad Meyerin place of the traditional file descriptor argument. 85877a840cSConrad MeyerThe 86877a840cSConrad Meyer.Fa seek 87877a840cSConrad Meyerfunction updates the current stream offset using 88877a840cSConrad Meyer.Fa *offset 89877a840cSConrad Meyerand 90877a840cSConrad Meyer.Fa whence . 91877a840cSConrad MeyerIf 92877a840cSConrad Meyer.Fa *offset 93877a840cSConrad Meyeris non-NULL, it updates 94877a840cSConrad Meyer.Fa *offset 95877a840cSConrad Meyerwith the current stream offset. 96877a840cSConrad Meyer.Pp 97877a840cSConrad Meyer.Nm 98877a840cSConrad Meyeris implemented as a thin shim around the 99877a840cSConrad Meyer.Xr funopen 3 100877a840cSConrad Meyerinterface. 101877a840cSConrad MeyerLimitations, possibilities, and requirements of that interface apply to 102877a840cSConrad Meyer.Nm . 103877a840cSConrad Meyer.Sh RETURN VALUES 104877a840cSConrad MeyerUpon successful completion, 105877a840cSConrad Meyer.Nm 106877a840cSConrad Meyerreturns a 107877a840cSConrad Meyer.Dv FILE 108877a840cSConrad Meyerpointer. 109877a840cSConrad MeyerOtherwise, 110877a840cSConrad Meyer.Dv NULL 111877a840cSConrad Meyeris returned and the global variable 112877a840cSConrad Meyer.Va errno 113877a840cSConrad Meyeris set to indicate the error. 114877a840cSConrad Meyer.Sh ERRORS 115877a840cSConrad Meyer.Bl -tag -width Er 116877a840cSConrad Meyer.It Bq Er EINVAL 117877a840cSConrad MeyerA bogus 118877a840cSConrad Meyer.Fa mode 119877a840cSConrad Meyerwas provided to 120877a840cSConrad Meyer.Nm . 121877a840cSConrad Meyer.It Bq Er ENOMEM 122877a840cSConrad MeyerThe 123877a840cSConrad Meyer.Nm 124877a840cSConrad Meyerfunction 125877a840cSConrad Meyermay fail and set 126877a840cSConrad Meyer.Va errno 127877a840cSConrad Meyerfor any of the errors 128877a840cSConrad Meyerspecified for the 129877a840cSConrad Meyer.Xr malloc 3 130877a840cSConrad Meyerroutine. 131877a840cSConrad Meyer.El 132877a840cSConrad Meyer.Sh SEE ALSO 133877a840cSConrad Meyer.Xr fcntl 2 , 134877a840cSConrad Meyer.Xr open 2 , 135877a840cSConrad Meyer.Xr fclose 3 , 136877a840cSConrad Meyer.Xr fopen 3 , 137877a840cSConrad Meyer.Xr fseek 3 , 138877a840cSConrad Meyer.Xr funopen 3 139877a840cSConrad Meyer.Sh HISTORY 140877a840cSConrad MeyerThe 141877a840cSConrad Meyer.Fn funopen 142877a840cSConrad Meyerfunctions first appeared in 143877a840cSConrad Meyer.Bx 4.4 . 144877a840cSConrad MeyerThe 145877a840cSConrad Meyer.Nm 146877a840cSConrad Meyerfunction first appeared in 147877a840cSConrad Meyer.Fx 11 . 148877a840cSConrad Meyer.Sh BUGS 149877a840cSConrad MeyerThe 150877a840cSConrad Meyer.Nm 151877a840cSConrad Meyerfunction is a nonstandard glibc extension and may not be portable to systems 152877a840cSConrad Meyerother than 153877a840cSConrad Meyer.Fx 154877a840cSConrad Meyerand Linux. 155