path: root/vcs-svn/line_buffer.txt
diff options
authorDavid Barr <>2010-08-09 22:39:43 (GMT)
committerJunio C Hamano <>2010-08-15 02:35:37 (GMT)
commit3bbaec00a8ffc6ea7e71c3b707851fe663d93a45 (patch)
tree5af41401b9e6764754058d4305a0d212190828b9 /vcs-svn/line_buffer.txt
parent1d73b52f5ba4184de6acf474f14668001304a10c (diff)
Add stream helper library
This library provides thread-unsafe fgets()- and fread()-like functions where the caller does not have to supply a buffer. It maintains a couple of static buffers and provides an API to use them. [rr: allow input from files other than stdin] [jn: with tests, documentation, and error handling improvements] Signed-off-by: David Barr <> Signed-off-by: Ramkumar Ramachandra <> Signed-off-by: Jonathan Nieder <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'vcs-svn/line_buffer.txt')
1 files changed, 58 insertions, 0 deletions
diff --git a/vcs-svn/line_buffer.txt b/vcs-svn/line_buffer.txt
new file mode 100644
index 0000000..8906fb1
--- /dev/null
+++ b/vcs-svn/line_buffer.txt
@@ -0,0 +1,58 @@
+line_buffer API
+The line_buffer library provides a convenient interface for
+mostly-line-oriented input.
+Each line is not permitted to exceed 10000 bytes. The provided
+functions are not thread-safe or async-signal-safe, and like
+`fgets()`, they generally do not function correctly if interrupted
+by a signal without SA_RESTART set.
+Calling sequence
+The calling program:
+ - specifies a file to read with `buffer_init`
+ - processes input with `buffer_read_line`, `buffer_read_string`,
+ `buffer_skip_bytes`, and `buffer_copy_bytes`
+ - closes the file with `buffer_deinit`, perhaps to start over and
+ read another file.
+Before exiting, the caller can use `buffer_reset` to deallocate
+resources for the benefit of profiling tools.
+ Open the named file for input. If filename is NULL,
+ start reading from stdin. On failure, returns -1 (with
+ errno indicating the nature of the failure).
+ Stop reading from the current file (closing it unless
+ it was stdin). Returns nonzero if `fclose` fails or
+ the error indicator was set.
+ Read a line and strip off the trailing newline.
+ On failure or end of file, returns NULL.
+ Read `len` characters of input or up to the end of the
+ file, whichever comes first. Returns NULL on error.
+ Returns whatever characters were read (possibly "")
+ for end of file.
+ Read `len` bytes of input and dump them to the standard output
+ stream. Returns early for error or end of file.
+ Discards `len` bytes from the input stream (stopping early
+ if necessary because of an error or eof).
+ Deallocates non-static buffers.