Skip to content

Conversation

@vszakats
Copy link
Member

@vszakats vszakats commented Nov 22, 2025

The safe (_s) variants of the Windows open() reject these flags,
while the classic ones silently accepted them.

Also:

  • also drop the now unused stat() call on Windows.
  • replace magic number with their equivalent Windows and Unix-specific
    S_* macros.

Refs:
https://learn.microsoft.com/cpp/c-runtime-library/reference/open-wopen
https://learn.microsoft.com/cpp/c-runtime-library/reference/fstat-fstat32-fstat64-fstati64-fstat32i64-fstat64i32

Cherry-picked from #19643


  • check/add headers for newly used macros. Requires sys/stat.h which is included from curl_setup*.h (twice even, for Windows), or fcntl.h if available, which is included from curl_setup_once.h, also from curlx/fopen.h via curl_fopen.h.

@testclutch

This comment was marked as off-topic.

@vszakats vszakats changed the title curl_fopen: do not pass invalid pmode flags to open() on Windows curl_fopen: do not pass invalid mode flags to open() on Windows Nov 22, 2025
The safe variants of the Windows `open()` reject these, while
the classic ones ignore it.

Also:
- also drop the now unused `stat()` call on Windows.
- replace magic number with their equivalent Windows and Unix-specific
  `S_*` macros.

https://learn.microsoft.com/cpp/c-runtime-library/reference/open-wopen
https://learn.microsoft.com/cpp/c-runtime-library/reference/fstat-fstat32-fstat64-fstati64-fstat32i64-fstat64i32
@vszakats vszakats closed this in 537987d Nov 24, 2025
@vszakats vszakats deleted the curlfopen branch November 24, 2025 13:31
vszakats added a commit that referenced this pull request Nov 24, 2025
- replace 0777 with `S_I*` macros.
- fix to not pass invalid flags on Windows.

Follow-up to 537987d #19645

Closes #19671
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

3 participants