From ec2d6d5322686cb4262d9c93c41f496cc6e7caa6 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 26 Feb 2023 19:32:28 +0000 Subject: [PATCH] Open files in shared mode on Windows --- src/jit/jit-exits.c | 9 +++++++-- test/regress/file11.vhd | 27 +++++++++++++++++++++++++++ test/regress/testlist.txt | 1 + 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 test/regress/file11.vhd diff --git a/src/jit/jit-exits.c b/src/jit/jit-exits.c index 71534e87..cc5de8af 100644 --- a/src/jit/jit-exits.c +++ b/src/jit/jit-exits.c @@ -36,6 +36,10 @@ #include #include +#ifdef __MINGW32__ +#include +#endif + void x_file_open(int8_t *status, void **_fp, uint8_t *name_bytes, int32_t name_len, int8_t mode, tree_t where) { @@ -72,7 +76,8 @@ void x_file_open(int8_t *status, void **_fp, uint8_t *name_bytes, *fp = stdout; else { #ifdef __MINGW32__ - const bool failed = (fopen_s(fp, fname, mode_str[mode]) != 0); + const bool failed = + ((*fp = _fsopen(fname, mode_str[mode], _SH_DENYNO)) == NULL); #else const bool failed = ((*fp = fopen(fname, mode_str[mode])) == NULL); #endif @@ -83,7 +88,7 @@ void x_file_open(int8_t *status, void **_fp, uint8_t *name_bytes, else { switch (errno) { case ENOENT: *status = NAME_ERROR; break; - case EPERM: *status = MODE_ERROR; break; + case EACCES: *status = MODE_ERROR; break; default: *status = NAME_ERROR; break; } } diff --git a/test/regress/file11.vhd b/test/regress/file11.vhd new file mode 100644 index 00000000..8c4a1de3 --- /dev/null +++ b/test/regress/file11.vhd @@ -0,0 +1,27 @@ +entity file11 is +end entity; + +architecture test of file11 is + + type char_file is file of character; + + file f1, f2 : char_file; + +begin + + process is + variable c : character; + begin + file_open(f1, "test.txt", WRITE_MODE); + write(f1, 'x'); + flush(f1); + + -- Check we can open the same file again + file_open(f2, "test.txt"); + read(f2, c); + assert c = 'x'; + + wait; + end process; + +end architecture; diff --git a/test/regress/testlist.txt b/test/regress/testlist.txt index 60e18106..dc19f5ef 100644 --- a/test/regress/testlist.txt +++ b/test/regress/testlist.txt @@ -731,3 +731,4 @@ link4 normal predef3 normal wait26 fail,gold signal29 fail,gold +file11 normal,2008 -- 2.39.2