Skip to content

curl_setup_once: drop E* macro redefines unused (with winsock2) - #16615

Closed
vszakats wants to merge 4 commits into
curl:masterfrom
vszakats:eunused
Closed

vszakats wants to merge 4 commits into
curl:masterfrom
vszakats:eunused

Conversation

@vszakats

@vszakats vszakats commented Mar 7, 2025 •

Copy link
Copy Markdown
Member

These were not used in curl sources at all.

Except EDQUOT which was used after mkdir() in src/tool_dirhie.c
for error display. It should not be redefined to a winsock2 error.
This makes the "exceeded your quota" error correctly appear on Windows,
if detected, after operations that create directories.

After this patch there remain 14 E* macro redefines on Windows,
down from 40 before this patch.

Bug: #16553 (comment)
Ref: #16612
Ref: #16605

vszakats added 3 commits March 7, 2025 17:19
It's only used in src/tool_dirhie when checking `mkdir` results.
@vszakats vszakats added cmdline tool Windows Windows-specific labels Mar 7, 2025
@vszakats vszakats changed the title curl_setup_once: drop unused E* macros curl_setup_once: drop unused E* macros, drop EDQUOT redefine Mar 7, 2025
@vszakats vszakats changed the title curl_setup_once: drop unused E* macros, drop EDQUOT redefine curl_setup_once: drop E* macros not used for winsock2 errors Mar 7, 2025
@vszakats vszakats changed the title curl_setup_once: drop E* macros not used for winsock2 errors curl_setup_once: drop E* macro redefines not used for winsock2 errors Mar 7, 2025
@vszakats vszakats changed the title curl_setup_once: drop E* macro redefines not used for winsock2 errors curl_setup_once: drop E* macro redefines unused (with winsock2) Mar 7, 2025
@vszakats

This comment was marked as off-topic.

@vszakats

This comment was marked as off-topic.

@testclutch

This comment was marked as outdated.

@vszakats vszakats removed the tidy-up label Mar 7, 2025
@vszakats vszakats closed this in d69425e Mar 8, 2025
@vszakats
vszakats deleted the eunused branch March 8, 2025 00:54
vszakats added a commit to vszakats/curl that referenced this pull request Mar 8, 2025
Same case as fixed earlier for `EDQUOT`. It fixes an `mkdir()` error
to appear correctly on Windows.

Follow-up to d69425e  curl#16615
vszakats added a commit that referenced this pull request Mar 8, 2025
The only user is error display code following an `mkdir()` call. In this
case the redefinition didn't cause an issue, but was unnecessary.

Follow-up to d69425e #16615
Closes #16620
vszakats added a commit that referenced this pull request Mar 12, 2025
…ixes

Before this patch, standard `E*` errno codes were redefined on Windows,
onto matching winsock2 `WSA*` error codes, which have different values.
This broke uses where using the `E*` value in non-socket context, or
other places expecting a POSIX `errno`, e.g. file I/O, threads, IDN or
interfacing with dependencies.

Fix it by introducing a curl-specific `SOCKE*` set of macros that map to
`WSA*` on Windows and standard POSIX codes on other platforms. Then
verify and update the code to use `SOCKE*` or `E*` macro depending on
context.

- Add `SOCKE*` macros that map to either winsock2 or POSIX error codes.
  And use them with `SOCKERRNO` or in contexts requiring
  platform-dependent socket error codes.

  This fixes `E*` uses which were supposed be POSIX values, not `WSA*`
  socket errors, on Windows:
  - lib/curl_multibyte.c
  - lib/curl_threads.c
  - lib/idn.c
  - lib/vtls/gtls.c
  - lib/vtls/rustls.c
  - src/tool_cb_wrt.c
  - src/tool_dirhie.c

- Ban `E*` codes having a `SOCKE*` mapping, via checksrc.
  Authored-by: Daniel Stenberg

- Add exceptions for `E*` codes used in file I/O, or other contexts
  requiring POSIX error codes.

Also:
- ftp: fix missing `SOCKEACCES` mapping for Windows.
- add `SOCKENOMEM` for `Curl_getaddrinfo()` via `asyn-thread.c`.
- tests/server/sockfilt: fix to set `SOCKERRNO` in local `select()`
  override on Windows.
