home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume23 / trn / part14 / last.c < prev    next >
C/C++ Source or Header  |  1991-08-22  |  1KB  |  62 lines

  1. /* $Header: last.c,v 4.3.3.1 91/01/16 02:47:15 davison Trn $
  2.  *
  3.  * $Log:    last.c,v $
  4.  * Revision 4.3.3.1  91/01/16  02:47:15  davison
  5.  * Integrated rn patches 48-54.
  6.  * 
  7.  * Revision 4.3.2.1  89/12/20  23:23:07  sob
  8.  * .rnlast sometimes is a null file. This gives bogus information when
  9.  * restarting rn following an abnormal termination. This bug was reported
  10.  * by weening@gang-of-four.stanford.edu
  11.  * 
  12.  * Revision 4.3  85/05/01  11:42:16  lwall
  13.  * Baseline for release with 4.3bsd.
  14.  * 
  15.  */
  16.  
  17. #include "EXTERN.h"
  18. #include "common.h"
  19. #include "rn.h"
  20. #include "util.h"
  21. #include "intrp.h"
  22. #include "INTERN.h"
  23. #include "last.h"
  24.  
  25. char *lastname = Nullch;    /* path name of .rnlast file */
  26.  
  27. void
  28. last_init(tcbuf)
  29. char *tcbuf;
  30. {
  31.     lastname = savestr(filexp(LASTNAME));
  32.     if ((tmpfp = fopen(lastname,"r")) != Nullfp &&
  33.     fgets(tcbuf,1024,tmpfp) != Nullch) {
  34.     tcbuf[strlen(tcbuf)-1] = '\0';
  35.     lastngname = savestr(tcbuf);
  36.     fgets(tcbuf,1024,tmpfp);
  37.     lasttime = atol(tcbuf);
  38.     fgets(tcbuf,1024,tmpfp);
  39.     lastactsiz = atol(tcbuf);
  40.     fclose(tmpfp);
  41.     }
  42.     else {
  43.     lastngname = nullstr;
  44.     lasttime = 0;
  45.     lastactsiz = 0;
  46.     }
  47. }
  48.  
  49. /* put out certain values for next run of rn */
  50.  
  51. void
  52. writelast()
  53. {
  54.     if ((tmpfp = fopen(lastname,"w")) != Nullfp) {
  55.     fprintf(tmpfp,"%s\n%ld\n%ld\n",
  56.         (ngname==Nullch?nullstr:ngname),(long)lasttime,(long)lastactsiz);
  57.     fclose(tmpfp);
  58.     }
  59.     else
  60.     printf(cantcreate,lastname) FLUSH;
  61. }
  62.