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

Function toarith

src/expr.c:471–493  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

469/* Coerce V to an integer value. Return true on success, false on failure. */
470
471static bool
472toarith (VALUE *v)
473{
474 switch (v->type)
475 {
476 case integer:
477 return true;
478 case string:
479 {
480 char *s = v->u.s;
481
482 if (! looks_like_integer (s))
483 return false;
484 if (mpz_init_set_str (v->u.i, s, 10) != 0)
485 error (EXPR_FAILURE, ERANGE, "%s", (s));
486 free (s);
487 v->type = integer;
488 return true;
489 }
490 default:
491 unreachable ();
492 }
493}
494
495/* Extract a size_t value from an integer value I.
496 If the value is negative, return SIZE_MAX.

Callers 3

eval6Function · 0.85
eval4Function · 0.85
eval3Function · 0.85

Calls 1

looks_like_integerFunction · 0.85

Tested by

no test coverage detected