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

Function record_line_starts

src/csplit.c:335–379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

333 the next buffer is filled. */
334
335static idx_t
336record_line_starts (struct buffer_record *b)
337{
338 char *line_start; /* Start of current line. */
339 idx_t lines; /* Number of lines found. */
340 idx_t line_length; /* Length of each line found. */
341
342 if (b->bytes_used == 0)
343 return 0;
344
345 lines = 0;
346 line_start = b->buffer;
347 char *buffer_end = line_start + b->bytes_used;
348 *buffer_end = '\n';
349
350 while (true)
351 {
352 char *line_end = rawmemchr (line_start, '\n');
353 if (line_end == buffer_end)
354 break;
355 line_length = line_end - line_start + 1;
356 keep_new_line (b, line_start, line_length);
357 line_start = line_end + 1;
358 lines++;
359 }
360
361 /* Check for an incomplete last line. */
362 idx_t bytes_left = buffer_end - line_start;
363 if (bytes_left)
364 {
365 if (have_read_eof)
366 {
367 keep_new_line (b, line_start, bytes_left);
368 lines++;
369 }
370 else
371 save_to_hold_area (ximemdup (line_start, bytes_left), bytes_left);
372 }
373
374 b->num_lines = lines;
375 b->first_available = b->start_line = last_line_number + 1;
376 last_line_number += lines;
377
378 return lines;
379}
380
381/* Work around <https://gcc.gnu.org/PR109614>. */
382#if 13 <= __GNUC__

Callers 1

load_bufferFunction · 0.85

Calls 2

keep_new_lineFunction · 0.85
save_to_hold_areaFunction · 0.85

Tested by

no test coverage detected