[BACK]Return to quit.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mail

Diff for /src/usr.bin/mail/quit.c between version 1.3 and 1.4

version 1.3, 1997/03/29 03:01:47 version 1.4, 1997/07/13 21:21:16
Line 1 
Line 1 
 /*      $OpenBSD$       */  /*      $OpenBSD$       */
 /*      $NetBSD: quit.c,v 1.5 1996/06/08 19:48:37 christos Exp $        */  /*      $NetBSD: quit.c,v 1.6 1996/12/28 07:11:07 tls Exp $     */
   
 /*  /*
  * Copyright (c) 1980, 1993   * Copyright (c) 1980, 1993
Line 36 
Line 36 
   
 #ifndef lint  #ifndef lint
 #if 0  #if 0
 static char sccsid[] = "@(#)quit.c      8.1 (Berkeley) 6/6/93";  static char sccsid[] = "@(#)quit.c      8.2 (Berkeley) 4/28/95";
 #else  #else
 static char rcsid[] = "$OpenBSD$";  static char rcsid[] = "$OpenBSD$";
 #endif  #endif
Line 64 
Line 64 
          * Otherwise, return -1 to abort command loop.           * Otherwise, return -1 to abort command loop.
          */           */
         if (sourcing)          if (sourcing)
                 return 1;                  return(1);
         return -1;          return(-1);
 }  }
   
 /*  /*
Line 113 
Line 113 
         if (fbuf == NULL)          if (fbuf == NULL)
                 goto newmail;                  goto newmail;
         if (flock(fileno(fbuf), LOCK_EX) == -1) {          if (flock(fileno(fbuf), LOCK_EX) == -1) {
                 perror("Unable to lock mailbox");                  warn("Unable to lock mailbox");
                 Fclose(fbuf);                  (void)Fclose(fbuf);
                 return;                  return;
         }          }
         if (!spool_lock()) {          if (!spool_lock()) {
                 Fclose(fbuf);                  (void)Fclose(fbuf);
                 return;                 /* mail.local printed error for us */                  return;                 /* mail.local printed error for us */
         }          }
         rbuf = NULL;          rbuf = NULL;
         if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) {          if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) {
                 printf("New mail has arrived.\n");                  puts("New mail has arrived.");
                 rbuf = Fopen(tempResid, "w");                  rbuf = Fopen(tempResid, "w");
                 if (rbuf == NULL || fbuf == NULL)                  if (rbuf == NULL || fbuf == NULL)
                         goto newmail;                          goto newmail;
Line 140 
Line 140 
                         (void) putc(c, rbuf);                          (void) putc(c, rbuf);
                 }                  }
 #endif  #endif
                 Fclose(rbuf);                  (void)Fclose(rbuf);
                 if ((rbuf = Fopen(tempResid, "r")) == NULL)                  if ((rbuf = Fopen(tempResid, "r")) == NULL)
                         goto newmail;                          goto newmail;
                 rm(tempResid);                  rm(tempResid);
