summaryrefslogtreecommitdiffstats
path: root/libopkg
diff options
context:
space:
mode:
authorgraham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2009-11-26 00:41:19 (EST)
committer graham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2009-11-26 00:41:19 (EST)
commit05c52125311ac8d73e5549b315e4f665eebfaf29 (patch)
treeace022f6465b6e0855bb3dfba954a96db578cdce /libopkg
parent3bca14e786c452664f5fec44cb47bc2e8aa8eb51 (diff)
Fix problem introduced in r382. Pointed out by jlc, thanks!
git-svn-id: http://opkg.googlecode.com/svn/trunk@386 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
Diffstat (limited to 'libopkg')
-rw-r--r--libopkg/file_util.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/libopkg/file_util.c b/libopkg/file_util.c
index 64e2bd3..e625984 100644
--- a/libopkg/file_util.c
+++ b/libopkg/file_util.c
@@ -66,11 +66,17 @@ file_read_line_alloc(FILE *fp)
int buf_len;
char *line = NULL;
int line_size = 0;
+ int got_nl = 0;
buf[0] = '\0';
while (fgets(buf, BUFSIZ, fp)) {
buf_len = strlen(buf);
+ if (buf[buf_len - 1] == '\n') {
+ buf_len--;
+ buf[buf_len] = '\0';
+ got_nl = 1;
+ }
if (line) {
line_size += buf_len;
line = xrealloc(line, line_size+1);
@@ -79,10 +85,8 @@ file_read_line_alloc(FILE *fp)
line_size = buf_len + 1;
line = xstrdup(buf);
}
- if (buf[buf_len - 1] == '\n') {
- buf[buf_len -1] = '\0';
+ if (got_nl)
break;
- }
}
return line;