From 4fe7bb9ca9a78cdba51f4f4fef1d0ac6e24fb5f1 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Mon, 19 Aug 2024 12:41:44 +1200 Subject: [PATCH] Fix fopen crashing due to file mode cache hint Fixed #288 --- doc/changes.md | 3 ++- kermit/k95/ckuus7.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/changes.md b/doc/changes.md index 959a1188..1f82575d 100644 --- a/doc/changes.md +++ b/doc/changes.md @@ -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 diff --git a/kermit/k95/ckuus7.c b/kermit/k95/ckuus7.c index f232fb3a..52ff91b2 100644 --- a/kermit/k95/ckuus7.c +++ b/kermit/k95/ckuus7.c @@ -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 @@ -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 */