BSD 4_3 development
[unix-history] / usr / contrib / rn / last.c
CommitLineData
9c4b96b4
C
1/* $Header: last.c,v 4.3 85/05/01 11:42:16 lwall Exp $
2 *
3 * $Log: last.c,v $
4 * Revision 4.3 85/05/01 11:42:16 lwall
5 * Baseline for release with 4.3bsd.
6 *
7 */
8
9#include "EXTERN.h"
10#include "common.h"
11#include "rn.h"
12#include "util.h"
13#include "intrp.h"
14#include "INTERN.h"
15#include "last.h"
16
17char *lastname = Nullch; /* path name of .rnlast file */
18
19void
20last_init(tcbuf)
21char *tcbuf;
22{
23 lastname = savestr(filexp(LASTNAME));
24 if ((tmpfp = fopen(lastname,"r")) != Nullfp) {
25 fgets(tcbuf,1024,tmpfp);
26 tcbuf[strlen(tcbuf)-1] = '\0';
27 lastngname = savestr(tcbuf);
28 fgets(tcbuf,1024,tmpfp);
29 lasttime = atol(tcbuf);
30 fgets(tcbuf,1024,tmpfp);
31 lastactsiz = atol(tcbuf);
32 fclose(tmpfp);
33 }
34 else {
35 lastngname = nullstr;
36 lasttime = 0;
37 lastactsiz = 0;
38 }
39}
40
41/* put out certain values for next run of rn */
42
43void
44writelast()
45{
46 if ((tmpfp = fopen(lastname,"w")) != Nullfp) {
47 fprintf(tmpfp,"%s\n%ld\n%ld\n",ngname,(long)lasttime,(long)lastactsiz);
48 fclose(tmpfp);
49 }
50 else
51 printf(cantcreate,lastname) FLUSH;
52}