]> diplodocus.org Git - nmh/blobdiff - uip/dropsbr.c
sbr/dtimep.l: Remove redundant wrapping parenthesis in definitions.
[nmh] / uip / dropsbr.c
index bf16b60f3e11d40e1f2cbf1f79d9e115aaeea383..3109bcf78a1223cbcd08ef0c2a3ef2694c5439cd 100644 (file)
@@ -1,6 +1,4 @@
-
-/*
- * dropsbr.c -- create/read/manipulate mail drops
+/* dropsbr.c -- create/read/manipulate mail drops
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -48,19 +46,16 @@ mbx_open (char *file, int mbx_style, uid_t uid, gid_t gid, mode_t mode)
     /* attempt to open and lock file */
     for (count = 4; count > 0; count--) {
         int failed_to_lock = 0;
-       if ((fd = lkopenspool (file, O_RDWR | O_CREAT |
-                              O_NONBLOCK, mode, &failed_to_lock)) == NOTOK) {
-            if (failed_to_lock) {
-                j = errno;
-                sleep (5);
-                continue;
-            } else {
-                return NOTOK;
-            }
-       }
 
-       /* good file descriptor */
-       break;
+       if ((fd = lkopenspool (file, O_RDWR | O_CREAT | O_NONBLOCK,
+            mode, &failed_to_lock)) != NOTOK)
+            break;
+
+        if (!failed_to_lock)
+            return NOTOK;
+
+        j = errno;
+        sleep (5);
     }
 
     errno = j;
@@ -272,7 +267,7 @@ mbx_copy (char *mailbox, int mbx_style, int md, int fd,
     int i, j, size;
     off_t start, stop;
     long pos;
-    char *cp, buffer[BUFSIZ];
+    char *cp, buffer[BUFSIZ + 1];   /* Space for NUL. */
     FILE *fp;
 
     pos = (long) lseek (md, (off_t) 0, SEEK_CUR);
@@ -295,10 +290,8 @@ mbx_copy (char *mailbox, int mbx_style, int md, int fd,
                        size++;
            }
                    
-           while ((i = read (fd, buffer, sizeof(buffer))) > 0) {
-                /* valgrind noticed that stringdex depends on null
-                   termination. */
-                buffer[i] = '\0';
+           while ((i = read (fd, buffer, sizeof buffer - 1)) > 0) {
+                buffer[i] = '\0';   /* Terminate for stringdex(). */
 
                for ( ; (j = stringdex (mmdlm1, buffer)) >= 0; buffer[j]++)
                    continue;
@@ -351,7 +344,7 @@ mbx_copy (char *mailbox, int mbx_style, int md, int fd,
                     * back to "From ".
                     */
                     if (has_prefix(buffer, "Return-Path:")) {
-                       char tmpbuffer[BUFSIZ];
+                       char tmpbuffer[sizeof buffer];
                        char *tp, *ep, *fp;
 
                        strncpy(tmpbuffer, buffer, sizeof(tmpbuffer));
@@ -366,7 +359,7 @@ mbx_copy (char *mailbox, int mbx_style, int md, int fd,
                         * Change the "X-Envelope-From:" field
                         * (if first line) back to "From ".
                         */
-                       char tmpbuffer[BUFSIZ];
+                       char tmpbuffer[sizeof buffer];
                        char *ep;
 
                        strncpy(tmpbuffer, buffer, sizeof(tmpbuffer));
@@ -377,7 +370,7 @@ mbx_copy (char *mailbox, int mbx_style, int md, int fd,
                         * If there is already a "From " line,
                         * then leave it alone.  Else we add one.
                         */
-                       char tmpbuffer[BUFSIZ];
+                       char tmpbuffer[sizeof buffer];
                        char *tp, *ep;
 
                        strncpy(tmpbuffer, buffer, sizeof(tmpbuffer));