Bugfix.
* mailbox/stream.c (mu_stream_readline): Fix byte counting.
Showing
1 changed file
with
5 additions
and
8 deletions
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2000, 2001, 2004, 2005, | 2 | Copyright (C) 1999, 2000, 2001, 2004, 2005, |
3 | 2006, 2007 Free Software Foundation, Inc. | 3 | 2006, 2007, 2009 Free Software Foundation, Inc. |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public | 6 | modify it under the terms of the GNU Lesser General Public |
... | @@ -298,7 +298,7 @@ mu_stream_readline (mu_stream_t is, char *buf, size_t count, | ... | @@ -298,7 +298,7 @@ mu_stream_readline (mu_stream_t is, char *buf, size_t count, |
298 | size_t n, nr = 0; | 298 | size_t n, nr = 0; |
299 | char c; | 299 | char c; |
300 | /* Grossly inefficient hopefully they override this */ | 300 | /* Grossly inefficient hopefully they override this */ |
301 | for (n = 1; n < count; n++) | 301 | for (n = 0; n < count; ) |
302 | { | 302 | { |
303 | status = is->_read (is, &c, 1, offset, &nr); | 303 | status = is->_read (is, &c, 1, offset, &nr); |
304 | if (status != 0) /* Error. */ | 304 | if (status != 0) /* Error. */ |
... | @@ -307,19 +307,16 @@ mu_stream_readline (mu_stream_t is, char *buf, size_t count, | ... | @@ -307,19 +307,16 @@ mu_stream_readline (mu_stream_t is, char *buf, size_t count, |
307 | { | 307 | { |
308 | *buf++ = c; | 308 | *buf++ = c; |
309 | offset++; | 309 | offset++; |
310 | n++; | ||
310 | if (c == '\n') /* Newline is stored like fgets(). */ | 311 | if (c == '\n') /* Newline is stored like fgets(). */ |
311 | break; | 312 | break; |
312 | } | 313 | } |
313 | else if (nr == 0) | 314 | else if (nr == 0) |
314 | { | 315 | break; /* EOF */ |
315 | if (n == 1) /* EOF, no data read. */ | ||
316 | n = 0; | ||
317 | break; /* EOF, some data was read. */ | ||
318 | } | ||
319 | } | 316 | } |
320 | *buf = '\0'; | 317 | *buf = '\0'; |
321 | if (pnread) | 318 | if (pnread) |
322 | *pnread = (n == count) ? n - 1: n; | 319 | *pnread = n; |
323 | } | 320 | } |
324 | else /* Buffered. */ | 321 | else /* Buffered. */ |
325 | { | 322 | { | ... | ... |
-
Please register or sign in to post a comment