6 char index[] = "/sys/games/lib/fortunes.index";
7 char fortunes[] = "/sys/games/lib/fortunes";
10 main(int argc, char *argv[])
16 int newindex, oldindex;
24 if((f=Bopen(argc>1?argv[1]:fortunes, OREAD)) == 0){
25 print("Misfortune!\n");
30 ix = open(index, OREAD);
33 fbuf = dirfstat(Bfildes(f));
34 if(ixbuf == nil || fbuf == nil){
35 print("Misfortune?\n");
38 if(ixbuf->length == 0){
39 /* someone else is rewriting the index */
43 if(fbuf->mtime > ixbuf->mtime){
44 nix = create(index, OWRITE, 0666);
53 ix = create(index, OWRITE, 0666);
59 seek(ix, truerand()%(ixbuf->length/sizeof(offs))*sizeof(offs), 0);
60 read(ix, off, sizeof(off));
61 Bseek(f, off[0]|(off[1]<<8)|(off[2]<<16)|(off[3]<<24), 0);
67 strcpy(choice, "Misfortune!");
84 Bwrite(&g, off, sizeof(off));
90 print("%s\n", choice);