Debian Codegraph @

lib/linebuffer.h

raw
1 /* linebuffer.h -- declarations for reading arbitrarily long lines
2
3 Copyright (C) 1986, 1991, 1998-1999, 2002-2003, 2007, 2009-2025 Free
4 Software 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 3 of the License, or
9 (at your option) 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, see <https://www.gnu.org/licenses/>. */
18
19 #if !defined LINEBUFFER_H
20 #define LINEBUFFER_H
21
22 #include "idx.h"
23 #include <stdio.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29
30 /* A 'struct linebuffer' holds a line of text. */
31
32 struct linebuffer
33 {
34 idx_t size; /* Allocated. */
35 idx_t length; /* Used. */
36 char *buffer;
37 };
38
39 /* Initialize linebuffer LINEBUFFER for use. */
40 void initbuffer (struct linebuffer *linebuffer);
41
42 /* Read an arbitrarily long line of text from STREAM into LINEBUFFER.
43 Consider lines to be terminated by DELIMITER.
44 Keep the delimiter; append DELIMITER if we reach EOF and it wasn't
45 the last character in the file. Do not NUL-terminate.
46 Return LINEBUFFER, except at end of file return NULL. */
47 struct linebuffer *readlinebuffer_delim (struct linebuffer *linebuffer,
48 FILE *stream, char delimiter);
49
50 /* Read an arbitrarily long line of text from STREAM into LINEBUFFER.
51 Keep the newline; append a newline if it's the last line of a file
52 that ends in a non-newline character. Do not NUL-terminate.
53 Return LINEBUFFER, except at end of file return NULL. */
54 struct linebuffer *readlinebuffer (struct linebuffer *linebuffer, FILE *stream);
55
56 /* Free linebuffer LINEBUFFER and its data, all allocated with malloc. */
57 void freebuffer (struct linebuffer *);
58
59
60 #ifdef __cplusplus
61 }
62 #endif
63
64 #endif /* LINEBUFFER_H */