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

Function parse_old_offset

src/od.c:1463–1500  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1461 and possibly set *OFFSET. */
1462
1463static bool
1464parse_old_offset (char *str, intmax_t *offset)
1465{
1466 /* Skip over any leading '+'. */
1467 char *s = str + (str[0] == '+');
1468
1469 if (! c_isdigit (s[0]))
1470 return false;
1471
1472 /* Determine the radix for S. If there is a '.', followed first by
1473 optional 'b' or (undocumented) 'B' and then by end of string,
1474 it's decimal, otherwise, if the string begins with '0X' or '0x',
1475 it's hexadecimal, else octal. */
1476 char *dot = strchr (s, '.');
1477 if (dot && dot[(dot[1] == 'b' || dot[1] == 'B') + 1])
1478 dot = NULL;
1479 int radix = dot ? 10 : s[0] == '0' && (s[1] == 'x' || s[1] == 'X') ? 16 : 8;
1480
1481 if (dot)
1482 {
1483 /* Temporarily remove the '.' from the decimal string. */
1484 dot[0] = dot[1];
1485 dot[1] = '\0';
1486 }
1487
1488 enum strtol_error s_err = xstr2nonneg (s, radix, offset, "bB");
1489
1490 if (dot)
1491 {
1492 /* Restore the decimal string's original value. */
1493 dot[1] = dot[0];
1494 dot[0] = '.';
1495 }
1496
1497 if (s_err == LONGINT_OVERFLOW)
1498 error (EXIT_FAILURE, ERANGE, "%s", quotef (str));
1499 return s_err == LONGINT_OK;
1500}
1501
1502/* Read a chunk of size BYTES_PER_BLOCK from the input files, write the
1503 formatted block to standard output, and repeat until the specified

Callers 1

mainFunction · 0.85

Calls 1

xstr2nonnegFunction · 0.85

Tested by

no test coverage detected