-/* $NetBSD: hack.unix.c,v 1.10 2009/05/06 02:59:12 ginsbach Exp $ */
+/* $NetBSD: hack.unix.c,v 1.18 2019/02/03 10:48:46 mrg Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: hack.unix.c,v 1.10 2009/05/06 02:59:12 ginsbach 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 *
-getdatestr()
+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;