MCPcopy Create free account
hub / github.com/coreutils/coreutils / load_buffer

Function load_buffer

src/csplit.c:453–494  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

451 (in which case end-of-file must have been encountered). */
452
453static bool
454load_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. */

Callers 3

get_first_line_in_bufferFunction · 0.85
remove_lineFunction · 0.85
find_lineFunction · 0.85

Calls 6

get_new_bufferFunction · 0.85
record_line_startsFunction · 0.85
save_bufferFunction · 0.85
free_bufferFunction · 0.85
xalloc_dieFunction · 0.85
read_inputFunction · 0.70

Tested by

no test coverage detected