aboutsummaryrefslogtreecommitdiff
path: root/man/man3/bio.html
blob: 7825992257eef426e8546e84f780d3c92bb24b72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<head>
<title>bio(3) - Plan 9 from User Space</title>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
</head>
<body bgcolor=#ffffff>
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=10><td>
<tr><td width=20><td>
<tr><td width=20><td><b>BIO(3)</b><td align=right><b>BIO(3)</b>
<tr><td width=20><td colspan=2>
    <br>
<p><font size=+1><b>NAME     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    Bopen, Bfdopen, Binit, Binits, Brdline, Brdstr, Bgetc, Bgetrune,
    Bgetd, Bungetc, Bungetrune, Bread, Bseek, Boffset, Bfildes, Blinelen,
    Bputc, Bputrune, Bprint, Bvprint, Bwrite, Bflush, Bterm, Bbuffered
    &ndash; buffered input/output<br>
    
</table>
<p><font size=+1><b>SYNOPSIS     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <tt><font size=+1>#include &lt;u.h&gt;<br>
    #include &lt;libc.h&gt;<br>
    #include &lt;bio.h&gt; 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>Biobuf* Bopen(char *file, int mode) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>Biobuf* Bfdopen(int fd, int mode) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Binit(Biobuf *bp, int fd, int mode) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Binits(Biobufhdr *bp, int fd, int mode, uchar *buf, int size)
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bterm(Biobufhdr *bp) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bprint(Biobufhdr *bp, char *format, ...) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bvprint(Biobufhdr *bp, char *format, va_list arglist); 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>void* &nbsp;&nbsp;&nbsp;&nbsp;Brdline(Biobufhdr *bp, int delim) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>char* &nbsp;&nbsp;&nbsp;&nbsp;Brdstr(Biobufhdr *bp, int delim, int nulldelim) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Blinelen(Biobufhdr *bp) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>vlong &nbsp;&nbsp;&nbsp;&nbsp;Boffset(Biobufhdr *bp) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bfildes(Biobufhdr *bp) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bgetc(Biobufhdr *bp) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>long &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bgetrune(Biobufhdr *bp) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bgetd(Biobufhdr *bp, double *d) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bungetc(Biobufhdr *bp) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bungetrune(Biobufhdr *bp) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>vlong &nbsp;&nbsp;&nbsp;&nbsp;Bseek(Biobufhdr *bp, vlong n, int type) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bputc(Biobufhdr *bp, int c) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bputrune(Biobufhdr *bp, long c) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>long &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bread(Biobufhdr *bp, void *addr, long nbytes) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>long &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bwrite(Biobufhdr *bp, void *addr, long nbytes) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bflush(Biobufhdr *bp) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bbuffered(Biobufhdr *bp) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    
</table>
<p><font size=+1><b>DESCRIPTION     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    These routines implement fast buffered I/O. I/O on different file
    descriptors is independent. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Bopen</i> opens <i>file</i> for mode <tt><font size=+1>OREAD</font></tt> or creates for mode <tt><font size=+1>OWRITE</font></tt>. It
    calls <a href="../man3/malloc.html"><i>malloc</i>(3)</a> to allocate a buffer. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Bfdopen</i> allocates a buffer for the already-open file descriptor
    <i>fd</i> for mode <tt><font size=+1>OREAD</font></tt> or <tt><font size=+1>OWRITE</font></tt>. It calls <a href="../man3/malloc.html"><i>malloc</i>(3)</a> to allocate a
    buffer. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Binit</i> initializes a standard size buffer, type <i>Biobuf</i>, with the
    open file descriptor passed in by the user. <i>Binits</i> initializes
    a non-standard size buffer, type <i>Biobufhdr</i>, with the open file
    descriptor, buffer area, and buffer size passed in by the user.
    <i>Biobuf</i> and <i>Biobufhdr</i> are related by the declaration:
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        <tt><font size=+1>typedef struct Biobuf Biobuf;<br>
        struct Biobuf<br>
        {<br>
        
        <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

            Biobufhdr;<br>
            uchar b[Bungetsize+Bsize];<br>
            
        </table>
        };<br>
        
        <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
        </font></tt>
        
    </table>
    Arguments of types pointer to Biobuf and pointer to Biobufhdr
    can be used interchangeably in the following routines. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Bopen</i>, <i>Binit</i>, or <i>Binits</i> should be called before any of the other
    routines on that buffer. <i>Bfildes</i> returns the integer file descriptor
    of the associated open file. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Bterm</i> flushes the buffer for <i>bp</i>. If the buffer was allocated by
    <i>Bopen</i>, the buffer is <i>freed</i> and the file is closed. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Brdline</i> reads a string from the file associated with <i>bp</i> up to
    and including the first <i>delim</i> character. The delimiter character
    at the end of the line is not altered. <i>Brdline</i> returns a pointer
    to the start of the line or <tt><font size=+1>0</font></tt> on end-of-file or read error. <i>Blinelen</i>
    returns the length (including the delimiter) of the most recent
    string
    returned by <i>Brdline</i>. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Brdstr</i> returns a <a href="../man3/malloc.html"><i>malloc</i>(3)</a>-allocated buffer containing the next
    line of input delimited by <i>delim</i>, terminated by a NUL (0) byte.
    Unlike <i>Brdline</i>, which returns when its buffer is full even if
    no delimiter has been found, <i>Brdstr</i> will return an arbitrarily
    long line in a single call. If <i>nulldelim</i> is set, the terminal
    delimiter will be
    overwritten with a NUL. After a successful call to <i>Brdstr</i>, the
    return value of <i>Blinelen</i> will be the length of the returned buffer,
    excluding the NUL. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Bgetc</i> returns the next character from <i>bp</i>, or a negative value
    at end of file. <i>Bungetc</i> may be called immediately after <i>Bgetc</i>
    to allow the same character to be reread. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Bgetrune</i> calls <i>Bgetc</i> to read the bytes of the next UTF sequence
    in the input stream and returns the value of the rune represented
    by the sequence. It returns a negative value at end of file. <i>Bungetrune</i>
    may be called immediately after <i>Bgetrune</i> to allow the same UTF
    sequence to be reread as either bytes or a rune.
    <i>Bungetc</i> and <i>Bungetrune</i> may back up a maximum of five bytes. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Bgetd</i> uses <i>charstod</i> (see <a href="../man3/atof.html"><i>atof</i>(3)</a>) and <i>Bgetc</i> to read the formatted
    floating-point number in the input stream, skipping initial blanks
    and tabs. The value is stored in <tt><font size=+1>*d. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <i>Bread</i> reads <i>nbytes</i> of data from <i>bp</i> into memory starting at <i>addr</i>.
    The number of bytes read is returned on success and a negative
    value is returned if a read error occurred. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Bseek</i> applies <a href="../man3/seek.html"><i>seek</i>(3)</a> to <i>bp</i>. It returns the new file offset. <i>Boffset</i>
    returns the file offset of the next character to be processed.
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Bputc</i> outputs the low order 8 bits of <i>c</i> on <i>bp</i>. If this causes
    a <i>write</i> to occur and there is an error, a negative value is returned.
    Otherwise, a zero is returned. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Bputrune</i> calls <i>Bputc</i> to output the low order 16 bits of <i>c</i> as a
    rune in UTF format on the output stream. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Bprint</i> is a buffered interface to <a href="../man3/print.html"><i>print</i>(3)</a>. If this causes a <i>write</i>
    to occur and there is an error, a negative value (<tt><font size=+1>Beof</font></tt>) is returned.
    Otherwise, the number of bytes output is returned. <i>Bvprint</i> does
    the same except it takes as argument a <tt><font size=+1>va_list</font></tt> parameter, so it
    can be called within a variadic function. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Bwrite</i> outputs <i>nbytes</i> of data starting at <i>addr</i> to <i>bp</i>. If this
    causes a <i>write</i> to occur and there is an error, a negative value
    is returned. Otherwise, the number of bytes written is returned.
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Bflush</i> causes any buffered output associated with <i>bp</i> to be written.
    The return is as for <i>Bputc</i>. <i>Bflush</i> is called on exit for every
    buffer still open for writing. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Bbuffered</i> returns the number of bytes in the buffer. When reading,
    this is the number of bytes still available from the last read
    on the file; when writing, it is the number of bytes ready to
    be written.<br>
    
