-/* $NetBSD: sync.c,v 1.23 2004/09/07 13:20:39 jrf Exp $ */
+/* $NetBSD: sync.c,v 1.28 2009/03/14 19:35:13 dholland Exp $ */
/*
* Copyright (c) 1983, 1993
#if 0
static char sccsid[] = "@(#)sync.c 8.2 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: sync.c,v 1.23 2004/09/07 13:20:39 jrf Exp $");
+__RCSID("$NetBSD: sync.c,v 1.28 2009/03/14 19:35:13 dholland Exp $");
#endif
#endif /* not lint */
#define BUFSIZE 4096
-static int sync_update(int, struct ship *, const char *, long, long, long, long);
+static int sync_update(int, struct ship *, const char *,
+ long, long, long, long);
static const char SF[] = _PATH_SYNC;
static const char LF[] = _PATH_LOCK;
va_start(ap, ship);
fmtship(format, sizeof(format), fmt, ship);
- vsprintf(message, format, ap);
+ vsnprintf(message, sizeof(message), format, ap);
va_end(ap);
Writestr(W_SIGNAL, from, message);
}
va_list ap;
va_start(ap, fmt);
- vsprintf(message, fmt, ap);
+ vsnprintf(message, sizeof(message), fmt, ap);
va_end(ap);
Writestr(W_SIGNAL, from, message);
}
int
-sync_exists(int game)
+sync_exists(int gamenum)
{
char buf[sizeof sync_file];
struct stat s;
time_t t;
- sprintf(buf, SF, game);
+ snprintf(buf, sizeof(buf), SF, gamenum);
time(&t);
setegid(egid);
if (stat(buf, &s) < 0) {
}
if (s.st_mtime < t - 60*60*2) { /* 2 hours */
unlink(buf);
- sprintf(buf, LF, game);
+ snprintf(buf, sizeof(buf), LF, gamenum);
unlink(buf);
setegid(gid);
return 0;
struct stat tmp;
if (sync_fp != NULL)
fclose(sync_fp);
- sprintf(sync_lock, LF, game);
- sprintf(sync_file, SF, game);
+ snprintf(sync_lock, sizeof(sync_lock), LF, game);
+ snprintf(sync_file, sizeof(sync_file), SF, game);
setegid(egid);
if (stat(sync_file, &tmp) < 0) {
mode_t omask = umask(002);
}
void
-sync_close(int remove)
+sync_close(int doremove)
{
if (sync_fp != 0)
fclose(sync_fp);
- if (remove) {
+ if (doremove) {
setegid(egid);
unlink(sync_file);
setegid(gid);
void
Write(int type, struct ship *ship, long a, long b, long c, long d)
{
+ size_t max = sizeof(sync_buf) - (sync_bp - sync_buf);
- sprintf(sync_bp, "%d %d 0 %ld %ld %ld %ld\n",
+ snprintf(sync_bp, max, "%d %d 0 %ld %ld %ld %ld\n",
type, ship->file->index, a, b, c, d);
while (*sync_bp++)
;
void
Writestr(int type, struct ship *ship, const char *a)
{
- sprintf(sync_bp, "%d %d 1 %s\n", type, ship->file->index, a);
+ size_t max = sizeof(sync_buf) - (sync_bp - sync_buf);
+
+ snprintf(sync_bp, max, "%d %d 1 %s\n", type, ship->file->index, a);
while (*sync_bp++)
;
sync_bp--;
if (isstr != 0 && isstr != 1)
goto bad;
if (isstr) {
+ int ch;
char *p;
+
for (p = buf;;) {
- switch (*p++ = getc(sync_fp)) {
+ ch = getc(sync_fp);
+ *p++ = ch;
+ switch (ch) {
case '\n':
p--;
case EOF:
astr = p;
a = b = c = d = 0;
} else {
- if (fscanf(sync_fp, "%ld%ld%ld%ld", &a, &b, &c, &d) != 4)
+ if (fscanf(sync_fp, "%ld%ld%ld%ld", &a, &b, &c, &d)
+ != 4)
goto bad;
astr = NULL;
}
}
static int
-sync_update(int type, struct ship *ship, const char *astr, long a, long b, long c, long d)
+sync_update(int type, struct ship *ship, const char *astr,
+ long a, long b, long c, long d)
{
switch (type) {
case W_DBP: {