Skip to content

Commit

Permalink
Fix fopen crashing due to file mode cache hint
Browse files Browse the repository at this point in the history
Fixed #288
  • Loading branch information
davidrg committed Aug 19, 2024
1 parent c0081ef commit 4fe7bb9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion doc/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Nothing yet
None yet

### Fixed bugs
None yet
* Fix `fopen` causing a crash. This issue seems to have come in some recent
version of the Microsoft C Runtime.

### Other Source Changes
None yet
Expand Down
16 changes: 16 additions & 0 deletions kermit/k95/ckuus7.c
Original file line number Diff line number Diff line change
Expand Up @@ -11890,6 +11890,12 @@ z_open(name, flags) char * name; int flags;
if (!mode[0]) /* Check for illegal combinations */
return(z_error = FX_BOM);
}

#ifdef NT
ckstrncat(mode,"S",8); /* S is also known as _O_SEQUENTIAL */
debug(F110, "z_open fopen", mode, 0);
#endif /* NT */

if (!z_inited) { /* If file structs not inited */
debug(F101,"z_open z_maxchan 1","",z_maxchan);
#ifdef UNIX
Expand Down Expand Up @@ -12010,12 +12016,22 @@ z_open(name, flags) char * name; int flags;
z_file[n] = NULL;
return(z_error = (errno ? FX_SYS : FX_UNK)); /* Return error code */
}
#ifdef COMMENT
/*
* 2024-08-19 DavidG: This started crashing on Windows 11 in CKW Beta 6. The
* call to setmode seems ok, it just doesn't like O_SEQUENTIAL anymore. Not
* sure if this is something unsupported now, or if its a bug in the CRT.
* For some reason I've not looked into too closely I'm not even getting
* O_SEQUENTIAL defined on my local PC, while its clearly there on the
* Gitub build agents.
*/
#ifdef NT
#ifdef O_SEQUENTIAL
if (t) /* Caching hint for NT */
_setmode(_fileno(t),O_SEQUENTIAL);
#endif /* O_SEQUENTIAL */
#endif /* NT */
#endif /* COMMENT */

z_nopen++; /* Open, count it. */
z_file[n]->z_fp = t; /* Stash the file pointer */
Expand Down

0 comments on commit 4fe7bb9

Please sign in to comment.