</table>
<p><font size=+1><b>SOURCE     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <tt><font size=+1>/usr/local/plan9/src/libbio<br>
    </font></tt>
</table>
<p><font size=+1><b>SEE ALSO    </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <a href="../man3/open.html"><i>open</i>(3)</a>, <a href="../man3/print.html"><i>print</i>(3)</a>, <a href="../man3/exits.html"><i>exits</i>(3)</a>, <a href="../man7/utf.html"><i>utf</i>(7)</a>,<br>
    
</table>
<p><font size=+1><b>DIAGNOSTICS     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <i>Bio</i> routines that return integers yield <tt><font size=+1>Beof</font></tt> if <i>bp</i> is not the
    descriptor of an open file. <i>Bopen</i> returns zero if the file cannot
    be opened in the given mode. All routines set <i>errstr</i> on error.<br>
    
</table>
<p><font size=+1><b>BUGS     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <i>Brdline</i> returns an error on strings longer than the buffer associated
    with the file and also if the end-of-file is encountered before
    a delimiter. <i>Blinelen</i> will tell how many characters are available
    in these cases. In the case of a true end-of-file, <i>Blinelen</i> will
    return zero. At the cost of allocating a buffer, <i>Brdstr</i> sidesteps
    these issues. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    The data returned by <i>Brdline</i> may be overwritten by calls to any
    other <i>bio</i> routine on the same <i>bp.</i><br>
    
</table>

<td width=20>
<tr height=20><td>
</table>
<!-- TRAILER -->
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=15><td width=10><td><td width=10>
<tr><td><td>
<center>
<a href="../../"><img src="../../dist/spaceglenda100.png" alt="Space Glenda" border=1></a>
</center>
</table>
<!-- TRAILER -->
</body></html>