ash: fix bug 585 (>"$VAR_WITH_UNICODE_CHARS" problem)
[oweals/busybox.git] / mailutils / mime.c
index 358f4e9030c0d3c8acd02a82209c0385a676c336..dd81139f2434667283c202aa6bf219c0461b6b29 100644 (file)
@@ -177,7 +177,8 @@ int makemime_main(int argc UNUSED_PARAM, char **argv)
 static const char *find_token(const char *const string_array[], const char *key, const char *defvalue)
 {
        const char *r = NULL;
-       for (int i = 0; string_array[i] != 0; i++) {
+       int i;
+       for (i = 0; string_array[i] != NULL; i++) {
                if (strcasecmp(string_array[i], key) == 0) {
                        r = (char *)string_array[i+1];
                        break;
@@ -232,7 +233,7 @@ static int parse(const char *boundary, char **argv)
                // N.B. to avoid false positives let us seek to the _last_ occurance
                p = NULL;
                s = line;
-               while ((s=strcasestr(s, "Content-Type:")) != NULL)
+               while ((s = strcasestr(s, "Content-Type:")) != NULL)
                        p = s++;
                if (!p)
                        goto next;
@@ -281,8 +282,8 @@ static int parse(const char *boundary, char **argv)
                                pid = vfork();
                                if (0 == pid) {
                                        // child reads from fd[0]
-                                       xdup2(fd[0], STDIN_FILENO);
-                                       close(fd[0]); close(fd[1]);
+                                       close(fd[1]);
+                                       xmove_fd(fd[0], STDIN_FILENO);
                                        xsetenv("CONTENT_TYPE", type);
                                        xsetenv("CHARSET", charset);
                                        xsetenv("ENCODING", encoding);
@@ -308,7 +309,8 @@ static int parse(const char *boundary, char **argv)
                        if (0 == strcasecmp(encoding, "base64")) {
                                decode_base64(stdin, fp);
                        } else if (0 != strcasecmp(encoding, "7bit")
-                               && 0 != strcasecmp(encoding, "8bit")) {
+                               && 0 != strcasecmp(encoding, "8bit")
+                       ) {
                                // quoted-printable, binary, user-defined are unsupported so far
                                bb_error_msg_and_die("no support of encoding '%s'", encoding);
                        } else {
@@ -323,11 +325,15 @@ static int parse(const char *boundary, char **argv)
                                // no means to truncate what we already have sent to the helper.
                                p = xmalloc_fgets_str(stdin, "\r\n");
                                while (p) {
-                                       if ((s = xmalloc_fgets_str(stdin, "\r\n")) == NULL)
+                                       s = xmalloc_fgets_str(stdin, "\r\n");
+                                       if (s == NULL)
                                                break;
-                                       if ('-' == s[0] && '-' == s[1]
-                                               && 0 == strncmp(s+2, boundary, boundary_len))
+                                       if ('-' == s[0]
+                                        && '-' == s[1]
+                                        && 0 == strncmp(s+2, boundary, boundary_len)
+                                       ) {
                                                break;
+                                       }
                                        fputs(p, fp);
                                        p = s;
                                }