Skip to content

build: detect and use _setmode() with Cygwin/MSYS, also use on Windows - #15169

Closed
vszakats wants to merge 1 commit into
curl:masterfrom
vszakats:build-_setmode
Closed

build: detect and use _setmode() with Cygwin/MSYS, also use on Windows#15169
vszakats wants to merge 1 commit into
curl:masterfrom
vszakats:build-_setmode

Conversation

@vszakats

@vszakats vszakats commented Oct 6, 2024

Copy link
Copy Markdown
Member

Before this patch setmode() was not detected with Cygwin/MSYS, because
it's a macro, not a function, and detection is looking for a function.

Switching to symbol detection doesn't work because it mis-detects it on
BSD systems which features a function with the same name but different
functionality and arguments.

Fix it by looking for a _setmode() function on Cygwin/MSYS, and use it
if available.

_setmode() is recommended over setmode() by Windows documentation so
use that on Windows too. It seems to be available on all supported
compilers, so omit detection.

https://learn.microsoft.com/cpp/c-runtime-library/reference/posix-setmode
https://learn.microsoft.com/cpp/c-runtime-library/reference/setmode

Officially Windows requires argument _O_BINARY with an underscore.
O_BINARY is also supported but bound to conditions. Continue to use it
for simplicity. Cygwin supports O_BINARY (no underscore).

Before this patch `setmode()` was not detected with Cygwin/MSYS, because
it's a macro, not a function, and detection is looking for a function.

Switching to symbol detection doesn't work because it mis-detects it on
BSD systems which feature a function with the same name but different
functionality and arguments.

Fix it by looking for a `_setmode()` function on Cygwin/MSYS, and use
it if available.

`_setmode()` is recommended over `setmode()` by Windows documentation
so use that on Windows too. It seems to be available on all supported
compilers, so omit detection.

https://learn.microsoft.com/cpp/c-runtime-library/reference/posix-setmode
https://learn.microsoft.com/cpp/c-runtime-library/reference/setmode

Officially Windows requires argument `_O_BINARY` with an underscore.
`O_BINARY` is also supported but bound to conditions, continue to use
it. Cygwin supports uses `O_BINARY` (no underscore).
@dfandrich

Copy link
Copy Markdown
Contributor

Analysis of PR #15169 at 870ee5d9:

Test http/test_09_push.py::TestPush::test_09_02_h2_push[0] failed, which has NOT been flaky recently, so there could be a real issue in the PR.

Test 1450 failed, which has NOT been flaky recently, so there could be a real issue in the PR.

Generated by Testclutch

@vszakats vszakats closed this in 5e70566 Oct 7, 2024
@vszakats
vszakats deleted the build-_setmode branch October 7, 2024 10:34
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
Before this patch `setmode()` was not detected with Cygwin/MSYS, because
it's a macro, not a function, and detection is looking for a function.

Switching to symbol detection doesn't work because it mis-detects it on
BSD systems which features a function with the same name but different
functionality and arguments.

Fix it by looking for a `_setmode()` function on Cygwin/MSYS, and use it
if available.

`_setmode()` is recommended over `setmode()` by Windows documentation so
use that on Windows too. It seems to be available on all supported
compilers, so omit detection.

https://learn.microsoft.com/cpp/c-runtime-library/reference/posix-setmode
https://learn.microsoft.com/cpp/c-runtime-library/reference/setmode

Officially Windows requires argument `_O_BINARY` with an underscore.
`O_BINARY` is also supported but bound to conditions. Continue to use it
for simplicity. Cygwin supports `O_BINARY` (no underscore).

Closes curl#15169
vszakats added a commit to vszakats/curl that referenced this pull request Feb 7, 2026
vszakats added a commit to vszakats/curl that referenced this pull request Feb 8, 2026
vszakats added a commit that referenced this pull request Feb 8, 2026
- move macro to `curl_setup.h` (from curlx), and rename.
  It's required by src, test servers, libtests. Also used by unit/tunit,
  (which is fixable but this patch doesn't touch it.)
- special-case it for Windows/Cygwin/MS-DOS.
- build: drop `setmode()`/`_setmode()` detection.
  This also avoids detecting the different `setmode()` on BSDs,
  and a lot of complexity and overhead.
- use `CURL_O_BINARY`.

Follow-up to 250d613 #15787
Follow-up to 5e70566 #15169

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

Development

Successfully merging this pull request may close these issues.

2 participants