From: nethack.allison Date: Sat, 7 Jun 2003 13:16:40 +0000 (+0000) Subject: fix for U486: Can't get Nethack 3.4.1 to work X-Git-Tag: MOVE2GIT~1937 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ff8744798dd6127065294746023b3be51354011f;p=nethack fix for U486: Can't get Nethack 3.4.1 to work >nhversion: 3.4.1 > > nhfrom: 3.4.1 Official binary release for Windows 95/98/NT/2000/Me/XP > (nh341win.zip) > comments: Whenever I run NethackW.exe, the nethack window > appears, and does not run anything. When I close out of the > program, I get this message: > Waiting for access to C:\GAMES\NETHACK341\record. (X retries left). > The X seems to always be either 9 or 59. I don't know how to fix this > > problem, any help would be greatly appreciated writes: >win32 open() returns -1 if failed - same as POSIX open(). > There is no STDIN in GUI applications so 0 is a valid return > value from open(). > So it should read like that unless that breaks Amiga code: Since I can't test the Amiga code, I added a macro OPENFAILURE to keep the Amiga code the same as it is now. It should probably be reviewed by someone on the Amiga team to verify if open() on the Amiga returns 0 or -1 on failure. If the latter, the macro could be removed completely. --- diff --git a/doc/fixes34.2 b/doc/fixes34.2 index 45211cb00..1ce180a99 100644 --- a/doc/fixes34.2 +++ b/doc/fixes34.2 @@ -98,6 +98,10 @@ vms: create an empty paniclog file during playground installation win32tty: add subkeyvalue option to alter key values; Finnish keyboard fix win32tty: distinguish between black/gray/white (by Quietust) win32gui: prevent male Valkyrie and other incorrect startup settings +win32: some code in files.c was incorrectly assuming that a file + descriptor return value of 0 from open() was invalid but it + could be valid on win32gui where stdin, stdout, stderr aren't open; + now it correctly checks for return value < 0 from open() tiles: high priest tile had a couple bad pixels tiles: bad pixels in Croesus and Yeenoghu tiles FreeBSD: incorrect srandom declaration diff --git a/src/files.c b/src/files.c index 498af1349..fddd9bcd4 100644 --- a/src/files.c +++ b/src/files.c @@ -91,6 +91,7 @@ char SAVEP[SAVESIZE]; /* holds path of directory for save file */ #ifdef HOLD_LOCKFILE_OPEN struct level_ftrack { +int init; int fd; /* file descriptor for level file */ int oflag; /* open flags */ boolean nethack_thinks_it_is_open; /* Does NetHack think it's open? */ @@ -535,7 +536,11 @@ const char *name; int lev, oflag; { int reslt, fd; - if (lftrack.fd) { + if (!lftrack.init) { + lftrack.init = 1; + lftrack.fd = -1; + } + if (lftrack.fd >= 0) { /* check for compatible access */ if (lftrack.oflag == oflag) { fd = lftrack.fd; @@ -554,7 +559,7 @@ int lev, oflag; fd = sopen(name, oflag,SH_DENYRW, FCMASK); lftrack.fd = fd; lftrack.oflag = oflag; - if (fd) + if (fd >= 0) lftrack.nethack_thinks_it_is_open = TRUE; } return fd; @@ -565,12 +570,13 @@ really_close() { int fd = lftrack.fd; lftrack.nethack_thinks_it_is_open = FALSE; - lftrack.fd = 0; + lftrack.fd = -1; lftrack.oflag = 0; (void)_close(fd); return; } +int close(fd) int fd; { @@ -1349,15 +1355,20 @@ int retryct; #endif /* UNIX || VMS */ #if defined(AMIGA) || defined(WIN32) || defined(MSDOS) +# ifdef AMIGA +#define OPENFAILURE(fd) (!fd) +# else +#define OPENFAILURE(fd) (fd < 0) +# endif lockptr = 0; - while (retryct-- && !lockptr) { + while (retryct-- && OPENFAILURE(lockptr)) { # ifdef AMIGA (void)DeleteFile(lockname); /* in case dead process was here first */ lockptr = Open(lockname,MODE_NEWFILE); # else lockptr = open(lockname, O_RDWR|O_CREAT|O_EXCL, S_IWRITE); # endif - if (!lockptr) { + if (OPENFAILURE(lockptr)) { raw_printf("Waiting for access to %s. (%d retries left).", filename, retryct); Delay(50);