| 1677 | initially. */ |
| 1678 | |
| 1679 | static void |
| 1680 | initbuf (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 |
no test coverage detected