+/* $NetBSD: save.c,v 1.7 1999/03/29 05:12:39 mrg Exp $ */
+
/*
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
-static char sccsid[] = "@(#)save.c 5.6 (Berkeley) 6/1/90";
+#if 0
+static char sccsid[] = "@(#)save.c 8.1 (Berkeley) 5/31/93";
+#else
+__RCSID("$NetBSD: save.c,v 1.7 1999/03/29 05:12:39 mrg Exp $");
+#endif
#endif /* not lint */
-#include "mille.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <string.h>
+#include "mille.h"
+
#ifndef unctrl
-#include "unctrl.h"
+#include "unctrl.h"
#endif
-# ifdef attron
-# include <term.h>
-# define _tty cur_term->Nttyb
-# 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;
- reg char *sp;
- reg int outf;
- reg time_t *tp;
- char buf[80];
- time_t tme;
- STAT junk;
-
+bool
+save()
+{
+ char *sp;
+ int outf;
+ time_t *tp;
+ char buf[80];
+ time_t tme;
+ STAT junk;
+ bool rv;
+
+ sp = NULL;
tp = &tme;
if (Fromfile && getyn(SAMEFILEPROMPT))
strcpy(buf, Fromfile);
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);
+ rv = varpush(outf, writev);
close(outf);
- wprintw(Score, " [%s]", buf);
+ 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)
-reg char *file; {
+ char *file;
+{
- reg char *sp;
- reg int inf;
- char buf[80];
- STAT sbuf;
+ char *sp;
+ int inf;
+ char buf[80];
+ STAT sbuf;
if ((inf = open(file, 0)) < 0) {
- perror(file);
+ 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;
}
-