Line 188 
Line 188 
                 }                  }
         }          }
         if (Tflag != NOSTR)          if (Tflag != NOSTR)
                 Fclose(readstat);                  (void)Fclose(readstat);
         if (p == msgCount && !modify && !anystat) {          if (p == msgCount && !modify && !anystat) {
                 printf("Held %d message%s in %s\n",                  printf("Held %d message%s in %s\n",
                         p, p == 1 ? "" : "s", mailname);                          p, p == 1 ? "" : "s", mailname);
                 Fclose(fbuf);                  (void)Fclose(fbuf);
                 spool_unlock();                  spool_unlock();
                 return;                  return;
         }          }
         if (c == 0) {          if (c == 0) {
                 if (p != 0) {                  if (p != 0) {
                         writeback(rbuf);                          writeback(rbuf);
                         Fclose(fbuf);                          (void)Fclose(fbuf);
                         spool_unlock();                          spool_unlock();
                         return;                          return;
                 }                  }
Line 217 
Line 217 
         mcount = c;          mcount = c;
         if (value("append") == NOSTR) {          if (value("append") == NOSTR) {
                 if ((obuf = Fopen(tempQuit, "w")) == NULL) {                  if ((obuf = Fopen(tempQuit, "w")) == NULL) {
                         perror(tempQuit);                          warn(tempQuit);
                         Fclose(fbuf);                          (void)Fclose(fbuf);
                         spool_unlock();                          spool_unlock();
                         return;                          return;
                 }                  }
                 if ((ibuf = Fopen(tempQuit, "r")) == NULL) {                  if ((ibuf = Fopen(tempQuit, "r")) == NULL) {
                         perror(tempQuit);                          warn(tempQuit);
                         rm(tempQuit);                          rm(tempQuit);
                         Fclose(obuf);                          (void)Fclose(obuf);
                         Fclose(fbuf);                          (void)Fclose(fbuf);
                         spool_unlock();                          spool_unlock();
                         return;                          return;
                 }                  }
Line 234 
Line 234 
                 if ((abuf = Fopen(mbox, "r")) != NULL) {                  if ((abuf = Fopen(mbox, "r")) != NULL) {
                         while ((c = getc(abuf)) != EOF)                          while ((c = getc(abuf)) != EOF)
                                 (void) putc(c, obuf);                                  (void) putc(c, obuf);
                         Fclose(abuf);                          (void)Fclose(abuf);
                 }                  }
                 if (ferror(obuf)) {                  if (ferror(obuf)) {
                         perror(tempQuit);                          warn(tempQuit);
                         Fclose(ibuf);                          (void)Fclose(ibuf);
                         Fclose(obuf);                          (void)Fclose(obuf);
                         Fclose(fbuf);                          (void)Fclose(fbuf);
                         spool_unlock();                          spool_unlock();
                         return;                          return;
                 }                  }
                 Fclose(obuf);                  (void)Fclose(obuf);
                 close(creat(mbox, 0600));                  (void)close(creat(mbox, 0600));
                 if ((obuf = Fopen(mbox, "r+")) == NULL) {                  if ((obuf = Fopen(mbox, "r+")) == NULL) {
                         perror(mbox);                          warn(mbox);
                         Fclose(ibuf);                          (void)Fclose(ibuf);
                         Fclose(fbuf);                          (void)Fclose(fbuf);
                         spool_unlock();                          spool_unlock();
                         return;                          return;
                 }                  }
         }          }
         else {          else {
                 if ((obuf = Fopen(mbox, "a")) == NULL) {                  if ((obuf = Fopen(mbox, "a")) == NULL) {
                         perror(mbox);                          warn(mbox);
                         Fclose(fbuf);                          (void)Fclose(fbuf);
                         spool_unlock();                          spool_unlock();
                         return;                          return;
                 }                  }
Line 266 
Line 266 
         for (mp = &message[0]; mp < &message[msgCount]; mp++)          for (mp = &message[0]; mp < &message[msgCount]; mp++)
                 if (mp->m_flag & MBOX)                  if (mp->m_flag & MBOX)
                         if (send(mp, obuf, saveignore, NOSTR) < 0) {                          if (send(mp, obuf, saveignore, NOSTR) < 0) {
                                 perror(mbox);                                  warn(mbox);
                                 Fclose(ibuf);                                  (void)Fclose(ibuf);
                                 Fclose(obuf);                                  (void)Fclose(obuf);
                                 Fclose(fbuf);                                  (void)Fclose(fbuf);
                                 spool_unlock();                                  spool_unlock();
                                 return;                                  return;
                         }                          }
Line 289 
Line 289 
                                 break;                                  break;
                         c = getc(ibuf);                          c = getc(ibuf);
                 }                  }
                 Fclose(ibuf);                  (void)Fclose(ibuf);
                 fflush(obuf);                  fflush(obuf);
         }          }
         trunc(obuf);          trunc(obuf);
         if (ferror(obuf)) {          if (ferror(obuf)) {
                 perror(mbox);                  warn(mbox);
                 Fclose(obuf);                  (void)Fclose(obuf);
                 Fclose(fbuf);                  (void)Fclose(fbuf);
                 spool_unlock();                  spool_unlock();
                 return;                  return;
         }          }
         Fclose(obuf);          (void)Fclose(obuf);
         if (mcount == 1)          if (mcount == 1)
                 printf("Saved 1 message in mbox\n");                  puts("Saved 1 message in mbox");
         else          else
                 printf("Saved %d messages in mbox\n", mcount);                  printf("Saved %d messages in mbox\n", mcount);
   
