]> diplodocus.org Git - nmh/blobdiff - uip/dropsbr.c
lock_file.c: close(2) file descriptor on failure, avoiding leak.
[nmh] / uip / dropsbr.c
index 7c8fe246fea5700b1d1edbb49e45e52c21c18a49..40ec9b806451feb55949738fbb41eb98a38f0e5e 100644 (file)
@@ -6,22 +6,13 @@
  */
 
 #include <h/nmh.h>
-#include <h/utils.h>
-
 #include <h/mh.h>
+#include <h/utils.h>
 #include <h/dropsbr.h>
 #include <h/mts.h>
 #include <h/tws.h>
-#include "../sbr/lock_file.h"
-#include "../sbr/m_mktemp.h"
-
-#ifdef NTOHLSWAP
-# include <netinet/in.h>
-#else
-# undef ntohl
-# define ntohl(n) (n)
-#endif
-
+#include "sbr/lock_file.h"
+#include "sbr/m_mktemp.h"
 #include <fcntl.h>
 
 /*
@@ -82,7 +73,7 @@ mbx_open (char *file, int mbx_style, uid_t uid, gid_t gid, mode_t mode)
        if (chmod (file, mode) < 0) {
            advise (file, "chmod");
        }
-    } else if (st.st_size > (off_t) 0) {
+    } else if (st.st_size > 0) {
        int status;
 
        /* check the maildrop */
@@ -116,7 +107,7 @@ static int
 mbx_chk_mbox (int fd)
 {
     /* just seek to the end */
-    if (lseek (fd, (off_t) 0, SEEK_END) == (off_t) NOTOK)
+    if (lseek(fd, 0, SEEK_END) == (off_t) NOTOK)
        return NOTOK;
 
     return OK;
@@ -133,7 +124,7 @@ mbx_chk_mmdf (int fd)
     ssize_t count;
     char ldelim[BUFSIZ];
 
-    count = strlen (mmdlm2);
+    count = LEN(MMDF_DELIM);
 
     if (lseek (fd, -count, SEEK_END) == (off_t) NOTOK)
        return NOTOK;
@@ -142,9 +133,9 @@ mbx_chk_mmdf (int fd)
 
     ldelim[count] = 0;
 
-    if (strcmp (ldelim, mmdlm2)
+    if (strcmp (ldelim, MMDF_DELIM)
            && write (fd, "\n", 1) != 1
-           && write (fd, mmdlm2, count) != count)
+           && write (fd, MMDF_DELIM, count) != count)
        return NOTOK;
 
     return OK;
@@ -168,8 +159,8 @@ mbx_copy (char *mailbox, int mbx_style, int md, int fd,
     switch (mbx_style) {
        case MMDF_FORMAT: 
        default: 
-           j = strlen (mmdlm1);
-           if (write (md, mmdlm1, j) != j)
+           j = LEN(MMDF_DELIM);
+           if (write (md, MMDF_DELIM, j) != j)
                return NOTOK;
 
            if (text) {
@@ -184,16 +175,16 @@ mbx_copy (char *mailbox, int mbx_style, int md, int fd,
            while ((i = read (fd, buffer, sizeof buffer - 1)) > 0) {
                 buffer[i] = '\0';   /* Terminate for stringdex(). */
 
-               for ( ; (j = stringdex (mmdlm1, buffer)) >= 0; buffer[j]++)
+               for ( ; (j = stringdex (MMDF_DELIM, buffer)) >= 0; buffer[j]++)
                    continue;
-               for ( ; (j = stringdex (mmdlm2, buffer)) >= 0; buffer[j]++)
+               for ( ; (j = stringdex (MMDF_DELIM, buffer)) >= 0; buffer[j]++)
                    continue;
                if (write (md, buffer, i) != i)
                    return NOTOK;
            }
 
-           j = strlen (mmdlm2);
-           if (write (md, mmdlm2, j) != j)
+           j = LEN(MMDF_DELIM);
+           if (write (md, MMDF_DELIM, j) != j)
                return NOTOK;
 
            return (i != NOTOK ? OK : NOTOK);
@@ -285,7 +276,7 @@ mbx_copy (char *mailbox, int mbx_style, int md, int fd,
            }
 
            fclose (fp);
-           lseek (fd, (off_t) 0, SEEK_END);
+           lseek(fd, 0, SEEK_END);
 
            return OK;
     }