-/* $NetBSD: save.c,v 1.5 1997/05/23 23:09:43 jtc Exp $ */
+/* $NetBSD: save.c,v 1.12 2008/01/28 05:55:10 dholland Exp $ */
/*
* Copyright (c) 1983, 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.
*
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)save.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$NetBSD: save.c,v 1.5 1997/05/23 23:09:43 jtc Exp $";
+__RCSID("$NetBSD: save.c,v 1.12 2008/01/28 05:55:10 dholland Exp $");
#endif
#endif /* not lint */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <termios.h>
+#include <time.h>
+
#include "mille.h"
#ifndef unctrl
#include "unctrl.h"
#endif
-# ifdef attron
-# include <term.h>
-# endif attron
-
/*
* @(#)save.c 1.2 (Berkeley) 3/28/83
*/
typedef struct stat STAT;
-char *ctime();
-
-int read(), write();
-
/*
* This routine saves the current game for use at a later date
+ * Returns FALSE if it couldn't be done.
*/
-
-save() {
-
- extern int errno;
- register char *sp;
- register int outf;
- register time_t *tp;
- char buf[80];
- time_t tme;
- STAT junk;
-
+bool
+save()
+{
+ char *sp;
+ int outfd;
+ time_t *tp;
+ char buf[80];
+ time_t tme;
+ STAT junk;
+ bool rv;
+
+ sp = NULL;
tp = &tme;
if (Fromfile && getyn(SAMEFILEPROMPT))
strcpy(buf, Fromfile);
&& getyn(OVERWRITEFILEPROMPT) == FALSE))
return FALSE;
- if ((outf = creat(buf, 0644)) < 0) {
+ if ((outfd = creat(buf, 0644)) < 0) {
error(strerror(errno));
return FALSE;
}
mvwaddstr(Score, ERR_Y, ERR_X, buf);
wrefresh(Score);
time(tp); /* get current time */
- strcpy(buf, ctime(tp));
- for (sp = buf; *sp != '\n'; sp++)
- continue;
- *sp = '\0';
- varpush(outf, write);
- close(outf);
- wprintw(Score, " [%s]", buf);
+ rv = varpush(outfd, writev);
+ close(outfd);
+ if (rv == FALSE) {
+ unlink(buf);
+ } else {
+ strcpy(buf, ctime(tp));
+ for (sp = buf; *sp != '\n'; sp++)
+ continue;
+ *sp = '\0';
+ wprintw(Score, " [%s]", buf);
+ }
wclrtoeol(Score);
wrefresh(Score);
- return TRUE;
+ return rv;
}
/*
* backup was made on exiting, in which case certain things must
* be cleaned up before the game starts.
*/
+bool
rest_f(file)
-register char *file;
+ const char *file;
{
- register char *sp;
- register int inf;
- char buf[80];
- STAT sbuf;
+ char *sp;
+ int inf;
+ char buf[80];
+ STAT sbuf;
- if ((inf = open(file, 0)) < 0) {
- perror(file);
+ if ((inf = open(file, O_RDONLY)) < 0) {
+ warn("%s", file);
exit(1);
}
if (fstat(inf, &sbuf) < 0) { /* get file stats */
- perror(file);
+ warn("%s", file);
exit(1);
}
- varpush(inf, read);
+ varpush(inf, readv);
close(inf);
strcpy(buf, ctime(&sbuf.st_mtime));
for (sp = buf; *sp != '\n'; sp++)
Fromfile = file;
return !On_exit;
}
-