Make all bucket and overflow addresses unsigned
[unix-history] / usr / src / lib / libc / stdio / funopen.3
CommitLineData
75964a78
KB
1.\" Copyright (c) 1990 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Chris Torek.
6.\"
7.\" %sccs.include.redist.man%
8.\"
9.\" @(#)funopen.3 5.1 (Berkeley) %G%
10.\"
11.TH FUNOPEN 3 ""
12.UC 7
13.SH NAME
14funopen, fropen, fwopen \- open a stream
15.SH SYNOPSIS
16.nf
17.ft B
18#include <stdio.h>
19
20FILE *
21funopen(void *cookie, int (*readfn)(void *, char *, int),
22.RS
23.\" old man macros need the reset of bold mode
24.ft B
25int (*writefn)(void *, char *, int),
26fpos_t (*seekfn)(void *, off_t, int), int (*closefn)(void *));
27.RE
28.\" old man macros need the reset of bold mode
29.ft B
30
31FILE *
32fropen(void *cookie, int (*readfn)(void *, char *, int));
33
34FILE *
35fwopen(void *cookie, int (*writefn)(void *, char *, int));
36.ft R
37.fi
38.SH DESCRIPTION
39.I Funopen
40associates a stream with up to four ``I/O functions''.
41Either
42.I readfn
43or
44.I writefn
45must be specified;
46the others can be given as an appropriately-typed NULL pointer.
47These I/O functions will be used to read, write, seek and
48close the new stream.
49.PP
50In general, omitting a function means that any attempt to perform the
51associated operation on the resulting stream will fail.
52If the close function is omitted, closing the stream will flush
53any buffered output and then succeed.
54.PP
55The calling conventions of
56.IR readfn ,
57.IR writefn ,
58.I seekfn
59and
60.I closefn
61must match those, respectively, of
62.IR read (2),
63.IR write (2),
64.IR seek (2),
65and
66.IR close (2)
67with the single exception that they are passed the
68.I cookie
69argument specified to
70.I funopen
71in place of the traditional file descriptor argument.
72.PP
73Read and write I/O functions are allowed to change the underlying buffer
74on fully buffered or line buffered streams by calling
75.IR setvbuf .
76They are also not required to completely fill or empty the buffer.
77They are not, however, allowed to change streams from unbuffered to buffered
78or to change the state of the line buffering flag.
79They must also be prepared to have read or write calls occur on buffers other
80than the one most recently specified.
81.PP
82All user I/O functions can report an error by returning \-1.
83Additionally, all of the functions should set the external variable
84.I errno
85appropriately if an error occurs.
86.PP
87An error on
88.I closefn
89does not keep the stream open.
90.PP
91As a convenience, the include file ``<stdio.h>'' defines the macros
92.I fropen
93and
94.I fwopen
95as calls to
96.I funopen
97with only a read or write function specified.
98.SH "SEE ALSO"
99fcntl(2), open(2), fclose(3), fopen(3), fseek(3), setbuf(3)
100.SH "RETURN VALUES"
101Upon successful completion,
102.I funopen
103returns a FILE pointer.
104Otherwise, NULL is returned and the global variable
105.I errno
106is set to indicate the error.
107.SH ERRORS
108.TP 15
109[EINVAL]
110.I Funopen
111was called without either a read or write function.
112.I Funopen
113may also fail and set errno for any of the errors
114specified for the routine
115.IR malloc (3).
116.SH BUGS
117.I Funopen
118may not be portable to systems other than BSD.