aboutsummaryrefslogtreecommitdiff
path: root/shell/ash.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2004-06-22 08:29:45 +0000
committerEric Andersen <andersen@codepoet.org>2004-06-22 08:29:45 +0000
commited9ecf78942e6da6f23f2e480639135c10631313 (patch)
tree1f7b66f71f04cf66fab5fc0a385adb34d5d5b97b /shell/ash.c
parent16a4c4167434d3626cdaf882fd6738dee2192606 (diff)
downloadbusybox-ed9ecf78942e6da6f23f2e480639135c10631313.tar.gz
Patch from Bastian Blank:
The updated patch adds a config option to explicitely enable 64 bit arithmetic. Also it removes the arith prototype from libbb.h as it is not used outside of ash. Bastian this patch has been slightly modified by Erik for cleanliness.
Diffstat (limited to 'shell/ash.c')
-rw-r--r--shell/ash.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/shell/ash.c b/shell/ash.c
index e2205efd2..a1c4f346b 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -1446,7 +1446,13 @@ static void defun(char *, union node *);
static void unsetfunc(const char *);
#ifdef CONFIG_ASH_MATH_SUPPORT
-static long dash_arith(const char *);
+#ifdef CONFIG_ASH_MATH_SUPPORT_64
+typedef int64_t arith_t;
+#else
+typedef long arith_t;
+#endif
+static arith_t dash_arith(const char *);
+static arith_t arith(const char *expr, int *perrcode);
#endif
#ifdef CONFIG_ASH_RANDOM_SUPPORT
@@ -4531,7 +4537,7 @@ static void ifsfree(void);
static void expandmeta(struct strlist *, int);
static int patmatch(char *, const char *);
-static int cvtnum(long);
+static int cvtnum(arith_t);
static size_t esclen(const char *, const char *);
static char *scanleft(char *, char *, char *, char *, int, int);
static char *scanright(char *, char *, char *, char *, int, int);
@@ -5902,12 +5908,16 @@ casematch(union node *pattern, char *val)
*/
static int
-cvtnum(long num)
+cvtnum(arith_t num)
{
int len;
expdest = makestrspace(32, expdest);
+#ifdef CONFIG_ASH_MATH_SUPPORT_64
+ len = fmtstr(expdest, 32, "%lld", (long long) num);
+#else
len = fmtstr(expdest, 32, "%ld", num);
+#endif
STADJUST(len, expdest);
return len;
}
@@ -12488,10 +12498,10 @@ static int timescmd(int ac, char **av)
}
#ifdef CONFIG_ASH_MATH_SUPPORT
-static long
+static arith_t
dash_arith(const char *s)
{
- long result;
+ arith_t result;
int errcode = 0;
INTOFF;
@@ -12523,7 +12533,7 @@ static int
letcmd(int argc, char **argv)
{
char **ap;
- long i;
+ arith_t i;
ap = argv + 1;
if(!*ap)
@@ -13094,8 +13104,8 @@ static inline int is_right_associativity(operator prec)
typedef struct ARITCH_VAR_NUM {
- long val;
- long contidional_second_val;
+ arith_t val;
+ arith_t contidional_second_val;
char contidional_second_val_initialized;
char *var; /* if NULL then is regular number,
else is variable name */
@@ -13152,9 +13162,9 @@ static int arith_lookup_val(v_n_t *t)
static inline int
arith_apply(operator op, v_n_t *numstack, v_n_t **numstackptr)
{
- long numptr_val;
+ int64_t numptr_val;
v_n_t *numptr_m1;
- long rez;
+ int64_t rez;
int ret_arith_lookup_val;
if (NUMPTR == numstack) goto err; /* There is no operator that can work
@@ -13280,7 +13290,7 @@ arith_apply(operator op, v_n_t *numstack, v_n_t **numstackptr)
goto err;
}
/* save to shell variable */
- sprintf(buf, "%ld", rez);
+ sprintf(buf, "%lld", (long long) rez);
setvar(numptr_m1->var, buf, 0);
/* after saving, make previous value for v++ or v-- */
if(op == TOK_POST_INC)
@@ -13343,7 +13353,7 @@ static const char op_tokens[] = {
#define endexpression &op_tokens[sizeof(op_tokens)-7]
-extern long arith (const char *expr, int *perrcode)
+static arith_t arith (const char *expr, int *perrcode)
{
register char arithval; /* Current character under analysis */
operator lasttok, op;