| 451 | (in which case end-of-file must have been encountered). */ |
| 452 | |
| 453 | static bool |
| 454 | load_buffer (void) |
| 455 | { |
| 456 | if (have_read_eof) |
| 457 | return false; |
| 458 | |
| 459 | /* We must make the buffer at least as large as the amount of data |
| 460 | in the partial line left over from the last call, |
| 461 | plus room for a sentinel '\n'. */ |
| 462 | idx_t bytes_wanted = MAX (START_SIZE, hold_count + 1); |
| 463 | |
| 464 | while (true) |
| 465 | { |
| 466 | struct buffer_record *b = get_new_buffer (bytes_wanted); |
| 467 | idx_t bytes_alloc = b->bytes_alloc; |
| 468 | idx_t bytes_avail = bytes_alloc; |
| 469 | char *p = b->buffer; |
| 470 | |
| 471 | /* First check the 'holding' area for a partial line. */ |
| 472 | if (hold_count) |
| 473 | { |
| 474 | p = mempcpy (p, hold_area, hold_count); |
| 475 | b->bytes_used += hold_count; |
| 476 | bytes_avail -= hold_count; |
| 477 | hold_count = 0; |
| 478 | } |
| 479 | |
| 480 | b->bytes_used += read_input (p, bytes_avail - 1); |
| 481 | |
| 482 | if (record_line_starts (b) != 0) |
| 483 | { |
| 484 | save_buffer (b); |
| 485 | return true; |
| 486 | } |
| 487 | |
| 488 | free_buffer (b); |
| 489 | if (have_read_eof) |
| 490 | return false; |
| 491 | if (ckd_add (&bytes_wanted, bytes_alloc, bytes_alloc >> 1)) |
| 492 | xalloc_die (); |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | /* Return the line number of the first line that has not yet been retrieved. |
| 497 | Return 0 if no lines available. */ |
no test coverage detected