[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.1 and 1.2

version 1.1, 1995/10/18 08:45:39 version 1.2, 1996/06/11 12:53:48
Line 1 
Line 1 
   /*      $OpenBSD$       */
   /*      $NetBSD: quit.c,v 1.5 1996/06/08 19:48:37 christos Exp $        */
   
 /*  /*
  * Copyright (c) 1980, 1993   * Copyright (c) 1980, 1993
  *      The Regents of the University of California.  All rights reserved.   *      The Regents of the University of California.  All rights reserved.
Line 32 
Line 35 
  */   */
   
 #ifndef lint  #ifndef lint
 static char sccsid[] = "from: @(#)quit.c        8.1 (Berkeley) 6/6/93";  #if 0
 static char rcsid[] = "$Id$";  static char sccsid[] = "@(#)quit.c      8.1 (Berkeley) 6/6/93";
   #else
   static char rcsid[] = "$OpenBSD$";
   #endif
 #endif /* not lint */  #endif /* not lint */
   
 #include "rcv.h"  #include "rcv.h"
Line 50 
Line 56 
  * The "quit" command.   * The "quit" command.
  */   */
 int  int
 quitcmd()  quitcmd(v)
           void *v;
 {  {
         /*          /*
          * If we are sourcing, then return 1 so execute() can handle it.           * If we are sourcing, then return 1 so execute() can handle it.
Line 70 
Line 77 
 quit()  quit()
 {  {
         int mcount, p, modify, autohold, anystat, holdbit, nohold;          int mcount, p, modify, autohold, anystat, holdbit, nohold;
         FILE *ibuf, *obuf, *fbuf, *rbuf, *readstat, *abuf;          FILE *ibuf = NULL, *obuf, *fbuf, *rbuf, *readstat = NULL, *abuf;
         register struct message *mp;          register struct message *mp;
         register int c;          register int c;
         extern char *tempQuit, *tempResid;          extern char *tempQuit, *tempResid;
Line 105 
Line 112 
         fbuf = Fopen(mailname, "r");          fbuf = Fopen(mailname, "r");
         if (fbuf == NULL)          if (fbuf == NULL)
                 goto newmail;                  goto newmail;
         flock(fileno(fbuf), LOCK_EX);          if (flock(fileno(fbuf), LOCK_EX) == -1) {
   nolock:
                   perror("Unable to lock mailbox");
                   Fclose(fbuf);
                   return;
           }
           if (dot_lock(mailname, 1, stdout, ".") == -1)
                   goto nolock;
         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");                  printf("New mail has arrived.\n");
Line 178 
Line 192 
                 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);                  Fclose(fbuf);
                   dot_unlock(mailname);
                 return;                  return;
         }          }
         if (c == 0) {          if (c == 0) {
                 if (p != 0) {                  if (p != 0) {
                         writeback(rbuf);                          writeback(rbuf);
                         Fclose(fbuf);                          Fclose(fbuf);
                           dot_unlock(mailname);
                         return;                          return;
                 }                  }
                 goto cream;                  goto cream;
Line 202 
Line 218 
                 if ((obuf = Fopen(tempQuit, "w")) == NULL) {                  if ((obuf = Fopen(tempQuit, "w")) == NULL) {
                         perror(tempQuit);                          perror(tempQuit);
                         Fclose(fbuf);                          Fclose(fbuf);
                           dot_unlock(mailname);
                         return;                          return;
                 }                  }
                 if ((ibuf = Fopen(tempQuit, "r")) == NULL) {                  if ((ibuf = Fopen(tempQuit, "r")) == NULL) {
Line 209 
Line 226 
                         rm(tempQuit);                          rm(tempQuit);
                         Fclose(obuf);                          Fclose(obuf);
                         Fclose(fbuf);                          Fclose(fbuf);
                           dot_unlock(mailname);
                         return;                          return;
                 }                  }
                 rm(tempQuit);                  rm(tempQuit);
Line 222 
Line 240 
                         Fclose(ibuf);                          Fclose(ibuf);
                         Fclose(obuf);                          Fclose(obuf);
                         Fclose(fbuf);                          Fclose(fbuf);
                           dot_unlock(mailname);
                         return;                          return;
                 }                  }
                 Fclose(obuf);                  Fclose(obuf);
Line 230 
Line 249 
                         perror(mbox);                          perror(mbox);
                         Fclose(ibuf);                          Fclose(ibuf);
                         Fclose(fbuf);                          Fclose(fbuf);
                           dot_unlock(mailname);
                         return;                          return;
                 }                  }
         }          }
         if (value("append") != NOSTR) {          else {
                 if ((obuf = Fopen(mbox, "a")) == NULL) {                  if ((obuf = Fopen(mbox, "a")) == NULL) {
                         perror(mbox);                          perror(mbox);
                         Fclose(fbuf);                          Fclose(fbuf);
                           dot_unlock(mailname);
                         return;                          return;
                 }                  }
                 fchmod(fileno(obuf), 0600);                  fchmod(fileno(obuf), 0600);
Line 248 
Line 269 
                                 Fclose(ibuf);                                  Fclose(ibuf);
                                 Fclose(obuf);                                  Fclose(obuf);
                                 Fclose(fbuf);                                  Fclose(fbuf);
                                   dot_unlock(mailname);
                                 return;                                  return;
                         }                          }
   
Line 274 
Line 296 
                 perror(mbox);                  perror(mbox);
                 Fclose(obuf);                  Fclose(obuf);
                 Fclose(fbuf);                  Fclose(fbuf);
                   dot_unlock(mailname);
                 return;                  return;
         }          }
         Fclose(obuf);          Fclose(obuf);
Line 290 
Line 313 
         if (p != 0) {          if (p != 0) {
                 writeback(rbuf);                  writeback(rbuf);
                 Fclose(fbuf);                  Fclose(fbuf);
                   dot_unlock(mailname);
                 return;                  return;
         }          }
   
Line 310 
Line 334 
                 Fclose(abuf);                  Fclose(abuf);
                 alter(mailname);                  alter(mailname);
                 Fclose(fbuf);                  Fclose(fbuf);
                   dot_unlock(mailname);
                 return;                  return;
         }          }
         demail();          demail();
         Fclose(fbuf);          Fclose(fbuf);
           dot_unlock(mailname);
         return;          return;
   
 newmail:  newmail:
         printf("Thou hast new mail.\n");          printf("Thou hast new mail.\n");
         if (fbuf != NULL)          if (fbuf != NULL) {
                 Fclose(fbuf);                  Fclose(fbuf);
                   dot_unlock(mailname);
           }
 }  }
   
 /*  /*
Line 388 
Line 416 
         extern char *tmpdir;          extern char *tmpdir;
         register int gotcha, c;          register int gotcha, c;
         register struct message *mp;          register struct message *mp;
         FILE *obuf, *ibuf, *readstat;          FILE *obuf, *ibuf, *readstat = NULL;
         struct stat statb;          struct stat statb;
         char *tempname;          char *tempname;
   

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2