linebuffer.h 2.06 KB
Newer Older
Jim Meyering's avatar
Jim Meyering committed
1
/* linebuffer.h -- declarations for reading arbitrarily long lines
2

3 4
   Copyright (C) 1986, 1991, 1998-1999, 2002-2003, 2007, 2009-2010 Free
   Software Foundation, Inc.
Jim Meyering's avatar
Jim Meyering committed
5

6
   This program is free software: you can redistribute it and/or modify
Jim Meyering's avatar
Jim Meyering committed
7
   it under the terms of the GNU General Public License as published by
8 9
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.
Jim Meyering's avatar
Jim Meyering committed
10 11 12 13 14 15 16

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
17
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18 19 20 21

#if !defined LINEBUFFER_H
# define LINEBUFFER_H

22 23
# include <stdio.h>

Jim Meyering's avatar
Jim Meyering committed
24 25 26 27
/* A `struct linebuffer' holds a line of text. */

struct linebuffer
{
28 29
  size_t size;                  /* Allocated. */
  size_t length;                /* Used. */
Jim Meyering's avatar
Jim Meyering committed
30 31 32 33
  char *buffer;
};

/* Initialize linebuffer LINEBUFFER for use. */
34
void initbuffer (struct linebuffer *linebuffer);
Jim Meyering's avatar
Jim Meyering committed
35

36 37 38
/* Read an arbitrarily long line of text from STREAM into LINEBUFFER.
   Consider lines to be terminated by DELIMITER.
   Keep the delimiter; append DELIMITER if we reach EOF and it wasn't
Bruno Haible's avatar
Bruno Haible committed
39 40
   the last character in the file.  Do not NUL-terminate.
   Return LINEBUFFER, except at end of file return NULL.  */
41
struct linebuffer *readlinebuffer_delim (struct linebuffer *linebuffer,
42
                                         FILE *stream, char delimiter);
43

Jim Meyering's avatar
Jim Meyering committed
44
/* Read an arbitrarily long line of text from STREAM into LINEBUFFER.
45
   Keep the newline; append a newline if it's the last line of a file
Bruno Haible's avatar
Bruno Haible committed
46 47
   that ends in a non-newline character.  Do not NUL-terminate.
   Return LINEBUFFER, except at end of file return NULL.  */
48
struct linebuffer *readlinebuffer (struct linebuffer *linebuffer, FILE *stream);
Jim Meyering's avatar
Jim Meyering committed
49 50

/* Free linebuffer LINEBUFFER and its data, all allocated with malloc. */
51
void freebuffer (struct linebuffer *);
52 53

#endif /* LINEBUFFER_H */