-/* NetHack 3.6 recover.c $NHDT-Date: 1501461282 2017/07/31 00:34:42 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.16 $ */
+/* NetHack 3.6 recover.c $NHDT-Date: 1550103078 2019/02/14 00:11:18 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.19 $ */
/* Copyright (c) Janet Walz, 1992. */
/* NetHack may be freely redistributed. See license for details. */
* level files. Requires that the `checkpoint' option be enabled at the
* time NetHack creates those level files.
*/
+#ifdef WIN32
+#include <errno.h>
+#include "win32api.h"
+#endif
+
#include "config.h"
#if !defined(O_WRONLY) && !defined(LSC) && !defined(AZTEC_C)
#include <fcntl.h>
#endif
-#ifdef WIN32
-#include <errno.h>
-#include "win32api.h"
+#if 1 /*JP*//* copy from lint.h */
+#ifdef __GNUC__
+#define PRAGMA_IGNORE_HELPER0(x) #x
+#define PRAGMA_IGNORE_HELPER1(x) PRAGMA_IGNORE_HELPER0(GCC diagnostic ignored x)
+#define PRAGMA_IGNORE_HELPER2(y) PRAGMA_IGNORE_HELPER1(#y)
+#define _pragma_ignore(opt) _Pragma("GCC diagnostic push") \
+ _Pragma(PRAGMA_IGNORE_HELPER2(opt))
+#define _pragma_pop _Pragma("GCC diagnostic pop")
+#else
+#define _pragma_push
+#define _pragma_ignore(opt)
+#define _pragma_pop
#endif
+#endif
+
#ifdef VMS
extern int FDECL(vms_creat, (const char *, unsigned));
#if defined(__BORLANDC__) && !defined(_WIN32)
extern unsigned _stklen = STKSIZ;
#endif
-char
- savename[SAVESIZE]; /* holds relative path of save file from playground */
+char savename[SAVESIZE]; /* holds relative path of save file from playground */
int
main(argc, argv)
&& strcmp(dir, HACKDIR)
#endif
) {
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wunused-result"
+_pragma_ignore(-Wunused-result)
(void) setgid(getgid());
(void) setuid(getuid());
-#pragma GCC diagnostic pop
+_pragma_pop
}
#endif /* SECURE && !VMS */
char *basename;
{
int gfd, lfd, sfd;
- int lev, savelev, hpid, pltmpsiz;
+ int res = 0, lev, savelev, hpid, pltmpsiz;
xchar levc;
struct version_info version_data;
struct savefile_info sfi;
char plbuf[PL_NSIZ];
/* level 0 file contains:
- * pid of creating process (ignored here)
- * level number for current level of save file
- * name of save file nethack would have created
- * savefile info
- * player name
- * and game state
+ * pid of creating process (ignored here)
+ * level number for current level of save file
+ * name of save file nethack would have created
+ * savefile info
+ * player name
+ * and game state
*/
(void) strcpy(lock, basename);
gfd = open_levelfile(0);
|| (read(gfd, (genericptr_t) &sfi, sizeof sfi) != sizeof sfi)
|| (read(gfd, (genericptr_t) &pltmpsiz, sizeof pltmpsiz)
!= sizeof pltmpsiz) || (pltmpsiz > PL_NSIZ)
- || (read(gfd, (genericptr_t) &plbuf, pltmpsiz) != pltmpsiz)) {
+ || (read(gfd, (genericptr_t) plbuf, pltmpsiz) != pltmpsiz)) {
Fprintf(stderr, "Error reading %s -- can't recover.\n", lock);
Close(gfd);
return -1;
}
/* save file should contain:
- * version info
- * savefile info
- * player name
- * current level (including pets)
- * (non-level-based) game state
- * other levels
+ * version info
+ * savefile info
+ * player name
+ * current level (including pets)
+ * (non-level-based) game state
+ * other levels
*/
sfd = create_savefile();
if (sfd < 0) {
return -1;
}
- if (write(sfd, (genericptr_t) &plbuf, pltmpsiz) != pltmpsiz) {
+ if (write(sfd, (genericptr_t) plbuf, pltmpsiz) != pltmpsiz) {
Fprintf(stderr, "Error writing %s; recovery failed (player name).\n",
savename);
Close(gfd);
set_levelfile_name(0);
(void) unlink(lock);
- for (lev = 1; lev < 256; lev++) {
+ for (lev = 1; lev < 256 && res == 0; lev++) {
/* level numbers are kept in xchars in save.c, so the
* maximum level number (for the endlevel) must be < 256
*/
if (lfd >= 0) {
/* any or all of these may not exist */
levc = (xchar) lev;
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wunused-result"
- write(sfd, (genericptr_t) &levc, sizeof(levc));
-#pragma GCC diagnostic pop
- copy_bytes(lfd, sfd);
+ if (write(sfd, (genericptr_t) &levc, sizeof levc)
+ != sizeof levc)
+ res = -1;
+ else
+ copy_bytes(lfd, sfd);
Close(lfd);
(void) unlink(lock);
}
#if 0 /* OBSOLETE, HackWB is no longer in use */
#ifdef AMIGA
- {
+ if (res == 0) {
/* we need to create an icon for the saved game
* or HackWB won't notice the file.
*/
- char iconfile[FILENAME];
- int in, out;
+ char iconfile[FILENAME];
+ int in, out;
- (void) sprintf(iconfile, "%s.info", savename);
- in = open("NetHack:default.icon", O_RDONLY);
- out = open(iconfile, O_WRONLY | O_TRUNC | O_CREAT);
- if (in > -1 && out > -1) {
+ (void) sprintf(iconfile, "%s.info", savename);
+ in = open("NetHack:default.icon", O_RDONLY);
+ out = open(iconfile, O_WRONLY | O_TRUNC | O_CREAT);
+ if (in > -1 && out > -1) {
copy_bytes(in, out);
- }
- if (in > -1)
+ }
+ if (in > -1)
close(in);
- if (out > -1)
+ if (out > -1)
close(out);
}
#endif /*AMIGA*/
#endif
- return 0;
+ return res;
}
#ifdef EXEPATH