summaryrefslogtreecommitdiff
path: root/libbb/get_line_from_file.c
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2006-06-10 11:04:43 +0000
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2006-06-10 11:04:43 +0000
commit2d1a6e7c1fc5f5772aa9986893f3d6db28fd99c2 (patch)
tree42d77ce40a0d8615ef307e22b38d3ee918a4e8a1 /libbb/get_line_from_file.c
parent6ba8bbe88a3bcb48df882793faea6713ad3bbc4e (diff)
downloadbusybox-w32-2d1a6e7c1fc5f5772aa9986893f3d6db28fd99c2.tar.gz
busybox-w32-2d1a6e7c1fc5f5772aa9986893f3d6db28fd99c2.tar.bz2
busybox-w32-2d1a6e7c1fc5f5772aa9986893f3d6db28fd99c2.zip
- fix bug #887, in bb_get_chomped_line_from_file(), the last char was removed
unconditionally, even if it was not a newline. This was apparently broken by r14254 - whitespace while at it.
Diffstat (limited to 'libbb/get_line_from_file.c')
-rw-r--r--libbb/get_line_from_file.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/libbb/get_line_from_file.c b/libbb/get_line_from_file.c
index 44cf44869..68837b20d 100644
--- a/libbb/get_line_from_file.c
+++ b/libbb/get_line_from_file.c
@@ -18,7 +18,7 @@
18 * stored and free'ed by the caller. If end is null '\n' isn't considered 18 * stored and free'ed by the caller. If end is null '\n' isn't considered
19 * and of line. If end isn't null, length of the chunk read is stored in it. */ 19 * and of line. If end isn't null, length of the chunk read is stored in it. */
20 20
21char *bb_get_chunk_from_file(FILE *file, int *end) 21char *bb_get_chunk_from_file(FILE * file, int *end)
22{ 22{
23 int ch; 23 int ch;
24 int idx = 0; 24 int idx = 0;
@@ -30,10 +30,12 @@ char *bb_get_chunk_from_file(FILE *file, int *end)
30 if (idx > linebufsz - 2) { 30 if (idx > linebufsz - 2) {
31 linebuf = xrealloc(linebuf, linebufsz += 80); 31 linebuf = xrealloc(linebuf, linebufsz += 80);
32 } 32 }
33 linebuf[idx++] = (char)ch; 33 linebuf[idx++] = (char) ch;
34 if (!ch || (end && ch == '\n')) break; 34 if (!ch || (end && ch == '\n'))
35 break;
35 } 36 }
36 if (end) *end = idx; 37 if (end)
38 *end = idx;
37 if (linebuf) { 39 if (linebuf) {
38 if (ferror(file)) { 40 if (ferror(file)) {
39 free(linebuf); 41 free(linebuf);
@@ -45,18 +47,21 @@ char *bb_get_chunk_from_file(FILE *file, int *end)
45} 47}
46 48
47/* Get line, including trailing /n if any */ 49/* Get line, including trailing /n if any */
48char *bb_get_line_from_file(FILE *file) 50char *bb_get_line_from_file(FILE * file)
49{ 51{
50 int i; 52 int i;
53
51 return bb_get_chunk_from_file(file, &i); 54 return bb_get_chunk_from_file(file, &i);
52} 55}
53 56
54/* Get line. Remove trailing /n */ 57/* Get line. Remove trailing /n */
55char *bb_get_chomped_line_from_file(FILE *file) 58char *bb_get_chomped_line_from_file(FILE * file)
56{ 59{
57 int i; 60 int i;
58 char *c=bb_get_chunk_from_file(file, &i); 61 char *c = bb_get_chunk_from_file(file, &i);
59 if(i) c[--i]=0; 62
60 63 if (i && c[--i] == '\n')
64 c[i] = 0;
65
61 return c; 66 return c;
62} 67}