-/* $OpenBSD: hack.bones.c,v 1.11 2019/06/28 13:32:52 deraadt Exp $ */
+/* $OpenBSD: hack.bones.c,v 1.12 2023/06/03 15:19:38 op Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
int
getbones(void)
{
- int fd,x,y,ok;
+ int fd,x,y;
if(rn2(3)) return(0); /* only once in three times do we find bones */
bones[6] = '0' + dlevel/10;
bones[7] = '0' + dlevel%10;
if((fd = open(bones, O_RDONLY)) == -1) return(0);
- if((ok = uptodate(fd)) != 0){
- getlev(fd, 0, dlevel);
- for(x = 0; x < COLNO; x++) for(y = 0; y < ROWNO; y++)
- levl[x][y].seen = levl[x][y].new = 0;
- }
+ getlev(fd, 0, dlevel);
+ for(x = 0; x < COLNO; x++) for(y = 0; y < ROWNO; y++)
+ levl[x][y].seen = levl[x][y].new = 0;
(void) close(fd);
#ifdef WIZARD
if(!wizard) /* duvel!frans: don't remove bones while debugging */
pline("Cannot unlink %s .", bones);
return(0);
}
- return(ok);
+ return(1);
}
-/* $OpenBSD: hack.h,v 1.13 2016/01/09 18:33:15 mestre Exp $*/
+/* $OpenBSD: hack.h,v 1.14 2023/06/03 15:19:38 op Exp $*/
/* $NetBSD: hack.h,v 1.3 1995/03/23 08:30:21 cgd Exp $*/
/*
int night(void);
int midnight(void);
void gethdate(char *);
-int uptodate(int);
void getlock(void);
#ifdef MAIL
void getmailstatus(void);
-/* $OpenBSD: hack.main.c,v 1.24 2019/06/28 13:32:52 deraadt Exp $ */
+/* $OpenBSD: hack.main.c,v 1.25 2023/06/03 15:19:38 op Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
int
main(int argc, char **argv)
{
- extern char *__progname;
int fd;
#ifdef CHDIR
char *dir;
u.ux = FAR; /* prevent nscr() */
(void) signal(SIGHUP, hackhangup);
- /*
- * Find the creation date of this game,
- * so as to avoid restoring outdated savefiles.
- */
- gethdate(__progname);
-
- /*
- * We cannot do chdir earlier, otherwise gethdate will fail.
- */
#ifdef CHDIR
chdirx(dir,1);
#endif
setftty();
(void) snprintf(SAVEF, sizeof SAVEF, "save/%u%s", getuid(), plname);
regularize(SAVEF+5); /* avoid . or / in name */
- if((fd = open(SAVEF, O_RDONLY)) >= 0 &&
- (uptodate(fd) || unlink(SAVEF) == 666)) {
+ if((fd = open(SAVEF, O_RDONLY)) >= 0) {
(void) signal(SIGINT,done1);
pline("Restoring old save file...");
(void) fflush(stdout);
-/* $OpenBSD: hack.unix.c,v 1.21 2021/12/15 16:29:29 deraadt Exp $ */
+/* $OpenBSD: hack.unix.c,v 1.22 2023/06/03 15:19:38 op Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
return(getlt()->tm_hour == 0);
}
-struct stat buf, hbuf;
-
-void
-gethdate(char *name)
-{
- char *p, *np, *path;
- char filename[PATH_MAX];
-
- if (strchr(name, '/') != NULL || (p = getenv("PATH")) == NULL)
- p = "";
- np = path = strdup(p); /* Make a copy for strsep. */
- if (path == NULL)
- err(1, NULL);
-
- for (;;) {
- if ((p = strsep(&np, ":")) == NULL)
- break;
- if (*p == '\0') /* :: */
- (void) strlcpy(filename, name, sizeof filename);
- else
- (void) snprintf(filename, sizeof filename,
- "%s/%s", p, name);
-
- if (stat(filename, &hbuf) == 0) {
- free(path);
- return;
- }
- }
- error("Cannot get status of %s.",
- (p = strrchr(name, '/')) ? p+1 : name);
- free(path);
-}
-
-int
-uptodate(int fd)
-{
- if(fstat(fd, &buf)) {
- pline("Cannot get status of saved level? ");
- return(0);
- }
- if(buf.st_mtime < hbuf.st_mtime) {
- pline("Saved level is out of date. ");
- return(0);
- }
- return(1);
-}
+struct stat buf;
/* see whether we should throw away this xlock file */
static int