comparison lib/linebuffer.c @ 1463:f8f00a1e2989

(readline): Return zero upon error as well as upon end of file. From James Youngman.
author Jim Meyering <jim@meyering.net>
date Mon, 03 Aug 1998 03:02:04 +0000
parents 3eda3e12f7ba
children b15c026c2dbd
comparison
equal deleted inserted replaced
1462:cbd00759e1a6 1463:f8f00a1e2989
1 /* linebuffer.c -- read arbitrarily long lines 1 /* linebuffer.c -- read arbitrarily long lines
2 Copyright (C) 1986, 1991 Free Software Foundation, Inc. 2 Copyright (C) 1986, 1991, 1998 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option) 6 the Free Software Foundation; either version 2, or (at your option)
7 any later version. 7 any later version.
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU General Public License for more details.
13 13
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software 15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ 16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17 17
18 /* Written by Richard Stallman. */ 18 /* Written by Richard Stallman. */
19 19
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23
20 #include <stdio.h> 24 #include <stdio.h>
21 #include "linebuffer.h" 25 #include "linebuffer.h"
22 26
23 char *xmalloc (); 27 char *xmalloc ();
24 char *xrealloc (); 28 char *xrealloc ();
35 linebuffer->buffer = (char *) xmalloc (linebuffer->size); 39 linebuffer->buffer = (char *) xmalloc (linebuffer->size);
36 } 40 }
37 41
38 /* Read an arbitrarily long line of text from STREAM into LINEBUFFER. 42 /* Read an arbitrarily long line of text from STREAM into LINEBUFFER.
39 Remove any newline. Does not null terminate. 43 Remove any newline. Does not null terminate.
40 Return LINEBUFFER, except at end of file return 0. */ 44 Return zero upon error or upon end of file.
45 Otherwise, return LINEBUFFER. */
41 46
42 struct linebuffer * 47 struct linebuffer *
43 readline (linebuffer, stream) 48 readline (linebuffer, stream)
44 struct linebuffer *linebuffer; 49 struct linebuffer *linebuffer;
45 FILE *stream; 50 FILE *stream;
47 int c; 52 int c;
48 char *buffer = linebuffer->buffer; 53 char *buffer = linebuffer->buffer;
49 char *p = linebuffer->buffer; 54 char *p = linebuffer->buffer;
50 char *end = buffer + linebuffer->size; /* Sentinel. */ 55 char *end = buffer + linebuffer->size; /* Sentinel. */
51 56
52 if (feof (stream)) 57 if (feof (stream) || ferror (stream))
53 { 58 {
54 linebuffer->length = 0; 59 linebuffer->length = 0;
55 return 0; 60 return 0;
56 } 61 }
57 62