Line 313 
Line 313 
   
         if (p != 0) {          if (p != 0) {
                 writeback(rbuf);                  writeback(rbuf);
                 Fclose(fbuf);                  (void)Fclose(fbuf);
                 spool_unlock();                  spool_unlock();
                 return;                  return;
         }          }
Line 330 
Line 330 
                         goto newmail;                          goto newmail;
                 while ((c = getc(rbuf)) != EOF)                  while ((c = getc(rbuf)) != EOF)
                         (void) putc(c, abuf);                          (void) putc(c, abuf);
                 Fclose(rbuf);                  (void)Fclose(rbuf);
                 trunc(abuf);                  trunc(abuf);
                 Fclose(abuf);                  (void)Fclose(abuf);
                 alter(mailname);                  alter(mailname);
                 Fclose(fbuf);                  (void)Fclose(fbuf);
                 spool_unlock();                  spool_unlock();
                 return;                  return;
         }          }
         demail();          demail();
         Fclose(fbuf);          (void)Fclose(fbuf);
         spool_unlock();          spool_unlock();
         return;          return;
   
 newmail:  newmail:
         printf("Thou hast new mail.\n");          puts("Thou hast new mail.");
         if (fbuf != NULL) {          if (fbuf != NULL) {
                 Fclose(fbuf);                  (void)Fclose(fbuf);
                 spool_unlock();                  spool_unlock();
         }          }
 }  }
Line 367 
Line 367 
   
         p = 0;          p = 0;
         if ((obuf = Fopen(mailname, "r+")) == NULL) {          if ((obuf = Fopen(mailname, "r+")) == NULL) {
                 perror(mailname);                  warn(mailname);
                 return(-1);                  return(-1);
         }          }
 #ifndef APPEND  #ifndef APPEND
Line 379 
Line 379 
                 if ((mp->m_flag&MPRESERVE)||(mp->m_flag&MTOUCH)==0) {                  if ((mp->m_flag&MPRESERVE)||(mp->m_flag&MTOUCH)==0) {
                         p++;                          p++;
                         if (send(mp, obuf, (struct ignoretab *)0, NOSTR) < 0) {                          if (send(mp, obuf, (struct ignoretab *)0, NOSTR) < 0) {
                                 perror(mailname);                                  warn(mailname);
                                 Fclose(obuf);                                  (void)Fclose(obuf);
                                 return(-1);                                  return(-1);
                         }                          }
                 }                  }
Line 392 
Line 392 
         fflush(obuf);          fflush(obuf);
         trunc(obuf);          trunc(obuf);
         if (ferror(obuf)) {          if (ferror(obuf)) {
                 perror(mailname);                  warn(mailname);
                 Fclose(obuf);                  (void)Fclose(obuf);
                 return(-1);                  return(-1);
         }          }
         if (res != NULL)          if (res != NULL)
                 Fclose(res);                  (void)Fclose(res);
         Fclose(obuf);          (void)Fclose(obuf);
         alter(mailname);          alter(mailname);
         if (p == 1)          if (p == 1)
                 printf("Held 1 message in %s\n", mailname);                  printf("Held 1 message in %s\n", mailname);
