X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/718b40e43f2fbb804acc0266499926f8e51f83ef..HEAD:/mille/save.c diff --git a/mille/save.c b/mille/save.c index 05c007f0..0785254c 100644 --- a/mille/save.c +++ b/mille/save.c @@ -1,4 +1,4 @@ -/* $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 @@ -12,11 +12,7 @@ * 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. * @@ -38,20 +34,18 @@ #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 + #include "mille.h" #ifndef unctrl #include "unctrl.h" #endif -# ifdef attron -# include -# endif attron - /* * @(#)save.c 1.2 (Berkeley) 3/28/83 */ @@ -63,10 +57,10 @@ typedef struct stat STAT; * 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; @@ -118,19 +112,23 @@ over: && 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'; @@ -147,16 +145,15 @@ over: * 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); } @@ -166,14 +163,17 @@ rest_f(file) } 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; }