(act_getline): Bugfix. Do not return eof on an empty line. Reported by Damon Harper.
Showing
1 changed file
with
4 additions
and
3 deletions
... | @@ -48,17 +48,20 @@ act_getline (FILE *fp, char **sptr, size_t *size) | ... | @@ -48,17 +48,20 @@ act_getline (FILE *fp, char **sptr, size_t *size) |
48 | size_t used = 0; | 48 | size_t used = 0; |
49 | unsigned lines = 0; | 49 | unsigned lines = 0; |
50 | 50 | ||
51 | if (feof (fp)) | ||
52 | return 0; | ||
53 | |||
51 | while (cont && fgets (buf, sizeof buf, fp)) | 54 | while (cont && fgets (buf, sizeof buf, fp)) |
52 | { | 55 | { |
53 | int len = strlen (buf); | 56 | int len = strlen (buf); |
54 | if (buf[len-1] == '\n') | 57 | if (buf[len-1] == '\n') |
55 | { | 58 | { |
59 | lines++; | ||
56 | buf[--len] = 0; | 60 | buf[--len] = 0; |
57 | if (buf[len-1] == '\\') | 61 | if (buf[len-1] == '\\') |
58 | { | 62 | { |
59 | buf[--len] = 0; | 63 | buf[--len] = 0; |
60 | cont = 1; | 64 | cont = 1; |
61 | lines++; | ||
62 | } | 65 | } |
63 | else | 66 | else |
64 | cont = 0; | 67 | cont = 0; |
... | @@ -80,8 +83,6 @@ act_getline (FILE *fp, char **sptr, size_t *size) | ... | @@ -80,8 +83,6 @@ act_getline (FILE *fp, char **sptr, size_t *size) |
80 | if (*sptr) | 83 | if (*sptr) |
81 | (*sptr)[used] = 0; | 84 | (*sptr)[used] = 0; |
82 | 85 | ||
83 | if (used && !feof (fp)) | ||
84 | lines++; | ||
85 | return lines; | 86 | return lines; |
86 | } | 87 | } |
87 | 88 | ... | ... |
-
Please register or sign in to post a comment