]> diplodocus.org Git - nmh/blobdiff - uip/distsbr.c
Removed "sleazy hack" of negative bufsz because commit
[nmh] / uip / distsbr.c
index 0191037691f388840a6b86650b4ee86c3cb198aa..bbaeaf51980a940ad792a94aeb75a6ec2c904fcb 100644 (file)
@@ -2,8 +2,6 @@
 /*
  * distsbr.c -- routines to do additional "dist-style" processing
  *
 /*
  * distsbr.c -- routines to do additional "dist-style" processing
  *
- * $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.
  * 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.
@@ -30,7 +28,8 @@ int
 distout (char *drft, char *msgnam, char *backup)
 {
     int state;
 distout (char *drft, char *msgnam, char *backup)
 {
     int state;
-    register char *dp, *resent;
+    register unsigned char *dp;
+    register char *resent;
     char name[NAMESZ], buffer[BUFSIZ];
     register FILE *ifp, *ofp;
 
     char name[NAMESZ], buffer[BUFSIZ];
     register FILE *ifp, *ofp;
 
@@ -47,9 +46,9 @@ distout (char *drft, char *msgnam, char *backup)
     lseek (hdrfd, (off_t) 0, SEEK_SET); /* msgnam not accurate */
     cpydata (hdrfd, fileno (ofp), msgnam, drft);
 
     lseek (hdrfd, (off_t) 0, SEEK_SET); /* msgnam not accurate */
     cpydata (hdrfd, fileno (ofp), msgnam, drft);
 
-    for (state = FLD, resent = NULL;;)
-       switch (state =
-               m_getfld (state, name, buffer, sizeof buffer, ifp)) {
+    for (state = FLD, resent = NULL;;) {
+       int buffersz = sizeof buffer;
+       switch (state = m_getfld (state, name, buffer, &buffersz, ifp)) {
            case FLD: 
            case FLDPLUS: 
            case FLDEOF: 
            case FLD: 
            case FLDPLUS: 
            case FLDEOF: 
@@ -66,8 +65,8 @@ distout (char *drft, char *msgnam, char *backup)
                resent = add (buffer, resent);
                fprintf (ofp, "%s: %s", name, buffer);
                while (state == FLDPLUS) {
                resent = add (buffer, resent);
                fprintf (ofp, "%s: %s", name, buffer);
                while (state == FLDPLUS) {
-                   state = m_getfld (state, name,
-                           buffer, sizeof buffer, ifp);
+                   buffersz = sizeof buffer;
+                   state = m_getfld (state, name, buffer, &buffersz, ifp);
                    resent = add (buffer, resent);
                    fputs (buffer, ofp);
                }
                    resent = add (buffer, resent);
                    fputs (buffer, ofp);
                }
@@ -100,6 +99,7 @@ distout (char *drft, char *msgnam, char *backup)
            default: 
                adios (NULL, "getfld() returned %d", state);
        }
            default: 
                adios (NULL, "getfld() returned %d", state);
        }
+    }
 process: ;
     fclose (ifp);
     fflush (ofp);
 process: ;
     fclose (ifp);
     fflush (ofp);
@@ -131,6 +131,7 @@ ready_msg (char *msgnam)
     int state, out;
     char name[NAMESZ], buffer[BUFSIZ], tmpfil[BUFSIZ];
     register FILE *ifp, *ofp;
     int state, out;
     char name[NAMESZ], buffer[BUFSIZ], tmpfil[BUFSIZ];
     register FILE *ifp, *ofp;
+    char *cp = NULL;
 
     if (hdrfd != NOTOK)
        close (hdrfd), hdrfd = NOTOK;
 
     if (hdrfd != NOTOK)
        close (hdrfd), hdrfd = NOTOK;
@@ -140,17 +141,20 @@ ready_msg (char *msgnam)
     if ((ifp = fopen (msgnam, "r")) == NULL)
        adios (msgnam, "unable to open message");
 
     if ((ifp = fopen (msgnam, "r")) == NULL)
        adios (msgnam, "unable to open message");
 
