aboutsummaryrefslogtreecommitdiff
path: root/libbb/get_line_from_file.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/get_line_from_file.c')
-rw-r--r--libbb/get_line_from_file.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/libbb/get_line_from_file.c b/libbb/get_line_from_file.c
index 2c9608e9e..1eb4af13c 100644
--- a/libbb/get_line_from_file.c
+++ b/libbb/get_line_from_file.c
@@ -17,7 +17,7 @@
17 * end of line. If end isn't NULL, length of the chunk read is stored in it. 17 * end of line. If end isn't NULL, length of the chunk read is stored in it.
18 * Return NULL if EOF/error */ 18 * Return NULL if EOF/error */
19 19
20char *bb_get_chunk_from_file(FILE * file, int *end) 20char *bb_get_chunk_from_file(FILE *file, int *end)
21{ 21{
22 int ch; 22 int ch;
23 int idx = 0; 23 int idx = 0;
@@ -27,7 +27,8 @@ char *bb_get_chunk_from_file(FILE * file, int *end)
27 while ((ch = getc(file)) != EOF) { 27 while ((ch = getc(file)) != EOF) {
28 /* grow the line buffer as necessary */ 28 /* grow the line buffer as necessary */
29 if (idx >= linebufsz) { 29 if (idx >= linebufsz) {
30 linebuf = xrealloc(linebuf, linebufsz += 80); 30 linebufsz += 80;
31 linebuf = xrealloc(linebuf, linebufsz);
31 } 32 }
32 linebuf[idx++] = (char) ch; 33 linebuf[idx++] = (char) ch;
33 if (!ch || (end && ch == '\n')) 34 if (!ch || (end && ch == '\n'))
@@ -49,7 +50,7 @@ char *bb_get_chunk_from_file(FILE * file, int *end)
49} 50}
50 51
51/* Get line, including trailing \n if any */ 52/* Get line, including trailing \n if any */
52char *xmalloc_fgets(FILE * file) 53char *xmalloc_fgets(FILE *file)
53{ 54{
54 int i; 55 int i;
55 56
@@ -57,7 +58,7 @@ char *xmalloc_fgets(FILE * file)
57} 58}
58 59
59/* Get line. Remove trailing \n */ 60/* Get line. Remove trailing \n */
60char *xmalloc_getline(FILE * file) 61char *xmalloc_getline(FILE *file)
61{ 62{
62 int i; 63 int i;
63 char *c = bb_get_chunk_from_file(file, &i); 64 char *c = bb_get_chunk_from_file(file, &i);