-/* $NetBSD: hack.main.c,v 1.4 1997/10/19 16:58:11 christos Exp $ */
+/* $NetBSD: hack.main.c,v 1.7 2002/05/26 00:12:12 wiz Exp $ */
/*
* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: hack.main.c,v 1.4 1997/10/19 16:58:11 christos Exp $");
+__RCSID("$NetBSD: hack.main.c,v 1.7 2002/05/26 00:12:12 wiz Exp $");
#endif /* not lint */
#include <signal.h>
int (*afternmv) __P((void));
int (*occupation) __P((void));
-char *occtxt; /* defined when occupation != NULL */
+const char *occtxt; /* defined when occupation != NULL */
int hackpid; /* current pid */
int locknum; /* max num of players */
#ifdef DEF_PAGER
-char *catmore; /* default pager */
+const char *catmore; /* default pager */
#endif
char SAVEF[PL_NSIZ + 11] = "save/"; /* save/99999player */
char *hname; /* name of the game (argv[0] of call) */
char obuf[BUFSIZ]; /* BUFSIZ is defined in stdio.h */
int main __P((int, char *[]));
-static void chdirx __P((char *, boolean));
+static void chdirx __P((const char *, boolean));
int
main(argc, argv)
char *dir;
#endif
+ /* Check for dirty tricks with closed fds 0, 1, 2 */
+ fd = open("/dev/null", O_RDONLY);
+ if (fd < 3)
+ exit(1);
+ close(fd);
+
hname = argv[0];
hackpid = getpid();
locknum = MAX_NR_OF_PLAYERS;
#endif
#ifdef DEF_PAGER
- if (!(catmore = getenv("HACKPAGER")) && !(catmore = getenv("PAGER")))
+ if (((catmore = getenv("HACKPAGER")) == NULL &&
+ (catmore = getenv("PAGER")) == NULL) ||
+ catmore[0] == '\0')
catmore = DEF_PAGER;
#endif
#ifdef MAIL
}
if ((sfoo = getenv("GENOCIDED")) != NULL) {
if (*sfoo == '!') {
- struct permonst *pm = mons;
+ const struct permonst *pm = mons;
char *gp = genocided;
while (pm < mons + CMNUM + 2) {
setftty();
(void) sprintf(SAVEF, "save/%d%s", getuid(), plname);
regularize(SAVEF + 5); /* avoid . or / in name */
- if ((fd = open(SAVEF, 0)) >= 0 &&
+ if ((fd = open(SAVEF, O_RDONLY)) >= 0 &&
(uptodate(fd) || unlink(SAVEF) == 666)) {
(void) signal(SIGINT, done1);
pline("Restoring old save file...");
/* VARARGS1 */
void
-#ifdef __STDC__
impossible(const char *s, ...)
-#else
-impossible(va_alist)
- va_dcl
-#endif
{
va_list ap;
-#ifndef __STDC__
- const char *s;
- va_start(ap);
- s = va_arg(ap, const char *);
-#else
va_start(ap, s);
-#endif
vpline(s, ap);
va_end(ap);
pline("Program in disorder - perhaps you'd better Quit.");
#ifdef CHDIR
static void
chdirx(dir, wr)
- char *dir;
+ const char *dir;
boolean wr;
{
if (dir == NULL)
dir = ".";
- if ((fd = open(RECORD, 2)) < 0) {
+ if ((fd = open(RECORD, O_RDWR)) < 0) {
printf("Warning: cannot write %s/%s", dir, RECORD);
getret();
} else