Annotation of researchv10no/games/trek/dump.c, revision 1.1.1.1

1.1       root        1: # include      "trek.h"
                      2: #include       "stat.h"
                      3: 
                      4: /**
                      5:  **    dump game for later restart
                      6:  **/
                      7: 
                      8: #define        CHECK   9
                      9: 
                     10: 
                     11: inode(f)
                     12: {      STATBUF         buf;
                     13: 
                     14:        fstat(f,&buf);
                     15:        return(buf.i_ino);
                     16: }
                     17: 
                     18: long Ftime(f)
                     19: {      STATBUF         buf;
                     20: 
                     21:        fstat(f,&buf);
                     22:        return(buf.i_mtime);
                     23: }
                     24: 
                     25: dumpgame()
                     26: {
                     27:        register int    f, len;
                     28:        int             check;
                     29:        long            t;
                     30:        int             n;
                     31: 
                     32:        if((f=creat("trek.dump",0664))<0) {
                     33:                printf("Cannot create 'trek.dump'\n");
                     34:                return;
                     35:        }
                     36: 
                     37:        check=CHECK; write(f,&check,2);
                     38:        len=sbrk(0); lseek(f,8L,0);
                     39:        if(write(f,0,len)!=len) {
                     40:                printf("Failed to write dump\n");
                     41:                return;
                     42:        }
                     43:        lseek(f,2L,0);
                     44:        n=inode(f); write(f,&n,2);
                     45:        time(&t); write(f,&t,4); close(f);
                     46:        exit(0);
                     47: }
                     48: 
                     49: restart()
                     50: {
                     51:        register int    f, len;
                     52:        int             check;
                     53:        char            chkpass[PWDLEN];
                     54:        long            t, tfile;
                     55:        int             n, nfile;
                     56: 
                     57:        if((f=open("trek.dump",0))<0) {
                     58:                printf("Cannot open 'trek.dump'\n");
                     59:                return(0);
                     60:        }
                     61: 
                     62:        read(f,&check,2);
                     63:        read(f,&n,2); read(f,&t,4);
                     64:        nfile=inode(f); tfile=Ftime(f);
                     65:        len=sbrk(0);
                     66:        if(check!=CHECK || read(f,0,len)!=len) {
                     67:                printf("Cannot restart\n");
                     68:                exit(1);
                     69:        }
                     70:        getpasswd(chkpass);
                     71:        if (cf(chkpass, Game.passwd)) {
                     72:                printf("Incorrect password\n");
                     73:                exit(1);
                     74:        }
                     75:        unlink("trek.dump");
                     76:        if(nfile!=n || tfile>t+2)
                     77:                lose(L_CHEAT);
                     78:        return(1);
                     79: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.