- lib/inet_ntop: fix to return `WSAEINVAL` on Windows, where `ENOSPC` is
  used on other platforms. To simulate Windows' built-in `inet_ntop()`,
  as tested on a Win10 machine.
  Note:
  - WINE returns `STATUS_INVALID_PARAMETER` = `0xC000000D`.
  - Microsoft documentation says it returns `WSA_INVALID_PARAMETER`
    (= `ERROR_INVALID_PARAMETER`) 87:
    https://learn.microsoft.com/windows/win32/api/ws2tcpip/nf-ws2tcpip-inet_ntop#return-value
- lib/inet_ntop: drop redundant `CURL_SETERRNO(ENOSPC)`.
  `inet_ntop4()` already sets it before returning `NULL`.
- replace stray `WSAEWOULDBLOCK` with `USE_WINSOCK` macro to detect
  winsock2.
- move existing `SOCKE*` mappings from `tests/server` to
  `curl_setup_once.h`.
- add missing `EINTR`, `EINVAL` constants for WinCE.

Follow-up to abf80aa #16612
Follow-up to d69425e #16615
Bug: #16553 (comment)

Closes #16621
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
These were not used in curl sources at all.

Except `EDQUOT` which was used after `mkdir()` in `src/tool_dirhie.c`
for error display. It should not be redefined to a winsock2 error.
This makes the "exceeded your quota" error correctly appear on Windows,
if detected, after operations that create directories.

After this patch there remain 14 `E*` macro redefines on Windows,
down from 40 before this patch.

Bug: curl#16553 (comment)
Ref: curl#16612
Ref: curl#16605
Closes curl#16615
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
The only user is error display code following an `mkdir()` call. In this
case the redefinition didn't cause an issue, but was unnecessary.

Follow-up to d69425e curl#16615
Closes curl#16620
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
…ixes

Before this patch, standard `E*` errno codes were redefined on Windows,
onto matching winsock2 `WSA*` error codes, which have different values.
This broke uses where using the `E*` value in non-socket context, or
other places expecting a POSIX `errno`, e.g. file I/O, threads, IDN or
interfacing with dependencies.

Fix it by introducing a curl-specific `SOCKE*` set of macros that map to
`WSA*` on Windows and standard POSIX codes on other platforms. Then
verify and update the code to use `SOCKE*` or `E*` macro depending on
context.

- Add `SOCKE*` macros that map to either winsock2 or POSIX error codes.
  And use them with `SOCKERRNO` or in contexts requiring
  platform-dependent socket error codes.

  This fixes `E*` uses which were supposed be POSIX values, not `WSA*`
  socket errors, on Windows:
  - lib/curl_multibyte.c
  - lib/curl_threads.c
  - lib/idn.c
  - lib/vtls/gtls.c
  - lib/vtls/rustls.c
  - src/tool_cb_wrt.c
  - src/tool_dirhie.c

- Ban `E*` codes having a `SOCKE*` mapping, via checksrc.
  Authored-by: Daniel Stenberg

- Add exceptions for `E*` codes used in file I/O, or other contexts
  requiring POSIX error codes.

Also:
- ftp: fix missing `SOCKEACCES` mapping for Windows.
- add `SOCKENOMEM` for `Curl_getaddrinfo()` via `asyn-thread.c`.
- tests/server/sockfilt: fix to set `SOCKERRNO` in local `select()`
  override on Windows.
- lib/inet_ntop: fix to return `WSAEINVAL` on Windows, where `ENOSPC` is
  used on other platforms. To simulate Windows' built-in `inet_ntop()`,
  as tested on a Win10 machine.
  Note:
  - WINE returns `STATUS_INVALID_PARAMETER` = `0xC000000D`.
  - Microsoft documentation says it returns `WSA_INVALID_PARAMETER`
    (= `ERROR_INVALID_PARAMETER`) 87:
    https://learn.microsoft.com/windows/win32/api/ws2tcpip/nf-ws2tcpip-inet_ntop#return-value
- lib/inet_ntop: drop redundant `CURL_SETERRNO(ENOSPC)`.
  `inet_ntop4()` already sets it before returning `NULL`.
- replace stray `WSAEWOULDBLOCK` with `USE_WINSOCK` macro to detect
  winsock2.
- move existing `SOCKE*` mappings from `tests/server` to
  `curl_setup_once.h`.
- add missing `EINTR`, `EINVAL` constants for WinCE.

Follow-up to abf80aa curl#16612
Follow-up to d69425e curl#16615
Bug: curl#16553 (comment)

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

Labels

cmdline tool Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

2 participants