/* NetHack 3.6 unixunix.c $NHDT-Date: 1432512788 2015/05/25 00:13:08 $ $NHDT-Branch: master $:$NHDT-Revision: 1.22 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
+/*-Copyright (c) Kenneth Lorber, Kensington, Maryland, 2015. */
/* NetHack may be freely redistributed. See license for details. */
/* This file collects some Unix dependencies */
static struct stat buf;
-/* see whether we should throw away this xlock file */
+/* see whether we should throw away this xlock file;
+ if yes, close it, otherwise leave it open */
static int
veryold(fd)
int fd;
time_t date;
if (fstat(fd, &buf))
- return (0); /* cannot get status */
+ return 0; /* cannot get status */
#ifndef INSURANCE
- if (buf.st_size != sizeof(int))
- return (0); /* not an xlock file */
+ if (buf.st_size != sizeof (int))
+ return 0; /* not an xlock file */
#endif
#if defined(BSD) && !defined(POSIX_TYPES)
(void) time((long *) (&date));
if (date - buf.st_mtime < 3L * 24L * 60L * 60L) { /* recent */
int lockedpid; /* should be the same size as hackpid */
- if (read(fd, (genericptr_t) &lockedpid, sizeof(lockedpid))
- != sizeof(lockedpid))
+ if (read(fd, (genericptr_t) &lockedpid, sizeof lockedpid)
+ != sizeof lockedpid)
/* strange ... */
- return (0);
+ return 0;
/* From: Rick Adams <seismo!rick> */
/* This will work on 4.1cbsd, 4.2bsd and system 3? & 5. */
by more than one machine! -pem */
if (!(kill(lockedpid, 0) == -1 && errno == ESRCH))
#endif
- return (0);
+ return 0;
}
(void) close(fd);
- return (1);
+ return 1;
}
static int
}
set_levelfile_name(lock, 0);
if (unlink(fqname(lock, LEVELPREFIX, 0)))
- return (0); /* cannot remove it */
- return (1); /* success! */
+ return 0; /* cannot remove it */
+ return 1; /* success! */
}
void
error("Cannot open %s", fq_lock);
}
- if (veryold(fd) /* closes fd if true */
- && eraseoldlocks())
+ /* veryold() closes fd if true */
+ if (veryold(fd) && eraseoldlocks())
goto gotlock;
(void) close(fd);
} while (i < locknum);
error("Cannot open %s", fq_lock);
}
- if (veryold(fd) /* closes fd if true */ && eraseoldlocks())
+ /* veryold() closes fd if true */
+ if (veryold(fd) && eraseoldlocks())
goto gotlock;
(void) close(fd);
+ {
+ const char destroy_old_game_prompt[] =
+/*JP
+ "There is already a game in progress under your name. Destroy old game?";
+*/
+ "\82 \82È\82½\82Ì\96¼\91O\82Å\95s\90³\8fI\97¹\82µ\82½\83Q\81[\83\80\82ª\8ec\82Á\82Ä\82¢\82Ü\82·\81D\94j\8aü\82µ\82Ü\82·\82©\81H";
+
if (iflags.window_inited) {
-#if 0 /*JP*/
- c = yn("There is already a game in progress under your name. "
- "Destroy old game?");
-#else
- c = yn("\82 \82È\82½\82Ì\96¼\91O\82Å\95s\90³\8fI\97¹\82µ\82½\83Q\81[\83\80\82ª\8ec\82Á\82Ä\82¢\82Ü\82·\81D"
- "\94j\8aü\82µ\82Ü\82·\82©\81H");
-#endif
+ /* this is a candidate for paranoid_confirmation */
+ c = yn(destroy_old_game_prompt);
} else {
-#if 0 /*JP*/
- (void) printf(
- "\nThere is already a game in progress under your name.");
- (void) printf(" Destroy old game? [yn] ");
-#else
- (void) printf(
- "\n\82 \82È\82½\82Ì\96¼\91O\82Å\95s\90³\8fI\97¹\82µ\82½\83Q\81[\83\80\82ª\8ec\82Á\82Ä\82¢\82Ü\82·\81D");
- (void) printf("\94j\8aü\82µ\82Ü\82·\82©\81H[yn] ");
-#endif
+ (void) printf("\n%s [yn] ", destroy_old_game_prompt);
(void) fflush(stdout);
if ((c = getchar()) != EOF) {
int tmp;
; /* eat rest of line and newline */
}
}
+ }
if (c == 'y' || c == 'Y') {
- if (eraseoldlocks())
+ if (eraseoldlocks()) {
goto gotlock;
- else {
+ } else {
unlock_file(HLOCK);
error("Couldn't destroy old game.");
}
if (fd == -1) {
error("cannot creat lock file (%s).", fq_lock);
} else {
- if (write(fd, (genericptr_t) &hackpid, sizeof(hackpid))
- != sizeof(hackpid)) {
+ if (write(fd, (genericptr_t) &hackpid, sizeof hackpid)
+ != sizeof hackpid) {
error("cannot write lock (%s)", fq_lock);
}
if (close(fd) == -1) {
}
}
-void regularize(s) /* normalize file name - we don't like .'s, /'s, spaces */
+/* normalize file name - we don't like .'s, /'s, spaces */
+void
+regularize(s)
register char *s;
{
register char *lp;
- while ((lp = index(s, '.')) || (lp = index(s, '/'))
- || (lp = index(s, ' ')))
+ while ((lp = index(s, '.')) != 0 || (lp = index(s, '/')) != 0
+ || (lp = index(s, ' ')) != 0)
*lp = '_';
#if defined(SYSV) && !defined(AIX_31) && !defined(SVR4) && !defined(LINUX) \
&& !defined(__APPLE__)
int
dosh()
{
- register char *str;
+ char *str;
+
#ifdef SYSCF
if (!sysopt.shellers || !sysopt.shellers[0]
|| !check_user_string(sysopt.shellers)) {
+ /* FIXME: should no longer assume a particular command keystroke,
+ and perhaps ought to say "unavailable" rather than "unknown" */
Norep("Unknown command '!'.");
return 0;
}
int wt;
{
register int f;
+
suspend_nhwindows((char *) 0); /* also calls end_screen() */
#ifdef _M_UNIX
sco_mapon();
linux_mapon();
#endif
if ((f = fork()) == 0) { /* child */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-result"
(void) setgid(getgid());
(void) setuid(getuid());
#ifdef CHDIR
(void) chdir(getenv("HOME"));
#endif
- return (1);
+#pragma GCC diagnostic pop
+ return 1;
}
if (f == -1) { /* cannot fork */
pline("Fork failed. Try again.");
- return (0);
+ return 0;
}
-/* fork succeeded; wait for child to exit */
+ /* fork succeeded; wait for child to exit */
#ifndef NO_SIGNAL
(void) signal(SIGINT, SIG_IGN);
(void) signal(SIGQUIT, SIG_IGN);
wait_synch();
}
resume_nhwindows();
- return (0);
+ return 0;
}
-#endif
+#endif /* SHELL || DEF_PAGER || DEF_MAILREADER */
#ifdef GETRES_SUPPORT
extern gid_t NDECL(nh_getgid);
extern gid_t NDECL(nh_getegid);
-int(getresuid)(ruid, euid, suid)
+/* the following several functions assume __STDC__ where parentheses
+ around the name of a function-like macro prevent macro expansion */
+
+int (getresuid)(ruid, euid, suid)
uid_t *ruid, *euid, *suid;
{
return nh_getresuid(ruid, euid, suid);
}
-uid_t(getuid)()
+uid_t (getuid)()
{
return nh_getuid();
}
-uid_t(geteuid)()
+uid_t (geteuid)()
{
return nh_geteuid();
}
-int(getresgid)(rgid, egid, sgid)
+int (getresgid)(rgid, egid, sgid)
gid_t *rgid, *egid, *sgid;
{
return nh_getresgid(rgid, egid, sgid);
}
-gid_t(getgid)()
+gid_t (getgid)()
{
return nh_getgid();
}
-gid_t(getegid)()
+gid_t (getegid)()
{
return nh_getegid();
}
/* XXX should be ifdef PANICTRACE_GDB, but there's no such symbol yet */
#ifdef PANICTRACE
boolean
-file_exists(const char *path)
+file_exists(path)
+const char *path;
{
+ struct stat sb;
+
/* Just see if it's there - trying to figure out if we can actually
* execute it in all cases is too hard - we really just want to
- * catch typos in SYSCF. */
- struct stat sb;
+ * catch typos in SYSCF.
+ */
if (stat(path, &sb)) {
return FALSE;
}