Move start_stop_daemon to debianutils.
[oweals/busybox.git] / coreutils / expr.c
index d6cc82e3ee5cae81419ded7334fe66ed535a5314..ecba825d58cc6d3eed49dae3d74e9a053253a392 100644 (file)
@@ -78,14 +78,14 @@ int expr_main (int argc, char **argv)
        VALUE *v;
 
        if (argc == 1) {
-               error_msg_and_die("too few arguments");
+               bb_error_msg_and_die("too few arguments");
        }
 
        args = argv + 1;
 
        v = eval ();
        if (*args)
-               error_msg_and_die ("syntax error");
+               bb_error_msg_and_die ("syntax error");
 
        if (v->type == integer)
                printf ("%d\n", v->u.i);
@@ -146,12 +146,8 @@ static int null (VALUE *v)
 
 static void tostring (VALUE *v)
 {
-       char *temp;
-
        if (v->type == integer) {
-               temp = xmalloc (4 * (sizeof (int) / sizeof (char)));
-               sprintf (temp, "%d", v->u.i);
-               v->u.s = temp;
+               bb_xasprintf (&(v->u.s), "%d", v->u.i);
                v->type = string;
        }
 }
@@ -194,7 +190,7 @@ nextarg (char *str)
 /* The comparison operator handling functions.  */
 
 #define cmpf(name, rel)                                        \
-static int name (l, r) VALUE *l; VALUE *r;             \
+static int name (VALUE *l, VALUE *r)           \
 {                                                      \
        if (l->type == string || r->type == string) {           \
                tostring (l);                           \
@@ -217,20 +213,20 @@ static int name (l, r) VALUE *l; VALUE *r;                \
 
 #define arithf(name, op)                       \
 static                                         \
-int name (l, r) VALUE *l; VALUE *r;            \
+int name (VALUE *l, VALUE *r)          \
 {                                              \
   if (!toarith (l) || !toarith (r))            \
-    error_msg_and_die ("non-numeric argument");        \
+    bb_error_msg_and_die ("non-numeric argument");     \
   return l->u.i op r->u.i;                     \
 }
 
 #define arithdivf(name, op)                    \
-static int name (l, r) VALUE *l; VALUE *r;             \
+static int name (VALUE *l, VALUE *r)           \
 {                                              \
   if (!toarith (l) || !toarith (r))            \
-    error_msg_and_die ( "non-numeric argument");       \
+    bb_error_msg_and_die ( "non-numeric argument");    \
   if (r->u.i == 0)                             \
-    error_msg_and_die ( "division by zero");           \
+    bb_error_msg_and_die ( "division by zero");                \
   return l->u.i op r->u.i;                     \
 }
 
@@ -274,7 +270,7 @@ of a basic regular expression is not portable; it is being ignored",
        re_syntax_options = RE_SYNTAX_POSIX_BASIC;
        errmsg = re_compile_pattern (pv->u.s, len, &re_buffer);
        if (errmsg) {
-               error_msg_and_die("%s", errmsg);
+               bb_error_msg_and_die("%s", errmsg);
        }
 
        len = re_match (&re_buffer, sv->u.s, strlen (sv->u.s), 0, &re_regs);
@@ -305,19 +301,19 @@ static VALUE *eval7 (void)
        VALUE *v;
 
        if (!*args)
-               error_msg_and_die ( "syntax error");
+               bb_error_msg_and_die ( "syntax error");
 
        if (nextarg ("(")) {
                args++;
                v = eval ();
                if (!nextarg (")"))
-                       error_msg_and_die ( "syntax error");
+                       bb_error_msg_and_die ( "syntax error");
                        args++;
                        return v;
                }
 
        if (nextarg (")"))
-               error_msg_and_die ( "syntax error");
+               bb_error_msg_and_die ( "syntax error");
 
        return str_value (*args++);
 }
@@ -331,7 +327,7 @@ static VALUE *eval6 (void)
        if (nextarg ("quote")) {
                args++;
                if (!*args)
-                       error_msg_and_die ( "syntax error");
+                       bb_error_msg_and_die ( "syntax error");
                return str_value (*args++);
        }
        else if (nextarg ("length")) {
@@ -377,9 +373,7 @@ static VALUE *eval6 (void)
                else {
                        v = xmalloc (sizeof(VALUE));
                        v->type = string;
-                       v->u.s = strncpy ((char *) xmalloc (i2->u.i + 1),
-                               l->u.s + i1->u.i - 1, i2->u.i);
-                               v->u.s[i2->u.i] = 0;
+                       v->u.s = bb_xstrndup(l->u.s + i1->u.i - 1, i2->u.i);
                }
                freev (l);
                freev (i1);
@@ -414,7 +408,7 @@ static VALUE *eval5 (void)
 static VALUE *eval4 (void)
 {
        VALUE *l, *r;
-       int (*fxn) (), val;
+       int (*fxn) (VALUE *, VALUE *), val;
 
        l = eval5 ();
        while (1) {
@@ -440,7 +434,7 @@ static VALUE *eval4 (void)
 static VALUE *eval3 (void)
 {
        VALUE *l, *r;
-       int (*fxn) (), val;
+       int (*fxn) (VALUE *, VALUE *), val;
 
        l = eval4 ();
        while (1) {
@@ -464,7 +458,7 @@ static VALUE *eval3 (void)
 static VALUE *eval2 (void)
 {
        VALUE *l, *r;
-       int (*fxn) (), val;
+       int (*fxn) (VALUE *, VALUE *), val;
 
        l = eval3 ();
        while (1) {