diff options
| author | Rob Landley <rob@landley.net> | 2013-06-15 00:49:06 -0500 | 
|---|---|---|
| committer | Rob Landley <rob@landley.net> | 2013-06-15 00:49:06 -0500 | 
| commit | bc9cfe08cfa2c47b2d106eda7b5d0ecc73f47238 (patch) | |
| tree | 64dc550d1e9a8ebf9b8afb454d8f61d0a7f571ea | |
| parent | fdc0a0e74f2ac366399c152196a2498a0e98ad0a (diff) | |
| download | toybox-bc9cfe08cfa2c47b2d106eda7b5d0ecc73f47238.tar.gz | |
Force 64 bit math in expr, from Daniel Verkamp
| -rw-r--r-- | toys/pending/expr.c | 10 | 
1 files changed, 5 insertions, 5 deletions
| diff --git a/toys/pending/expr.c b/toys/pending/expr.c index 949bb664..dd27d58f 100644 --- a/toys/pending/expr.c +++ b/toys/pending/expr.c @@ -36,7 +36,7 @@ GLOBALS(  // If s is not NULL, the value is a string (s).  struct value {    char *s; -  long i; +  long long i;  };  static void parse_expr(struct value *ret, struct value *v); @@ -57,7 +57,7 @@ static void get_value(struct value *v)    arg = toys.optargs[TT.argidx++]; -  v->i = strtol(arg, &endp, 10); +  v->i = strtoll(arg, &endp, 10);    v->s = *endp ? arg : NULL;  } @@ -79,10 +79,10 @@ static int is_zero(const struct value *v)    return ((v->s && *v->s == '\0') || v->i == 0);  } -static char *num_to_str(long num) +static char *num_to_str(long long num)  {    static char num_buf[21]; -  snprintf(num_buf, sizeof(num_buf), "%ld", num); +  snprintf(num_buf, sizeof(num_buf), "%lld", num);    return num_buf;  } @@ -266,7 +266,7 @@ void expr_main(void)    if (!tok.s || *tok.s) error_exit("syntax error"); // final token should be end of expression    if (ret.s) printf("%s\n", ret.s); -  else printf("%ld\n", ret.i); +  else printf("%lld\n", ret.i);    exit(is_zero(&ret));  } | 