-    strncpy (tmpfil, m_tmpfil ("dist"), sizeof(tmpfil));
-    if ((hdrfd = open (tmpfil, O_RDWR | O_CREAT | O_TRUNC, 0600)) == NOTOK)
-       adios (tmpfil, "unable to re-open temporary file");
+    cp = m_mktemp2(NULL, "dist", &hdrfd, NULL);
+    if (cp == NULL) {
+        adios("distsbr", "unable to create temporary file");
+    }
+    fchmod(hdrfd, 0600);
+    strncpy(tmpfil, cp, sizeof(tmpfil));
     if ((out = dup (hdrfd)) == NOTOK
            || (ofp = fdopen (out, "w")) == NULL)
        adios (NULL, "no file descriptors -- you lose big");
     unlink (tmpfil);
 
     if ((out = dup (hdrfd)) == NOTOK
            || (ofp = fdopen (out, "w")) == NULL)
        adios (NULL, "no file descriptors -- you lose big");
     unlink (tmpfil);
 
-    for (state = FLD;;)
-       switch (state =
-               m_getfld (state, name, buffer, sizeof buffer, ifp)) {
+    for (state = FLD;;) {
+       int buffersz = sizeof buffer;
+       switch (state = m_getfld (state, name, buffer, &buffersz, ifp)) {
            case FLD: 
            case FLDPLUS: 
            case FLDEOF: 
            case FLD: 
            case FLDPLUS: 
            case FLDEOF: 
@@ -158,8 +162,8 @@ ready_msg (char *msgnam)
                    fprintf (ofp, "Prev-");
                fprintf (ofp, "%s: %s", name, buffer);
                while (state == FLDPLUS) {
                    fprintf (ofp, "Prev-");
                fprintf (ofp, "%s: %s", name, buffer);
                while (state == FLDPLUS) {
-                   state = m_getfld (state, name,
-                           buffer, sizeof buffer, ifp);
+                   buffersz = sizeof buffer;
+                   state = m_getfld (state, name, buffer, &buffersz, ifp);
                    fputs (buffer, ofp);
                }
                if (state == FLDEOF)
                    fputs (buffer, ofp);
                }
                if (state == FLDEOF)
@@ -170,17 +174,20 @@ ready_msg (char *msgnam)
            case BODYEOF: 
                fclose (ofp);
 
            case BODYEOF: 
                fclose (ofp);
 
-               strncpy (tmpfil, m_tmpfil ("dist"), sizeof(tmpfil));
-               if ((txtfd = open (tmpfil, O_RDWR | O_CREAT | O_TRUNC, 0600)) == NOTOK)
-                   adios (tmpfil, "unable to open temporary file");
+                cp = m_mktemp2(NULL, "dist", &txtfd, NULL);
+                if (cp == NULL) {
+                    adios("distsbr", "unable to create temporary file");
+                }
+                fchmod(txtfd, 0600);
+               strncpy (tmpfil, cp, sizeof(tmpfil));
                if ((out = dup (txtfd)) == NOTOK
                        || (ofp = fdopen (out, "w")) == NULL)
                    adios (NULL, "no file descriptors -- you lose big");
                unlink (tmpfil);
                fprintf (ofp, "\n%s", buffer);
                while (state == BODY) {
                if ((out = dup (txtfd)) == NOTOK
                        || (ofp = fdopen (out, "w")) == NULL)
                    adios (NULL, "no file descriptors -- you lose big");
                unlink (tmpfil);
                fprintf (ofp, "\n%s", buffer);
                while (state == BODY) {
-                   state = m_getfld (state, name,
-                           buffer, sizeof buffer, ifp);
+                   buffersz = sizeof buffer;
+                   state = m_getfld (state, name, buffer, &buffersz, ifp);
                    fputs (buffer, ofp);
                }
            case FILEEOF: 
                    fputs (buffer, ofp);
                }
            case FILEEOF: 
@@ -193,6 +200,7 @@ ready_msg (char *msgnam)
            default: 
                adios (NULL, "getfld() returned %d", state);
        }
            default: 
                adios (NULL, "getfld() returned %d", state);
        }
+    }
 process: ;
     fclose (ifp);
     fclose (ofp);
 process: ;
     fclose (ifp);
     fclose (ofp);