-/* $NetBSD: hack.unix.c,v 1.8 2001/03/25 20:44:03 jsm Exp $ */
+/* $NetBSD: hack.unix.c,v 1.18 2019/02/03 10:48:46 mrg Exp $ */
/*
- * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
+ * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
+ * Amsterdam
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - Neither the name of the Stichting Centrum voor Wiskunde en
+ * Informatica, nor the names of its contributors may be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: hack.unix.c,v 1.8 2001/03/25 20:44:03 jsm Exp $");
+__RCSID("$NetBSD: hack.unix.c,v 1.18 2019/02/03 10:48:46 mrg Exp $");
#endif /* not lint */
/* This file collects some Unix dependencies; hack.pager.c contains some more */
extern int locknum;
+static struct tm *getlt(void);
+static int veryold(int);
+
void
-setrandom()
+setrandom(void)
{
(void) srandom((int) time((time_t *) 0));
}
-struct tm *
-getlt()
+static struct tm *
+getlt(void)
{
time_t date;
}
int
-getyear()
+getyear(void)
{
return (1900 + getlt()->tm_year);
}
char *
-getdate()
+getdatestr(void)
{
- static char datestr[7];
+ static char datestr[32];
struct tm *lt = getlt();
- (void) sprintf(datestr, "%02d%02d%02d",
+ (void) snprintf(datestr, sizeof(datestr), "%02d%02d%02d",
lt->tm_year % 100, lt->tm_mon + 1, lt->tm_mday);
return (datestr);
}
int
-phase_of_the_moon()
+phase_of_the_moon(void)
{ /* 0-7, with 0: new, 4: full *//* moon
* period: 29.5306 days */
/* year: 365.2422 days */
}
int
-night()
+night(void)
{
int hour = getlt()->tm_hour;
}
int
-midnight()
+midnight(void)
{
return (getlt()->tm_hour == 0);
}
-struct stat buf, hbuf;
+static struct stat buf, hbuf;
void
-gethdate(name)
- char *name;
+gethdate(char *name)
{
#if 0
/* old version - for people short of space */
if ((np = strchr(path, ':')) == NULL)
np = path + strlen(path); /* point to end str */
if (np - path <= 1) /* %% */
- (void) strcpy(filename, name);
+ (void) strlcpy(filename, name, sizeof(filename));
else {
- (void) strncpy(filename, path, np - path);
- filename[np - path] = '/';
- (void) strcpy(filename + (np - path) + 1, name);
+ (void) snprintf(filename, sizeof(filename),
+ "%.*s/%s",
+ (int)(np - path), path, name);
}
if (stat(filename, &hbuf) == 0)
return;
}
/* see whether we should throw away this xlock file */
-int
-veryold(fd)
- int fd;
+static int
+veryold(int fd)
{
int i;
time_t date;
int lockedpid; /* should be the same size as
* hackpid */
- if (read(fd, (char *) &lockedpid, sizeof(lockedpid)) !=
+ if (read(fd, &lockedpid, sizeof(lockedpid)) !=
sizeof(lockedpid))
/* strange ... */
return (0);
}
void
-getlock()
+getlock(void)
{
int i = 0, fd;
if (fd == -1) {
error("cannot creat lock file.");
} else {
- if (write(fd, (char *) &hackpid, sizeof(hackpid))
+ if (write(fd, &hackpid, sizeof(hackpid))
!= sizeof(hackpid)) {
error("cannot write lock");
}
static long laststattime;
void
-getmailstatus()
+getmailstatus(void)
{
if (!(mailbox = getenv("MAIL")))
return;
}
void
-ckmailstatus()
+ckmailstatus(void)
{
if (!mailbox
#ifdef MAILCKFREQ
}
void
-newmail()
+newmail(void)
{
/* produce a scroll of mail */
struct obj *obj;
/* make md run through the cave */
void
-mdrush(md, away)
- struct monst *md;
- boolean away;
+mdrush(struct monst *md, boolean away)
{
int uroom = inroom(u.ux, u.uy);
if (uroom >= 0) {
}
void
-readmail()
+readmail(void)
{
#ifdef DEF_MAILREADER /* This implies that UNIX is defined */
char *mr = 0;
if (!(mr = getenv("MAILREADER")))
mr = DEF_MAILREADER;
if (child(1)) {
- execl(mr, mr, (char *) 0);
+ execl(mr, mr, (char *)NULL);
exit(1);
}
#else /* DEF_MAILREADER */
}
#endif /* MAIL */
+/*
+ * normalize file name - we don't like ..'s or /'s
+ */
void
-regularize(s) /* normalize file name - we don't like ..'s
- * or /'s */
- char *s;
+regularize(char *s)
{
char *lp;