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

Function dump_strings

src/od.c:1581–1675  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1579 traditional version of od. Return true if successful. */
1580
1581static bool
1582dump_strings (void)
1583{
1584 idx_t bufsize = MAX (100, string_min + 1);
1585 char *buf = ximalloc (bufsize);
1586 intmax_t address = n_bytes_to_skip;
1587 bool ok = true;
1588
1589 while (true)
1590 {
1591 idx_t i = 0;
1592 int c = 1; /* Init to 1 so can distinguish if NUL read. */
1593
1594 if (0 <= end_offset
1595 && (end_offset < string_min || end_offset - string_min < address))
1596 break;
1597
1598 /* Store consecutive printable characters to BUF. */
1599 while (! (0 <= end_offset && end_offset <= address))
1600 {
1601 if (i == bufsize - 1)
1602 buf = xpalloc (buf, &bufsize, 1, -1, sizeof *buf);
1603 ok &= read_char (&c);
1604 if (c < 0)
1605 {
1606 free (buf);
1607 return ok;
1608 }
1609 address++;
1610 buf[i++] = c;
1611 if (c == '\0')
1612 break; /* Print this string. */
1613 if (! isprint (c))
1614 {
1615 c = -1; /* Give up on this string. */
1616 break;
1617 }
1618 }
1619
1620 if (c < 0 || i - !c < string_min)
1621 continue;
1622
1623 buf[i] = 0;
1624
1625 /* If we get here, the string is all printable, so print it. */
1626
1627 format_address (address - i, ' ');
1628
1629 for (i = 0; (c = buf[i]); i++)
1630 {
1631 switch (c)
1632 {
1633 case '\a':
1634 fputs ("\\a", stdout);
1635 break;
1636
1637 case '\b':
1638 fputs ("\\b", stdout);

Callers 1

mainFunction · 0.85

Calls 2

read_charFunction · 0.85
check_and_closeFunction · 0.85

Tested by

no test coverage detected