* patch #3966: Create a mh_xmalloc function to prevent mistakes when
[mmh] / uip / mhbuildsbr.c
index 73907ab..64ec8a6 100644 (file)
@@ -3,6 +3,10 @@
  * mhbuildsbr.c -- routines to expand/translate MIME composition files
  *
  * $Id$
+ *
+ * This code is Copyright (c) 2002, by the authors of nmh.  See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
  */
 
 /*
 #include <h/md5.h>
 #include <errno.h>
 #include <signal.h>
-#include <zotnet/mts/mts.h>
-#include <zotnet/tws/tws.h>
+#include <h/mts.h>
+#include <h/tws.h>
 #include <h/mime.h>
 #include <h/mhparse.h>
+#include <h/utils.h>
+
+#ifdef TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# ifdef TM_IN_SYS_TIME
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
 
 #ifdef HAVE_SYS_WAIT_H
 # include <sys/wait.h>
 #endif
 
 
-extern int errno;
-
 extern int debugsw;
 extern int verbosw;
 
@@ -227,8 +241,7 @@ pidcheck (int status)
 
     fflush (stdout);
     fflush (stderr);
-    done (1);
-    /* NOTREACHED */
+    return done (1);
 }
 
 
@@ -773,8 +786,7 @@ add_header (CT ct, char *name, char *value)
     HF hp;
 
     /* allocate header field structure */
-    if (!(hp = malloc (sizeof(*hp))))
-       adios (NULL, "out of memory");
+    hp = mh_xmalloc (sizeof(*hp));
 
     /* link data into header structure */
     hp->name = name;
@@ -1433,9 +1445,9 @@ InitMessage (CT ct)
     struct k2v *kv;
     CI ci = &ct->c_ctinfo;
 
-    if (ct->c_encoding != CE_7BIT) {
+    if ((ct->c_encoding != CE_7BIT) && (ct->c_encoding != CE_8BIT)) {
        admonish (NULL,
-                 "\"%s/%s\" type in message %s should be encoded in 7bit",
+                 "\"%s/%s\" type in message %s should be encoded in 7bit or 8bit",
                  ci->ci_type, ci->ci_subtype, ct->c_file);
        return NOTOK;
     }
@@ -1541,8 +1553,7 @@ invalid_param:
                        goto no_body;
                    }
                    
-                   if ((e->eb_body = bp = malloc ((unsigned) size)) == NULL)
-                       adios (NULL, "out of memory");
+                   e->eb_body = bp = mh_xmalloc ((unsigned) size);
                    fseek (p->c_fp, p->c_begin, SEEK_SET);
                    while (size > 0)
                        switch (cc = fread (bp, sizeof(*bp), size, p->c_fp)) {
@@ -2662,7 +2673,7 @@ losing_ftp:
            goto losing_ftp;
 #endif
 
-    if (cachefile[0])
+    if (cachefile[0]) {
        if (caching)
            chmod (cachefile, cachetype ? m_gmprot () : 0444);
        else {
@@ -2676,7 +2687,7 @@ losing_ftp:
 
                fseek (gp, 0L, SEEK_SET);
 
-               while ((cc = fread (buffer, sizeof(*buffer), sizeof(buffer), gp))
+               while ((cc= fread (buffer, sizeof(*buffer), sizeof(buffer), gp))
                           > 0)
                    fwrite (buffer, sizeof(*buffer), cc, fp);
                fflush (fp);
@@ -2694,6 +2705,7 @@ losing_ftp:
            }
            umask (mask);
        }
+    }
 
     fseek (ce->ce_fp, 0L, SEEK_SET);
     *file = ce->ce_file;
@@ -3159,11 +3171,12 @@ use_forw:
        /* search the arguments for a folder name */
        for (ap = arguments; *ap; ap++) {
            cp = *ap;
-           if (*cp == '+' || *cp == '@')
+           if (*cp == '+' || *cp == '@') {
                if (folder)
                    adios (NULL, "only one folder per #forw directive");
                else
                    folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
+           }
        }
 
        /* else, use the current folder */