-/* $NetBSD: hack.unix.c,v 1.11 2009/06/07 18:30:39 dholland 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.11 2009/06/07 18:30:39 dholland 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(void)
(void) srandom((int) time((time_t *) 0));
}
-struct tm *
+static struct tm *
getlt(void)
{
time_t date;
char *
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);
}
return (getlt()->tm_hour == 0);
}
-struct stat buf, hbuf;
+static struct stat buf, hbuf;
void
gethdate(char *name)
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
+static int
veryold(int fd)
{
int i;
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);
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");
}
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 */