-/* $NetBSD: save.c,v 1.6 1997/10/12 00:54:32 lukem Exp $ */
+/* $NetBSD: save.c,v 1.16 2011/08/26 09:01:07 tron 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.
*
#if 0
static char sccsid[] = "@(#)save.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: save.c,v 1.6 1997/10/12 00:54:32 lukem Exp $");
+__RCSID("$NetBSD: save.c,v 1.16 2011/08/26 09:01:07 tron Exp $");
#endif
#endif /* not lint */
+#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
*/
* Returns FALSE if it couldn't be done.
*/
bool
-save()
+save(void)
{
char *sp;
- int outf;
+ int outfd;
time_t *tp;
char buf[80];
time_t tme;
&& getyn(OVERWRITEFILEPROMPT) == FALSE))
return FALSE;
- if ((outf = creat(buf, 0644)) < 0) {
- error(strerror(errno));
+ if ((outfd = creat(buf, 0644)) < 0) {
+ error("%s", strerror(errno));
return FALSE;
}
mvwaddstr(Score, ERR_Y, ERR_X, buf);
wrefresh(Score);
time(tp); /* get current time */
- rv = varpush(outf, writev);
- close(outf);
+ rv = varpush(outfd, writev);
+ close(outfd);
if (rv == FALSE) {
unlink(buf);
} else {
- strcpy(buf, ctime(tp));
+ char *p;
+ if ((p = ctime(tp)) == NULL)
+ strcpy(buf, "?");
+ else
+ strcpy(buf, p);
for (sp = buf; *sp != '\n'; sp++)
continue;
*sp = '\0';
* be cleaned up before the game starts.
*/
bool
-rest_f(file)
- char *file;
+rest_f(const char *file)
{
- char *sp;
+ char *sp, *p;
int inf;
char buf[80];
STAT sbuf;
- if ((inf = open(file, 0)) < 0) {
+ if ((inf = open(file, O_RDONLY)) < 0) {
warn("%s", file);
exit(1);
}
}
varpush(inf, readv);
close(inf);
- strcpy(buf, ctime(&sbuf.st_mtime));
+ if ((p = ctime(&sbuf.st_mtime)) == NULL)
+ strcpy(buf, "?");
+ else
+ strcpy(buf, p);
for (sp = buf; *sp != '\n'; sp++)
continue;
*sp = '\0';
/*
* initialize some necessary values
*/
- (void)sprintf(Initstr, "%s [%s]\n", file, buf);
+ (void)snprintf(Initstr, INITSTR_SIZE, "%s [%s]\n", file, buf);
Fromfile = file;
return !On_exit;
}