-/* $NetBSD: save.c,v 1.5 1997/10/10 08:59:48 lukem Exp $ */
+/* $NetBSD: save.c,v 1.16 2012/10/13 19:19:39 dholland Exp $ */
/*
* Copyright (c) 1980, 1993
* 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
#if 0
static char sccsid[] = "@(#)save.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: save.c,v 1.5 1997/10/10 08:59:48 lukem Exp $");
+__RCSID("$NetBSD: save.c,v 1.16 2012/10/13 19:19:39 dholland Exp $");
#endif
#endif /* not lint */
-#include "back.h"
+#include <errno.h>
-extern int errno;
+#include "back.h"
-static char confirm[] = "Are you sure you want to leave now?";
-static char prompt[] = "Enter a file name: ";
-static char exist1[] = "The file '";
-static char exist2[] =
+static const char confirm[] = "Are you sure you want to leave now?";
+static const char prompt[] = "Enter a file name: ";
+static const char exist1[] = "The file '";
+static const char exist2[] =
"' already exists.\nAre you sure you want to use this file?";
-static char cantuse[] = "\nCan't use ";
-static char saved[] = "This game has been saved on the file '";
-static char type[] = "'.\nType \"backgammon ";
-static char rec[] = "\" to recover your game.\n\n";
-static char cantrec[] = "Can't recover file: ";
+static const char cantuse[] = "\nCan't use ";
+static const char saved[] = "This game has been saved on the file '";
+static const char type[] = "'.\nType \"backgammon ";
+static const char rec[] = "\" to recover your game.\n\n";
+static const char cantrec[] = "Can't recover file: ";
+
+static void norec(const char *) __dead;
void
-save(n)
- int n;
+save(struct move *mm, int n)
{
int fdesc;
char *fs;
writec(*fs++);
}
*fs = '\0';
- if ((fdesc = open(fname, 2)) == -1 && errno == 2) {
- if ((fdesc = creat(fname, 0700)) != -1)
+ if ((fdesc = open(fname, O_RDWR)) == -1 && errno == ENOENT) {
+ if ((fdesc = creat(fname, 0600)) != -1)
break;
}
if (fdesc != -1) {
close(fdesc);
if (yorn(0)) {
unlink(fname);
- fdesc = creat(fname, 0700);
+ fdesc = creat(fname, 0600);
break;
} else {
cflag = 1;
writel(cantuse);
writel(fname);
writel(".\n");
- close(fdesc);
cflag = 1;
}
write(fdesc, board, sizeof board);
write(fdesc, off, sizeof off);
write(fdesc, in, sizeof in);
- write(fdesc, dice, sizeof dice);
+ write(fdesc, mm->dice, sizeof mm->dice);
write(fdesc, &cturn, sizeof cturn);
write(fdesc, &dlast, sizeof dlast);
write(fdesc, &pnum, sizeof pnum);
}
void
-recover(s)
- char *s;
+recover(struct move *mm, const char *s)
{
int fdesc;
- if ((fdesc = open(s, 0)) == -1)
+ if ((fdesc = open(s, O_RDONLY)) == -1)
norec(s);
read(fdesc, board, sizeof board);
read(fdesc, off, sizeof off);
read(fdesc, in, sizeof in);
- read(fdesc, dice, sizeof dice);
+ read(fdesc, mm->dice, sizeof mm->dice);
read(fdesc, &cturn, sizeof cturn);
read(fdesc, &dlast, sizeof dlast);
read(fdesc, &pnum, sizeof pnum);
rflag = 1;
}
-void
-norec(s)
- char *s;
+static void
+norec(const char *s)
{
- char *c;
+ const char *c;
tflag = 0;
writel(cantrec);