Line 443 
Line 443 
                 }                  }
         }          }
         if (Tflag != NOSTR)          if (Tflag != NOSTR)
                 Fclose(readstat);                  (void)Fclose(readstat);
         if (!gotcha || Tflag != NOSTR)          if (!gotcha || Tflag != NOSTR)
                 goto done;                  goto done;
         ibuf = NULL;          ibuf = NULL;
Line 454 
Line 454 
                     "mboxXXXXXXXXXX");                      "mboxXXXXXXXXXX");
                 if ((fd = mkstemp(tempname)) == -1 ||                  if ((fd = mkstemp(tempname)) == -1 ||
                     (obuf = Fdopen(fd, "w")) == NULL) {                      (obuf = Fdopen(fd, "w")) == NULL) {
                         perror(tempname);                          warn(tempname);
                         relsesigs();                          relsesigs();
                         reset(0);                          reset(0);
                 }                  }
                 if ((ibuf = Fopen(mailname, "r")) == NULL) {                  if ((ibuf = Fopen(mailname, "r")) == NULL) {
                         perror(mailname);                          warn(mailname);
                         Fclose(obuf);                          (void)Fclose(obuf);
                         rm(tempname);                          rm(tempname);
                         relsesigs();                          relsesigs();
                         reset(0);                          reset(0);
Line 468 
Line 468 
                 fseek(ibuf, (long)mailsize, 0);                  fseek(ibuf, (long)mailsize, 0);
                 while ((c = getc(ibuf)) != EOF)                  while ((c = getc(ibuf)) != EOF)
                         (void) putc(c, obuf);                          (void) putc(c, obuf);
                 Fclose(ibuf);                  (void)Fclose(ibuf);
                 Fclose(obuf);                  (void)Fclose(obuf);
                 if ((ibuf = Fopen(tempname, "r")) == NULL) {                  if ((ibuf = Fopen(tempname, "r")) == NULL) {
                         perror(tempname);                          warn(tempname);
                         rm(tempname);                          rm(tempname);
                         relsesigs();                          relsesigs();
                         reset(0);                          reset(0);
Line 481 
Line 481 
         printf("\"%s\" ", mailname);          printf("\"%s\" ", mailname);
         fflush(stdout);          fflush(stdout);
         if ((obuf = Fopen(mailname, "r+")) == NULL) {          if ((obuf = Fopen(mailname, "r+")) == NULL) {
                 perror(mailname);                  warn(mailname);
                 relsesigs();                  relsesigs();
                 reset(0);                  reset(0);
         }          }
Line 492 
Line 492 
                         continue;                          continue;
                 c++;                  c++;
                 if (send(mp, obuf, (struct ignoretab *) NULL, NOSTR) < 0) {                  if (send(mp, obuf, (struct ignoretab *) NULL, NOSTR) < 0) {
                         perror(mailname);                          warn(mailname);
                         relsesigs();                          relsesigs();
                         reset(0);                          reset(0);
                 }                  }
Line 501 
Line 501 
         if (ibuf != NULL) {          if (ibuf != NULL) {
                 while ((c = getc(ibuf)) != EOF)                  while ((c = getc(ibuf)) != EOF)
                         (void) putc(c, obuf);                          (void) putc(c, obuf);
                 Fclose(ibuf);                  (void)Fclose(ibuf);
         }          }
         fflush(obuf);          fflush(obuf);
         if (ferror(obuf)) {          if (ferror(obuf)) {
                 perror(mailname);                  warn(mailname);
                 relsesigs();                  relsesigs();
                 reset(0);                  reset(0);
         }          }
         Fclose(obuf);          (void)Fclose(obuf);
         if (gotcha) {          if (gotcha) {
                 rm(mailname);                  rm(mailname);
                 printf("removed\n");                  puts("removed");
         } else          } else
                 printf("complete\n");                  puts("complete");
         fflush(stdout);          fflush(stdout);
   
 done:  done:

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4