#include "xbinary-io.h"
#include "xdectoint.h"
#include "xnanosleep.h"
-#include "xstrtol.h"
#if HAVE_INOTIFY
# include "hash.h"
static bool
parse_obsolete_option (int argc, char * const *argv, uintmax_t *n_units)
{
- char const *p;
- char const *n_string;
- char const *n_string_end;
- int default_count = DEFAULT_N_LINES;
bool t_from_start;
bool t_count_lines = true;
bool t_forever = false;
int posix_ver = posix2_version ();
bool obsolete_usage = posix_ver < 200112;
bool traditional_usage = obsolete_usage || 200809 <= posix_ver;
- p = argv[1];
+ char const *p = argv[1];
switch (*p++)
{
break;
}
- n_string = p;
- while (c_isdigit (*p))
- p++;
- n_string_end = p;
+ uintmax_t n;
+ if (!c_isdigit (*p))
+ n = DEFAULT_N_LINES;
+ else
+ for (n = 0; c_isdigit (*p); p++)
+ n = ckd_mul (&n, n, 10) || ckd_add (&n, n, *p - '0') ? UINTMAX_MAX : n;
switch (*p)
{
- case 'b': default_count *= 512; FALLTHROUGH;
+ case 'b': n = ckd_mul (&n, n, 512) ? UINTMAX_MAX : n; FALLTHROUGH;
case 'c': t_count_lines = false; FALLTHROUGH;
case 'l': p++; break;
}
if (*p)
return false;
- if (n_string == n_string_end)
- *n_units = default_count;
- else if ((xstrtoumax (n_string, nullptr, 10, n_units, "b")
- & ~LONGINT_INVALID_SUFFIX_CHAR)
- != LONGINT_OK)
- error (EXIT_FAILURE, errno, "%s: %s", _("invalid number"),
- quote (argv[1]));
+ *n_units = n;
/* Set globals. */
from_start = t_from_start;
#
['obs-plus-c1', '+2c', 'abcd', 'bcd', 0],
['obs-plus-c2', '+8c', 'abcd', '', 0],
+['obs-plus-c3', '+999999999999999999999999999999999999999999c', 'abcd', '', 0],
['obs-c3', '-1c', 'abcd', 'd', 0],
['obs-c4', '-9c', 'abcd', 'abcd', 0],
['obs-c5', '-12c', 'x' . ('y' x 12) . 'z', ('y' x 11) . 'z', 0],