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

Function initbuf

src/sort.c:1679–1701  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1677 initially. */
1678
1679static void
1680initbuf (struct buffer *buf, size_t line_bytes, size_t alloc)
1681{
1682 /* Ensure that the line array is properly aligned. If the desired
1683 size cannot be allocated, repeatedly halve it until allocation
1684 succeeds. The smaller allocation may hurt overall performance,
1685 but that's better than failing. */
1686 while (true)
1687 {
1688 alloc += sizeof (struct line) - alloc % sizeof (struct line);
1689 buf->buf = malloc (alloc);
1690 if (buf->buf)
1691 break;
1692 alloc /= 2;
1693 if (alloc <= line_bytes + 1)
1694 xalloc_die ();
1695 }
1696
1697 buf->line_bytes = line_bytes;
1698 buf->alloc = alloc;
1699 buf->used = buf->left = buf->nlines = 0;
1700 buf->eof = false;
1701}
1702
1703/* Return one past the limit of the line array. */
1704

Callers 3

checkFunction · 0.85
mergefpsFunction · 0.85
sortFunction · 0.85

Calls 1

xalloc_dieFunction · 0.85

Tested by

no test coverage detected