xref: /freebsd/lib/libc/stdio/fopencookie.3 (revision 2a105685d2c7f97a5b01d4e38ec3ff0a338c4cc5)
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.\" $FreeBSD$
26877a840cSConrad Meyer.\"
27877a840cSConrad Meyer.Dd May 9, 2016
28877a840cSConrad Meyer.Dt FOPENCOOKIE 3
29877a840cSConrad Meyer.Os
30877a840cSConrad Meyer.Sh NAME
31877a840cSConrad Meyer.Nm fopencookie
32877a840cSConrad Meyer.Nd open a stream
33877a840cSConrad Meyer.Sh LIBRARY
34877a840cSConrad Meyer.Lb libc
35877a840cSConrad Meyer.Sh SYNOPSIS
36877a840cSConrad Meyer.In stdio.h
37877a840cSConrad Meyer.Ft typedef ssize_t
38*2a105685SEnji Cooper.Fn (*cookie_read_function_t) "void *cookie" "char *buf" "size_t size"
39877a840cSConrad Meyer.Ft typedef ssize_t
40*2a105685SEnji Cooper.Fn (*cookie_write_function_t) "void *cookie" "const char *buf" "size_t size"
41877a840cSConrad Meyer.Ft typedef int
42*2a105685SEnji Cooper.Fn (*cookie_seek_function_t) "void *cookie" "off64_t *offset" "int whence"
43877a840cSConrad Meyer.Ft typedef int
44*2a105685SEnji Cooper.Fn (*cookie_close_function_t) "void *cookie"
45877a840cSConrad Meyer.Bd -literal
46877a840cSConrad Meyertypedef struct {
47877a840cSConrad Meyer	cookie_read_function_t	*read;
48877a840cSConrad Meyer	cookie_write_function_t	*write;
49877a840cSConrad Meyer	cookie_seek_function_t	*seek;
50877a840cSConrad Meyer	cookie_close_function_t	*close;
51877a840cSConrad Meyer} cookie_io_functions_t;
52877a840cSConrad Meyer.Ed
53877a840cSConrad Meyer.Ft FILE *
54877a840cSConrad Meyer.Fn fopencookie "void *cookie" "const char *mode" "cookie_io_functions_t io_funcs"
55877a840cSConrad Meyer.Sh DESCRIPTION
56877a840cSConrad MeyerThe
57877a840cSConrad Meyer.Nm
58877a840cSConrad Meyerfunction
59877a840cSConrad Meyerassociates a stream with up to four
60877a840cSConrad Meyer.Dq Tn I/O No functions .
61877a840cSConrad MeyerThese
62877a840cSConrad Meyer.Tn I/O
63877a840cSConrad Meyerfunctions will be used to read, write, seek and
64877a840cSConrad Meyerclose the new stream.
65877a840cSConrad Meyer.Pp
66877a840cSConrad MeyerIn general, omitting a function means that any attempt to perform the
67877a840cSConrad Meyerassociated operation on the resulting stream will fail.
68877a840cSConrad MeyerIf the write function is omitted, data written to the stream is discarded.
69877a840cSConrad MeyerIf the close function is omitted, closing the stream will flush
70877a840cSConrad Meyerany buffered output and then succeed.
71877a840cSConrad Meyer.Pp
72877a840cSConrad MeyerThe calling conventions of
73877a840cSConrad Meyer.Fa read ,
74877a840cSConrad Meyer.Fa write ,
75877a840cSConrad Meyerand
76877a840cSConrad Meyer.Fa close
77877a840cSConrad Meyermust match those, respectively, of
78877a840cSConrad Meyer.Xr read 2 ,
79877a840cSConrad Meyer.Xr write 2 ,
80877a840cSConrad Meyerand
81877a840cSConrad Meyer.Xr close 2
82877a840cSConrad Meyerwith the single exception that they are passed the
83877a840cSConrad Meyer.Fa cookie
84877a840cSConrad Meyerargument specified to
85877a840cSConrad Meyer.Nm
86877a840cSConrad Meyerin place of the traditional file descriptor argument.
87877a840cSConrad MeyerThe
88877a840cSConrad Meyer.Fa seek
89877a840cSConrad Meyerfunction updates the current stream offset using
90877a840cSConrad Meyer.Fa *offset
91877a840cSConrad Meyerand
92877a840cSConrad Meyer.Fa whence .
93877a840cSConrad MeyerIf
94877a840cSConrad Meyer.Fa *offset
95877a840cSConrad Meyeris non-NULL, it updates
96877a840cSConrad Meyer.Fa *offset
97877a840cSConrad Meyerwith the current stream offset.
98877a840cSConrad Meyer.Pp
99877a840cSConrad Meyer.Nm
100877a840cSConrad Meyeris implemented as a thin shim around the
101877a840cSConrad Meyer.Xr funopen 3
102877a840cSConrad Meyerinterface.
103877a840cSConrad MeyerLimitations, possibilities, and requirements of that interface apply to
104877a840cSConrad Meyer.Nm .
105877a840cSConrad Meyer.Sh RETURN VALUES
106877a840cSConrad MeyerUpon successful completion,
107877a840cSConrad Meyer.Nm
108877a840cSConrad Meyerreturns a
109877a840cSConrad Meyer.Dv FILE
110877a840cSConrad Meyerpointer.
111877a840cSConrad MeyerOtherwise,
112877a840cSConrad Meyer.Dv NULL
113877a840cSConrad Meyeris returned and the global variable
114877a840cSConrad Meyer.Va errno
115877a840cSConrad Meyeris set to indicate the error.
116877a840cSConrad Meyer.Sh ERRORS
117877a840cSConrad Meyer.Bl -tag -width Er
118877a840cSConrad Meyer.It Bq Er EINVAL
119877a840cSConrad MeyerA bogus
120877a840cSConrad Meyer.Fa mode
121877a840cSConrad Meyerwas provided to
122877a840cSConrad Meyer.Nm .
123877a840cSConrad Meyer.It Bq Er ENOMEM
124877a840cSConrad MeyerThe
125877a840cSConrad Meyer.Nm
126877a840cSConrad Meyerfunction
127877a840cSConrad Meyermay fail and set
128877a840cSConrad Meyer.Va errno
129877a840cSConrad Meyerfor any of the errors
130877a840cSConrad Meyerspecified for the
131877a840cSConrad Meyer.Xr malloc 3
132877a840cSConrad Meyerroutine.
133877a840cSConrad Meyer.El
134877a840cSConrad Meyer.Sh SEE ALSO
135877a840cSConrad Meyer.Xr fcntl 2 ,
136877a840cSConrad Meyer.Xr open 2 ,
137877a840cSConrad Meyer.Xr fclose 3 ,
138877a840cSConrad Meyer.Xr fopen 3 ,
139877a840cSConrad Meyer.Xr fseek 3 ,
140877a840cSConrad Meyer.Xr funopen 3
141877a840cSConrad Meyer.Sh HISTORY
142877a840cSConrad MeyerThe
143877a840cSConrad Meyer.Fn funopen
144877a840cSConrad Meyerfunctions first appeared in
145877a840cSConrad Meyer.Bx 4.4 .
146877a840cSConrad MeyerThe
147877a840cSConrad Meyer.Nm
148877a840cSConrad Meyerfunction first appeared in
149877a840cSConrad Meyer.Fx 11 .
150877a840cSConrad Meyer.Sh BUGS
151877a840cSConrad MeyerThe
152877a840cSConrad Meyer.Nm
153877a840cSConrad Meyerfunction is a nonstandard glibc extension and may not be portable to systems
154877a840cSConrad Meyerother than
155877a840cSConrad Meyer.Fx
156877a840cSConrad Meyerand Linux.
157