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

Function dump

src/od.c:1514–1573  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1512 Otherwise, return true. */
1513
1514static bool
1515dump (void)
1516{
1517 char *block[2];
1518 bool idx = false;
1519 bool ok = true;
1520 idx_t n_bytes_read;
1521
1522 block[0] = xinmalloc (2, bytes_per_block);
1523 block[1] = block[0] + bytes_per_block;
1524
1525 intmax_t current_offset = n_bytes_to_skip;
1526
1527 do
1528 {
1529 intmax_t needed_bound
1530 = end_offset < 0 ? INTMAX_MAX : end_offset - current_offset;
1531 if (needed_bound <= 0)
1532 {
1533 n_bytes_read = 0;
1534 break;
1535 }
1536 idx_t n_needed = MIN (bytes_per_block, needed_bound);
1537 ok &= read_block (n_needed, block[idx], &n_bytes_read);
1538 if (n_bytes_read < bytes_per_block)
1539 break;
1540 affirm (n_bytes_read == bytes_per_block);
1541 write_block (current_offset, n_bytes_read,
1542 block[!idx], block[idx]);
1543 if (ferror (stdout))
1544 ok = false;
1545 current_offset += n_bytes_read;
1546 idx = !idx;
1547 }
1548 while (ok);
1549
1550 if (n_bytes_read > 0)
1551 {
1552 int l_c_m = get_lcm ();
1553
1554 /* Ensure zero-byte padding up to the smallest multiple of l_c_m that
1555 is at least as large as n_bytes_read. */
1556 idx_t bytes_to_write = (n_bytes_read + l_c_m - 1
1557 - (n_bytes_read + l_c_m - 1) % l_c_m);
1558
1559 memset (block[idx] + n_bytes_read, 0, bytes_to_write - n_bytes_read);
1560 write_block (current_offset, n_bytes_read, block[!idx], block[idx]);
1561 current_offset += n_bytes_read;
1562 }
1563
1564 if (ok || current_offset)
1565 format_address (current_offset, '\n');
1566
1567 if (0 <= end_offset && end_offset <= current_offset)
1568 ok &= check_and_close (0);
1569
1570 free (block[0]);
1571

Callers 1

mainFunction · 0.85

Calls 4

read_blockFunction · 0.85
write_blockFunction · 0.85
get_lcmFunction · 0.85
check_and_closeFunction · 0.85

Tested by

no test coverage detected