1 .\" $NetBSD: funopen.3,v 1.23 2015/09/06 01:36:21 dholland Exp $
3 .\" Copyright (c) 1990, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" This code is derived from software contributed to Berkeley by
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\" notice, this list of conditions and the following disclaimer in the
15 .\" documentation and/or other materials provided with the distribution.
16 .\" 3. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)funopen.3 8.1 (Berkeley) 6/9/93
50 .Fn funopen "void *cookie" "int (*readfn)(void *, char *, int)" "int (*writefn)(void *, const char *, int)" "off_t (*seekfn)(void *, off_t, int)" "int (*closefn)(void *)"
51 .Fn funopen2 "void *cookie" "ssize_t (*readfn)(void *, void *, size_t)" "ssize_t (*writefn)(void *, const void *, size_t)" "off_t (*seekfn)(void *, off_t, int)" "int (*flushfn)(void *)" "int (*closefn)(void *)"
53 .Fn fropen "void *cookie" "int (*readfn)(void *, char *, int)"
55 .Fn fropen2 "void *cookie" "ssize_t (*readfn)(void *, void *, size_t)"
57 .Fn fwopen "void *cookie" "int (*writefn)(void *, const char *, int)"
59 .Fn fwopen2 "void *cookie" "ssize_t (*writefn)(void *, const void *, size_t)"
64 associates a stream with up to four
65 .Dq Tn I/O No functions .
71 the others can be given as an appropriately-typed
76 functions will be used to read, write, seek and
81 function provides sightly different read and write signatures, which match
82 better the corresponding system calls, plus the ability to augment the
83 streams default flushing function.
84 If a flushing function is provided, then it is called after all data has
85 been written to the stream.
87 In general, omitting a function means that any attempt to perform the
88 associated operation on the resulting stream will fail.
89 If the close function is omitted, closing the stream will flush
90 any buffered output and then succeed.
92 The calling conventions of
98 must match those, respectively, of
104 except that they are passed the
106 argument specified to
108 in place of the traditional file descriptor argument.
112 functions are allowed to change the underlying buffer
113 on fully buffered or line buffered streams by calling
115 They are also not required to completely fill or empty the buffer.
116 They are not, however, allowed to change streams from unbuffered to buffered
117 or to change the state of the line buffering flag.
118 They must also be prepared to have read or write calls occur on buffers other
119 than the one most recently specified.
123 functions can report an error by returning \-1.
124 Additionally, all of the functions should set the external variable
126 appropriately if an error occurs.
130 does not keep the stream open.
132 As a convenience, the include file
140 with only a read or write function specified.
142 Upon successful completion,
149 is returned and the global variable
151 is set to indicate the error.
158 was called without either a read or write function.
162 may also fail and set
164 for any of the errors
165 specified for the routine
179 functions first appeared in
183 functions first appeared in
186 All three functions are specific to