diff options
author | aldot <aldot@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-06-10 11:04:43 +0000 |
---|---|---|
committer | aldot <aldot@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-06-10 11:04:43 +0000 |
commit | 7bace079f7d28e5823557cdcabd1649c71c7f71a (patch) | |
tree | 42d77ce40a0d8615ef307e22b38d3ee918a4e8a1 /libbb/get_line_from_file.c | |
parent | 31670fef486c042ebe4eb110b59c1963eb94411d (diff) | |
download | busybox-w32-7bace079f7d28e5823557cdcabd1649c71c7f71a.tar.gz busybox-w32-7bace079f7d28e5823557cdcabd1649c71c7f71a.tar.bz2 busybox-w32-7bace079f7d28e5823557cdcabd1649c71c7f71a.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.
git-svn-id: svn://busybox.net/trunk/busybox@15348 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb/get_line_from_file.c')
-rw-r--r-- | libbb/get_line_from_file.c | 23 |
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 | ||
21 | char *bb_get_chunk_from_file(FILE *file, int *end) | 21 | char *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 */ |
48 | char *bb_get_line_from_file(FILE *file) | 50 | char *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 */ |
55 | char *bb_get_chomped_line_from_file(FILE *file) | 58 | char *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 | } |