3 Bopen, Bfdopen, Binit, Binits, Brdline, Brdstr, Bgetc, Bgetrune, Bgetd, Bungetc, Bungetrune, Bread, Bseek, Boffset, Bfildes, Blinelen, Bputc, Bputrune, Bprint, Bvprint, Bwrite, Bflush, Bterm, Bbuffered, Blethal, Biofn \- buffered input/output
14 .ta \w' 'u +\w' 'u +\w' 'u +\w' 'u +\w' 'u
15 typedef struct Biobufhdr Biobufhdr;
17 void *aux; /* user data */
23 Biobuf* Bopen(char *file, int mode)
26 Biobuf* Bfdopen(int fd, int mode)
29 int Binit(Biobuf *bp, int fd, int mode)
32 int Binits(Biobufhdr *bp, int fd, int mode, uchar *buf, int size)
35 int Bterm(Biobufhdr *bp)
38 int Bprint(Biobufhdr *bp, char *format, ...)
41 int Bvprint(Biobufhdr *bp, char *format, va_list arglist);
44 void* Brdline(Biobufhdr *bp, int delim)
47 char* Brdstr(Biobufhdr *bp, int delim, int nulldelim)
50 int Blinelen(Biobufhdr *bp)
53 vlong Boffset(Biobufhdr *bp)
56 int Bfildes(Biobufhdr *bp)
59 int Bgetc(Biobufhdr *bp)
62 long Bgetrune(Biobufhdr *bp)
65 int Bgetd(Biobufhdr *bp, double *d)
68 int Bungetc(Biobufhdr *bp)
71 int Bungetrune(Biobufhdr *bp)
74 vlong Bseek(Biobufhdr *bp, vlong n, int type)
77 int Bputc(Biobufhdr *bp, int c)
80 int Bputrune(Biobufhdr *bp, long c)
83 long Bread(Biobufhdr *bp, void *addr, long nbytes)
86 long Bwrite(Biobufhdr *bp, void *addr, long nbytes)
89 int Bflush(Biobufhdr *bp)
92 int Bbuffered(Biobufhdr *bp)
95 void Blethal(Biobufhdr *bp, void (*errorf)(char *))
98 void Biofn(Biobufhdr *bp, int (*iof)(Biobufhdr *, void *, long))
101 These routines implement fast buffered I/O.
102 I/O on different file descriptors is independent.
113 to allocate a buffer.
116 allocates a buffer for the already-open file descriptor
124 to allocate a buffer.
127 initializes a standard size buffer, type
129 with the open file descriptor passed in
132 initializes a non-standard size buffer, type
134 with the open file descriptor,
135 buffer area, and buffer size passed in
140 are related by the declaration:
143 typedef struct Biobuf Biobuf;
147 uchar b[Bungetsize+Bsize];
152 of types pointer to Biobuf and pointer to Biobufhdr
153 can be used interchangeably in the following routines.
159 should be called before any of the
160 other routines on that buffer.
162 returns the integer file descriptor of the associated open file.
165 flushes the buffer for
170 If the buffer was allocated by
176 and the file is closed.
179 reads a string from the file associated with
181 up to and including the first
184 The delimiter character at the end of the line is
185 not altered, thus the returned string probably won't be NUL-terminated.
187 returns a pointer to the start of the line or
189 on end-of-file or read error.
191 returns the length (including the delimiter)
192 of the most recent string returned by
197 .IR malloc (2)-allocated
198 buffer containing the next line of input delimited by
200 terminated by a NUL (0) byte.
203 which returns when its buffer is full even if no delimiter has been found,
205 will return an arbitrarily long line in a single call.
208 is set, the terminal delimiter will be overwritten with a NUL.
209 After a successful call to
213 will be the length of the returned buffer, excluding the NUL.
216 returns the next character from
221 may be called immediately after
223 to allow the same character to be reread.
228 to read the bytes of the next
230 sequence in the input stream and returns the value of the rune
231 represented by the sequence.
232 It returns a negative value
235 may be called immediately after
239 sequence to be reread as either bytes or a rune.
243 may back up a maximum of five bytes.
252 to read the formatted
253 floating-point number in the input stream,
254 skipping initial blanks and tabs.
255 The value is stored in
263 into memory starting at
265 The number of bytes read is returned on success
266 and a negative value is returned if a read error occurred.
273 It returns the new file offset.
275 returns the file offset of the next character to be processed.
278 outputs the low order 8 bits of
284 to occur and there is an error,
285 a negative value is returned.
286 Otherwise, a zero is returned.
291 to output the low order
298 on the output stream.
301 is a buffered interface to
305 to occur and there is an error,
311 returns the number of bytes written.
313 does the same except it takes as argument a
315 parameter, so it can be called within a variadic function.
326 to occur and there is an error,
327 a negative value is returned.
328 Otherwise, the number of bytes written is returned.
331 causes any buffered output associated with
338 exit for every buffer still open
342 returns the number of bytes in the buffer.
343 When reading, this is the number of bytes still available from the last
344 read on the file; when writing, it is the number of bytes ready to be
350 to be called in case of an error happening on read/write.
353 will have the program terminated in case of error.
357 is called with a non-nil
359 function, then that function is called for I/O in lieu of
365 restores normal behaviour.
376 routines that return integers yield
380 is not the descriptor of an open file.
382 returns zero if the file cannot be opened in the given mode.
387 An error during read or write will call an error handler specified by
392 returns an error on strings longer than the buffer associated
394 and also if the end-of-file is encountered
397 will tell how many characters are available
399 In the case of a true end-of-file,
402 At the cost of allocating a buffer,
404 sidesteps these issues.
411 cannot be an arbitrary rune.
415 may be overwritten by calls to any other