* lib/linebuffer.c (readlinebuffer_delim): New function,
[gnulib.git] / lib / linebuffer.h
1 /* linebuffer.h -- declarations for reading arbitrarily long lines
2
3    Copyright (C) 1986, 1991, 1998, 1999, 2002, 2003, 2007 Free Software
4    Foundation, Inc.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2, or (at your option)
9    any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software Foundation,
18    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
19
20 #if !defined LINEBUFFER_H
21 # define LINEBUFFER_H
22
23 # include <stdio.h>
24
25 /* A `struct linebuffer' holds a line of text. */
26
27 struct linebuffer
28 {
29   size_t size;                  /* Allocated. */
30   size_t length;                /* Used. */
31   char *buffer;
32 };
33
34 /* Initialize linebuffer LINEBUFFER for use. */
35 void initbuffer (struct linebuffer *linebuffer);
36
37 /* Read an arbitrarily long line of text from STREAM into LINEBUFFER.
38    Consider lines to be terminated by DELIMITER.
39    Keep the delimiter; append DELIMITER if we reach EOF and it wasn't
40    the last character in the file.  Do not null terminate.
41    Return LINEBUFFER, except at end of file return 0.  */
42 struct linebuffer *readlinebuffer_delim (struct linebuffer *linebuffer,
43                                          FILE *stream, char delimiter);
44
45 /* Read an arbitrarily long line of text from STREAM into LINEBUFFER.
46    Keep the newline; append a newline if it's the last line of a file
47    that ends in a non-newline character.  Do not null terminate.
48    Return LINEBUFFER, except at end of file return 0.  */
49 struct linebuffer *readlinebuffer (struct linebuffer *linebuffer, FILE *stream);
50
51 /* Free linebuffer LINEBUFFER and its data, all allocated with malloc. */
52 void freebuffer (struct linebuffer *);
53
54 #endif /* LINEBUFFER_H */