]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curlx_win32_fopen: use `_fsopen()`/`_wfsopen()` with `_SH_DENYNO`
authorViktor Szakats <commit@vsz.me>
Mon, 5 Jan 2026 10:04:10 +0000 (11:04 +0100)
committerViktor Szakats <commit@vsz.me>
Tue, 6 Jan 2026 11:20:01 +0000 (12:20 +0100)
Replacing `fopen_s()`/`_wfopen_s()`, to allow customizing share mode,
and keep the sharing mode as was with `fopen()`/`_wopen()` earlier and
as used in `_sopen_s()`/`_wsopen_s()`.

The replaced functions used `_SH_SECURE` internally. Otherwise they are
identical to the replacements.

Ref: https://learn.microsoft.com/cpp/c-runtime-library/reference/fsopen-wfsopen

Reported-by: Jay Satiro
Fixes #20155
Ref: #20156
Follow-up to 1e7d0bafc6d25d98ec72ff419df65fda3cf147a7 #19643
Closes #20186

lib/curlx/fopen.c

index 035632af4b40895a68275b8fb9ef5a550ff69eb9..e9eb6df3b09e40a42a0603d9822653e166f2f0b2 100644 (file)
@@ -348,7 +348,7 @@ FILE *curlx_win32_fopen(const char *filename, const char *mode)
       target = fixed;
     else
       target = filename_w;
-    errno = _wfopen_s(&result, target, mode_w);
+    result = _wfsopen(target, mode_w, _SH_DENYNO);
   }
   else
     /* !checksrc! disable ERRNOVAR 1 */
@@ -360,7 +360,7 @@ FILE *curlx_win32_fopen(const char *filename, const char *mode)
     target = fixed;
   else
     target = filename;
-  errno = fopen_s(&result, target, mode);
+  result = _fsopen(target, mode, _SH_DENYNO);
 #endif
 
   CURLX_FREE(fixed);