=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mail/quit.c,v retrieving revision 1.14 retrieving revision 1.15 diff -c -r1.14 -r1.15 *** src/usr.bin/mail/quit.c 2001/01/16 05:36:09 1.14 --- src/usr.bin/mail/quit.c 2001/11/20 20:50:00 1.15 *************** *** 1,4 **** ! /* $OpenBSD: quit.c,v 1.14 2001/01/16 05:36:09 millert Exp $ */ /* $NetBSD: quit.c,v 1.6 1996/12/28 07:11:07 tls Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: quit.c,v 1.15 2001/11/20 20:50:00 millert Exp $ */ /* $NetBSD: quit.c,v 1.6 1996/12/28 07:11:07 tls Exp $ */ /* *************** *** 38,44 **** #if 0 static char sccsid[] = "@(#)quit.c 8.2 (Berkeley) 4/28/95"; #else ! static char rcsid[] = "$OpenBSD: quit.c,v 1.14 2001/01/16 05:36:09 millert Exp $"; #endif #endif /* not lint */ --- 38,44 ---- #if 0 static char sccsid[] = "@(#)quit.c 8.2 (Berkeley) 4/28/95"; #else ! static char rcsid[] = "$OpenBSD: quit.c,v 1.15 2001/11/20 20:50:00 millert Exp $"; #endif #endif /* not lint */ *************** *** 73,79 **** * Save all untouched messages back in the system mailbox. * Remove the system mailbox, if none saved there. */ ! void quit() { int mcount, p, modify, autohold, anystat, holdbit, nohold; --- 73,79 ---- * Save all untouched messages back in the system mailbox. * Remove the system mailbox, if none saved there. */ ! int quit() { int mcount, p, modify, autohold, anystat, holdbit, nohold; *************** *** 88,102 **** * so just return quickly. */ if (readonly) ! return; /* * If editing (not reading system mail box), then do the work * in edstop() */ ! if (edit) { ! edstop(); ! return; ! } /* * See if there any messages to save in mbox. If no, we --- 88,100 ---- * so just return quickly. */ if (readonly) ! return(0); /* * If editing (not reading system mail box), then do the work * in edstop() */ ! if (edit) ! return(edstop()); /* * See if there any messages to save in mbox. If no, we *************** *** 114,124 **** if (flock(fileno(fbuf), LOCK_EX) == -1) { warn("Unable to lock mailbox"); (void)Fclose(fbuf); ! return; } if (!spool_lock()) { (void)Fclose(fbuf); ! return; /* lockspool printed error for us */ } rbuf = NULL; if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) { --- 112,122 ---- if (flock(fileno(fbuf), LOCK_EX) == -1) { warn("Unable to lock mailbox"); (void)Fclose(fbuf); ! return(-1); } if (!spool_lock()) { (void)Fclose(fbuf); ! return(-1); /* lockspool printed error for us */ } rbuf = NULL; if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) { *************** *** 195,208 **** p, p == 1 ? "" : "s", mailname); (void)Fclose(fbuf); spool_unlock(); ! return; } if (c == 0) { if (p != 0) { writeback(rbuf); (void)Fclose(fbuf); spool_unlock(); ! return; } goto cream; } --- 193,206 ---- p, p == 1 ? "" : "s", mailname); (void)Fclose(fbuf); spool_unlock(); ! return(0); } if (c == 0) { if (p != 0) { writeback(rbuf); (void)Fclose(fbuf); spool_unlock(); ! return(0); } goto cream; } *************** *** 224,230 **** warn("%s", tempname); (void)Fclose(fbuf); spool_unlock(); ! return; } if ((ibuf = Fopen(tempname, "r")) == NULL) { warn("%s", tempname); --- 222,228 ---- warn("%s", tempname); (void)Fclose(fbuf); spool_unlock(); ! return(-1); } if ((ibuf = Fopen(tempname, "r")) == NULL) { warn("%s", tempname); *************** *** 232,238 **** (void)Fclose(obuf); (void)Fclose(fbuf); spool_unlock(); ! return; } (void)rm(tempname); if ((abuf = Fopen(mbox, "r")) != NULL) { --- 230,236 ---- (void)Fclose(obuf); (void)Fclose(fbuf); spool_unlock(); ! return(-1); } (void)rm(tempname); if ((abuf = Fopen(mbox, "r")) != NULL) { *************** *** 246,252 **** (void)Fclose(obuf); (void)Fclose(fbuf); spool_unlock(); ! return; } (void)Fclose(obuf); (void)close(creat(mbox, 0600)); --- 244,250 ---- (void)Fclose(obuf); (void)Fclose(fbuf); spool_unlock(); ! return(-1); } (void)Fclose(obuf); (void)close(creat(mbox, 0600)); *************** *** 255,269 **** (void)Fclose(ibuf); (void)Fclose(fbuf); spool_unlock(); ! return; } ! } ! else { if ((obuf = Fopen(mbox, "a")) == NULL) { warn("%s", mbox); (void)Fclose(fbuf); spool_unlock(); ! return; } fchmod(fileno(obuf), 0600); } --- 253,266 ---- (void)Fclose(ibuf); (void)Fclose(fbuf); spool_unlock(); ! return(-1); } ! } else { if ((obuf = Fopen(mbox, "a")) == NULL) { warn("%s", mbox); (void)Fclose(fbuf); spool_unlock(); ! return(-1); } fchmod(fileno(obuf), 0600); } *************** *** 275,281 **** (void)Fclose(obuf); (void)Fclose(fbuf); spool_unlock(); ! return; } /* --- 272,278 ---- (void)Fclose(obuf); (void)Fclose(fbuf); spool_unlock(); ! return(-1); } /* *************** *** 302,308 **** (void)Fclose(obuf); (void)Fclose(fbuf); spool_unlock(); ! return; } (void)Fclose(obuf); if (mcount == 1) --- 299,305 ---- (void)Fclose(obuf); (void)Fclose(fbuf); spool_unlock(); ! return(-1); } (void)Fclose(obuf); if (mcount == 1) *************** *** 319,325 **** writeback(rbuf); (void)Fclose(fbuf); spool_unlock(); ! return; } /* --- 316,322 ---- writeback(rbuf); (void)Fclose(fbuf); spool_unlock(); ! return(0); } /* *************** *** 340,351 **** alter(mailname); (void)Fclose(fbuf); spool_unlock(); ! return; } demail(); (void)Fclose(fbuf); spool_unlock(); ! return; newmail: puts("Thou hast new mail."); --- 337,348 ---- alter(mailname); (void)Fclose(fbuf); spool_unlock(); ! return(0); } demail(); (void)Fclose(fbuf); spool_unlock(); ! return(0);; newmail: puts("Thou hast new mail."); *************** *** 353,358 **** --- 350,356 ---- (void)Fclose(fbuf); spool_unlock(); } + return(0); } /* *************** *** 415,421 **** * Terminate an editing session by attempting to write out the user's * file from the temporary. Save any new stuff appended to the file. */ ! void edstop() { int gotcha, c; --- 413,419 ---- * Terminate an editing session by attempting to write out the user's * file from the temporary. Save any new stuff appended to the file. */ ! int edstop() { int gotcha, c; *************** *** 425,431 **** char tempname[PATHSIZE]; if (readonly) ! return; holdsigs(); if (Tflag != NULL) { if ((readstat = Fopen(Tflag, "w")) == NULL) --- 423,429 ---- char tempname[PATHSIZE]; if (readonly) ! return(0); holdsigs(); if (Tflag != NULL) { if ((readstat = Fopen(Tflag, "w")) == NULL) *************** *** 459,472 **** (obuf = Fdopen(fd, "w")) == NULL) { warn("%s", tempname); relsesigs(); ! reset(0); } if ((ibuf = Fopen(mailname, "r")) == NULL) { warn("%s", mailname); (void)Fclose(obuf); (void)rm(tempname); relsesigs(); ! reset(0); } fseek(ibuf, (long)mailsize, 0); while ((c = getc(ibuf)) != EOF) --- 457,470 ---- (obuf = Fdopen(fd, "w")) == NULL) { warn("%s", tempname); relsesigs(); ! return(-1); } if ((ibuf = Fopen(mailname, "r")) == NULL) { warn("%s", mailname); (void)Fclose(obuf); (void)rm(tempname); relsesigs(); ! return(-1); } fseek(ibuf, (long)mailsize, 0); while ((c = getc(ibuf)) != EOF) *************** *** 477,483 **** warn("%s", tempname); (void)rm(tempname); relsesigs(); ! reset(0); } (void)rm(tempname); } --- 475,481 ---- warn("%s", tempname); (void)rm(tempname); relsesigs(); ! return(-1); } (void)rm(tempname); } *************** *** 486,492 **** if ((obuf = Fopen(mailname, "r+")) == NULL) { warn("%s", mailname); relsesigs(); ! reset(0); } trunc(obuf); c = 0; --- 484,490 ---- if ((obuf = Fopen(mailname, "r+")) == NULL) { warn("%s", mailname); relsesigs(); ! return(-1); } trunc(obuf); c = 0; *************** *** 497,503 **** if (sendmessage(mp, obuf, NULL, NULL) < 0) { warn("%s", mailname); relsesigs(); ! reset(0); } } gotcha = (c == 0 && ibuf == NULL); --- 495,501 ---- if (sendmessage(mp, obuf, NULL, NULL) < 0) { warn("%s", mailname); relsesigs(); ! return(-1); } } gotcha = (c == 0 && ibuf == NULL); *************** *** 510,516 **** if (ferror(obuf)) { warn("%s", mailname); relsesigs(); ! reset(0); } (void)Fclose(obuf); if (gotcha) { --- 508,514 ---- if (ferror(obuf)) { warn("%s", mailname); relsesigs(); ! return(-1); } (void)Fclose(obuf); if (gotcha) { *************** *** 522,525 **** --- 520,524 ---- done: relsesigs(); + return(0); }