[BusyBox] [PATCH] 64bit arithmetic for ash
Bastian Blank
waldi at debian.org
Fri Jun 18 21:11:13 UTC 2004
Hi folks
The attached patch makes ash able to do 64bit arithmetic.
Bastian
--
Landru! Guide us!
-- A Beta 3-oid, "The Return of the Archons", stardate 3157.4
-------------- next part --------------
Index: include/libbb.h
===================================================================
--- include/libbb.h (revision 450)
+++ include/libbb.h (working copy)
@@ -289,7 +289,7 @@
char *concat_subpath_file(const char *path, const char *filename);
char *last_char_is(const char *s, int c);
-extern long arith (const char *startbuf, int *errcode);
+extern int64_t arith (const char *startbuf, int *errcode);
int read_package_field(const char *package_buffer, char **field_name, char **field_value);
//#warning yuk!
Index: shell/ash.c
===================================================================
--- shell/ash.c (revision 450)
+++ shell/ash.c (working copy)
@@ -1446,7 +1446,7 @@
static void unsetfunc(const char *);
#ifdef CONFIG_ASH_MATH_SUPPORT
-static long dash_arith(const char *);
+static int64_t dash_arith(const char *);
#endif
#ifdef CONFIG_ASH_RANDOM_SUPPORT
@@ -4531,7 +4531,7 @@
static void expandmeta(struct strlist *, int);
static int patmatch(char *, const char *);
-static int cvtnum(long);
+static int cvtnum(int64_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 +5902,12 @@
*/
static int
-cvtnum(long num)
+cvtnum(int64_t num)
{
int len;
expdest = makestrspace(32, expdest);
- len = fmtstr(expdest, 32, "%ld", num);
+ len = fmtstr(expdest, 32, "%lld", (long long) num);
STADJUST(len, expdest);
return len;
}
@@ -12488,10 +12488,10 @@
}
#ifdef CONFIG_ASH_MATH_SUPPORT
-static long
+static int64_t
dash_arith(const char *s)
{
- long result;
+ int64_t result;
int errcode = 0;
INTOFF;
@@ -12523,7 +12523,7 @@
letcmd(int argc, char **argv)
{
char **ap;
- long i;
+ int64_t i;
ap = argv + 1;
if(!*ap)
@@ -13094,8 +13094,8 @@
typedef struct ARITCH_VAR_NUM {
- long val;
- long contidional_second_val;
+ int64_t val;
+ int64_t contidional_second_val;
char contidional_second_val_initialized;
char *var; /* if NULL then is regular number,
else is variable name */
@@ -13152,9 +13152,9 @@
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 +13280,7 @@
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 +13343,7 @@
#define endexpression &op_tokens[sizeof(op_tokens)-7]
-extern long arith (const char *expr, int *perrcode)
+extern int64_t arith (const char *expr, int *perrcode)
{
register char arithval; /* Current character under analysis */
operator lasttok, op;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
Url : http://lists.busybox.net/pipermail/busybox/attachments/20040618/0978b591/attachment-0002.pgp
More information about the busybox
mailing list