VS 2013 build of NetHack.exe and also fix level file locking
This commit is contained in:
+4
-4
@@ -330,7 +330,7 @@ struct obj *corpse;
|
||||
clear_bypasses();
|
||||
fd = open_bonesfile(&u.uz, &bonesid);
|
||||
if (fd >= 0) {
|
||||
(void) close(fd);
|
||||
(void) nhclose(fd);
|
||||
if (wizard) {
|
||||
if (yn("Bones file already exists. Replace it?") == 'y') {
|
||||
if (delete_bonesfile(&u.uz)) goto make_bones;
|
||||
@@ -503,7 +503,7 @@ struct obj *corpse;
|
||||
if (bytes_counted > freediskspace(bones)) { /* not enough room */
|
||||
if (wizard)
|
||||
pline("Insufficient space to create bones file.");
|
||||
(void) close(fd);
|
||||
(void) nhclose(fd);
|
||||
cancel_bonesfile();
|
||||
return;
|
||||
}
|
||||
@@ -549,7 +549,7 @@ getbones()
|
||||
ok = TRUE;
|
||||
if(wizard) {
|
||||
if(yn("Get bones?") == 'n') {
|
||||
(void) close(fd);
|
||||
(void) nhclose(fd);
|
||||
compress_bonesfile();
|
||||
return(0);
|
||||
}
|
||||
@@ -593,7 +593,7 @@ getbones()
|
||||
resetobjs(level.buriedobjlist,TRUE);
|
||||
}
|
||||
}
|
||||
(void) close(fd);
|
||||
(void) nhclose(fd);
|
||||
sanitize_engravings();
|
||||
|
||||
if(wizard) {
|
||||
|
||||
@@ -941,7 +941,7 @@ currentlevel_rewrite()
|
||||
|
||||
#ifdef MFLOPPY
|
||||
if (!savelev(fd, ledger_no(&u.uz), COUNT_SAVE)) {
|
||||
(void) close(fd);
|
||||
(void) nhclose(fd);
|
||||
delete_levelfile(ledger_no(&u.uz));
|
||||
pline("NetHack is out of disk space for making levels!");
|
||||
You("can save, quit, or continue playing.");
|
||||
@@ -1153,7 +1153,7 @@ boolean at_stairs, falling, portal;
|
||||
}
|
||||
minit(); /* ZEROCOMP */
|
||||
getlev(fd, hackpid, new_ledger, FALSE);
|
||||
(void) close(fd);
|
||||
(void) nhclose(fd);
|
||||
oinit(); /* reassign level dependent obj probabilities */
|
||||
}
|
||||
/* do this prior to level-change pline messages */
|
||||
|
||||
+42
-35
@@ -637,12 +637,12 @@ really_close()
|
||||
lftrack.fd = -1;
|
||||
lftrack.oflag = 0;
|
||||
if (fd != -1)
|
||||
(void)_close(fd);
|
||||
(void)close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
int
|
||||
close(fd)
|
||||
nhclose(fd)
|
||||
int fd;
|
||||
{
|
||||
if (lftrack.fd == fd) {
|
||||
@@ -651,10 +651,17 @@ int fd;
|
||||
lftrack.nethack_thinks_it_is_open = FALSE;
|
||||
return 0;
|
||||
}
|
||||
return _close(fd);
|
||||
return close(fd);
|
||||
}
|
||||
#else
|
||||
int
|
||||
nhclose(fd)
|
||||
int fd;
|
||||
{
|
||||
return close(fd);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* ---------- END LEVEL FILE HANDLING ----------- */
|
||||
|
||||
|
||||
@@ -992,7 +999,7 @@ restore_saved_game()
|
||||
if ((fd = open_savefile()) < 0) return fd;
|
||||
|
||||
if (validate(fd, fq_save) != 0) {
|
||||
(void) close(fd), fd = -1;
|
||||
(void) nhclose(fd), fd = -1;
|
||||
(void) delete_savefile();
|
||||
}
|
||||
return fd;
|
||||
@@ -1017,7 +1024,7 @@ const char* filename;
|
||||
get_plname_from_file(fd, tplname);
|
||||
result = dupstr(tplname);
|
||||
}
|
||||
(void) close(fd);
|
||||
(void) nhclose(fd);
|
||||
}
|
||||
nh_compress(SAVEF);
|
||||
|
||||
@@ -1724,7 +1731,7 @@ const char *filename;
|
||||
if (unlink(lockname) < 0)
|
||||
HUP raw_printf("Can't unlink %s.", lockname);
|
||||
# ifdef NO_FILE_LINKS
|
||||
(void) close(lockfd);
|
||||
(void) nhclose(lockfd);
|
||||
# endif
|
||||
|
||||
#endif /* UNIX || VMS */
|
||||
@@ -2839,9 +2846,9 @@ const char *dir UNUSED_if_not_OS2_CODEVIEW;
|
||||
wait_synch();
|
||||
}
|
||||
# endif
|
||||
(void) close(fd); /* RECORD is accessible */
|
||||
(void) nhclose(fd); /* RECORD is accessible */
|
||||
} else if ((fd = open(fq_record, O_CREAT|O_RDWR, FCMASK)) >= 0) {
|
||||
(void) close(fd); /* RECORD newly created */
|
||||
(void) nhclose(fd); /* RECORD newly created */
|
||||
# if defined(VMS) && !defined(SECURE)
|
||||
/* Re-protect RECORD with world:read+write+execute+delete access. */
|
||||
(void) chmod(fq_record, FCMASK | 007);
|
||||
@@ -2881,9 +2888,9 @@ const char *dir UNUSED_if_not_OS2_CODEVIEW;
|
||||
raw_printf("Warning: cannot write record %s", tmp);
|
||||
wait_synch();
|
||||
} else
|
||||
(void) close(fd);
|
||||
(void) nhclose(fd);
|
||||
} else /* open succeeded */
|
||||
(void) close(fd);
|
||||
(void) nhclose(fd);
|
||||
#else /* MICRO || WIN32*/
|
||||
|
||||
# ifdef MAC
|
||||
@@ -2967,14 +2974,14 @@ recover_savefile()
|
||||
if (read(gfd, (genericptr_t) &hpid, sizeof hpid) != sizeof hpid) {
|
||||
raw_printf(
|
||||
"\nCheckpoint data incompletely written or subsequently clobbered. Recovery impossible.");
|
||||
(void)close(gfd);
|
||||
(void)nhclose(gfd);
|
||||
return FALSE;
|
||||
}
|
||||
if (read(gfd, (genericptr_t) &savelev, sizeof(savelev))
|
||||
!= sizeof(savelev)) {
|
||||
raw_printf("\nCheckpointing was not in effect for %s -- recovery impossible.\n",
|
||||
lock);
|
||||
(void)close(gfd);
|
||||
(void)nhclose(gfd);
|
||||
return FALSE;
|
||||
}
|
||||
if ((read(gfd, (genericptr_t) savename, sizeof savename)
|
||||
@@ -2988,7 +2995,7 @@ recover_savefile()
|
||||
(read(gfd, (genericptr_t) &tmpplbuf, pltmpsiz)
|
||||
!= pltmpsiz)) {
|
||||
raw_printf("\nError reading %s -- can't recover.\n", lock);
|
||||
(void)close(gfd);
|
||||
(void)nhclose(gfd);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -3004,15 +3011,15 @@ recover_savefile()
|
||||
sfd = create_savefile();
|
||||
if (sfd < 0) {
|
||||
raw_printf("\nCannot recover savefile %s.\n", SAVEF);
|
||||
(void)close(gfd);
|
||||
(void)nhclose(gfd);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
lfd = open_levelfile(savelev, errbuf);
|
||||
if (lfd < 0) {
|
||||
raw_printf("\n%s\n", errbuf);
|
||||
(void)close(gfd);
|
||||
(void)close(sfd);
|
||||
(void)nhclose(gfd);
|
||||
(void)nhclose(sfd);
|
||||
delete_savefile();
|
||||
return FALSE;
|
||||
}
|
||||
@@ -3020,8 +3027,8 @@ recover_savefile()
|
||||
if (write(sfd, (genericptr_t) &version_data, sizeof version_data)
|
||||
!= sizeof version_data) {
|
||||
raw_printf("\nError writing %s; recovery failed.", SAVEF);
|
||||
(void)close(gfd);
|
||||
(void)close(sfd);
|
||||
(void)nhclose(gfd);
|
||||
(void)nhclose(sfd);
|
||||
delete_savefile();
|
||||
return FALSE;
|
||||
}
|
||||
@@ -3031,8 +3038,8 @@ recover_savefile()
|
||||
raw_printf(
|
||||
"\nError writing %s; recovery failed (savefile_info).\n",
|
||||
SAVEF);
|
||||
(void)close(gfd);
|
||||
(void)close(sfd);
|
||||
(void)nhclose(gfd);
|
||||
(void)nhclose(sfd);
|
||||
delete_savefile();
|
||||
return FALSE;
|
||||
}
|
||||
@@ -3042,8 +3049,8 @@ recover_savefile()
|
||||
raw_printf(
|
||||
"Error writing %s; recovery failed (player name size).\n",
|
||||
SAVEF);
|
||||
(void)close(gfd);
|
||||
(void)close(sfd);
|
||||
(void)nhclose(gfd);
|
||||
(void)nhclose(sfd);
|
||||
delete_savefile();
|
||||
return FALSE;
|
||||
}
|
||||
@@ -3053,28 +3060,28 @@ recover_savefile()
|
||||
raw_printf(
|
||||
"Error writing %s; recovery failed (player name).\n",
|
||||
SAVEF);
|
||||
(void)close(gfd);
|
||||
(void)close(sfd);
|
||||
(void)nhclose(gfd);
|
||||
(void)nhclose(sfd);
|
||||
delete_savefile();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!copy_bytes(lfd, sfd)) {
|
||||
(void) close(lfd);
|
||||
(void) close(sfd);
|
||||
(void) nhclose(lfd);
|
||||
(void) nhclose(sfd);
|
||||
delete_savefile();
|
||||
return FALSE;
|
||||
}
|
||||
(void)close(lfd);
|
||||
(void)nhclose(lfd);
|
||||
processed[savelev] = 1;
|
||||
|
||||
if (!copy_bytes(gfd, sfd)) {
|
||||
(void) close(lfd);
|
||||
(void) close(sfd);
|
||||
(void) nhclose(lfd);
|
||||
(void) nhclose(sfd);
|
||||
delete_savefile();
|
||||
return FALSE;
|
||||
}
|
||||
(void)close(gfd);
|
||||
(void)nhclose(gfd);
|
||||
processed[0] = 1;
|
||||
|
||||
for (lev = 1; lev < 256; lev++) {
|
||||
@@ -3088,17 +3095,17 @@ recover_savefile()
|
||||
levc = (xchar) lev;
|
||||
write(sfd, (genericptr_t) &levc, sizeof(levc));
|
||||
if (!copy_bytes(lfd, sfd)) {
|
||||
(void) close(lfd);
|
||||
(void) close(sfd);
|
||||
(void) nhclose(lfd);
|
||||
(void) nhclose(sfd);
|
||||
delete_savefile();
|
||||
return FALSE;
|
||||
}
|
||||
(void)close(lfd);
|
||||
(void)nhclose(lfd);
|
||||
processed[lev] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
(void)close(sfd);
|
||||
(void)nhclose(sfd);
|
||||
|
||||
#ifdef HOLD_LOCKFILE_OPEN
|
||||
really_close();
|
||||
|
||||
+1
-1
@@ -753,7 +753,7 @@ char *buf;
|
||||
break;
|
||||
}
|
||||
(void) write(fd, buf, strlen(buf));
|
||||
(void) close(fd);
|
||||
(void) nhclose(fd);
|
||||
}
|
||||
}
|
||||
#endif /* UNIX386MUSIC */
|
||||
|
||||
+4
-4
@@ -703,7 +703,7 @@ xchar ltmp;
|
||||
|
||||
/* Remove levels and bones that may have been created.
|
||||
*/
|
||||
(void) close(nfd);
|
||||
(void) nhclose(nfd);
|
||||
# ifdef AMIGA
|
||||
clearlocks();
|
||||
# else
|
||||
@@ -752,7 +752,7 @@ register int fd;
|
||||
if (!restgamestate(fd, &stuckid, &steedid)) {
|
||||
display_nhwindow(WIN_MESSAGE, TRUE);
|
||||
savelev(-1, 0, FREE_SAVE); /* discard current level */
|
||||
(void) close(fd);
|
||||
(void) nhclose(fd);
|
||||
(void) delete_savefile();
|
||||
restoring = FALSE;
|
||||
return(0);
|
||||
@@ -826,7 +826,7 @@ register int fd;
|
||||
get_plname_from_file(fd, plname);
|
||||
|
||||
getlev(fd, 0, (xchar)0, FALSE);
|
||||
(void) close(fd);
|
||||
(void) nhclose(fd);
|
||||
|
||||
/* Now set the restore settings to match the
|
||||
* settings used by the save file output routines
|
||||
@@ -1543,7 +1543,7 @@ register unsigned int len;
|
||||
} else {
|
||||
pline("Read %d instead of %u bytes.", rlen, len);
|
||||
if(restoring) {
|
||||
(void) close(fd);
|
||||
(void) nhclose(fd);
|
||||
(void) delete_savefile();
|
||||
error("Error restoring old game.");
|
||||
}
|
||||
|
||||
+9
-9
@@ -162,7 +162,7 @@ dosave0()
|
||||
nh_uncompress(fq_save);
|
||||
fd = open_savefile();
|
||||
if (fd > 0) {
|
||||
(void) close(fd);
|
||||
(void) nhclose(fd);
|
||||
clear_nhwindow(WIN_MESSAGE);
|
||||
There("seems to be an old save file.");
|
||||
if (yn("Overwrite the old file?") == 'n') {
|
||||
@@ -218,7 +218,7 @@ dosave0()
|
||||
pline("Require %ld bytes but only have %ld.", needed, fds);
|
||||
}
|
||||
flushout();
|
||||
(void) close(fd);
|
||||
(void) nhclose(fd);
|
||||
(void) delete_savefile();
|
||||
return 0;
|
||||
}
|
||||
@@ -265,7 +265,7 @@ dosave0()
|
||||
ofd = open_levelfile(ltmp, whynot);
|
||||
if (ofd < 0) {
|
||||
HUP pline1(whynot);
|
||||
(void) close(fd);
|
||||
(void) nhclose(fd);
|
||||
(void) delete_savefile();
|
||||
HUP Strcpy(killer.name, whynot);
|
||||
HUP done(TRICKED);
|
||||
@@ -273,7 +273,7 @@ dosave0()
|
||||
}
|
||||
minit(); /* ZEROCOMP */
|
||||
getlev(ofd, hackpid, ltmp, FALSE);
|
||||
(void) close(ofd);
|
||||
(void) nhclose(ofd);
|
||||
bwrite(fd, (genericptr_t) <mp, sizeof ltmp); /* level number*/
|
||||
savelev(fd, ltmp, WRITE_SAVE | FREE_SAVE); /* actual level*/
|
||||
delete_levelfile(ltmp);
|
||||
@@ -401,7 +401,7 @@ savestateinlock()
|
||||
Strcpy(killer.name, whynot);
|
||||
done(TRICKED);
|
||||
}
|
||||
(void) close(fd);
|
||||
(void) nhclose(fd);
|
||||
|
||||
fd = create_levelfile(0, whynot);
|
||||
if (fd < 0) {
|
||||
@@ -739,7 +739,7 @@ def_bclose(fd)
|
||||
bw_FILE = 0;
|
||||
} else
|
||||
#endif
|
||||
(void) close(fd);
|
||||
(void) nhclose(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -876,7 +876,7 @@ zerocomp_bclose(fd)
|
||||
int fd;
|
||||
{
|
||||
zerocomp_bufoff(fd);
|
||||
(void) close(fd);
|
||||
(void) nhclose(fd);
|
||||
return;
|
||||
}
|
||||
#endif /* ZEROCOMP */
|
||||
@@ -1432,8 +1432,8 @@ char *from, *to;
|
||||
if (nto != nfrom)
|
||||
panic("Copyfile failed!");
|
||||
} while (nfrom == BUFSIZ);
|
||||
(void) close(fdfrom);
|
||||
(void) close(fdto);
|
||||
(void) nhclose(fdfrom);
|
||||
(void) nhclose(fdto);
|
||||
# endif /* TOS */
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user