Skip to content

tidy-up: drop redundant includes - #22374

Closed
vszakats wants to merge 7 commits into
curl:masterfrom
vszakats:dropincludes
Closed

tidy-up: drop redundant includes#22374
vszakats wants to merge 7 commits into
curl:masterfrom
vszakats:dropincludes

Conversation

@vszakats

@vszakats vszakats commented Jul 23, 2026

Copy link
Copy Markdown
Member

sys/types.h and sys/socket.h (non-Win32). They are included via
curl/curl.h and curl_setup.h.

This drops HAVE_SYS_TYPES_H guards from the codebase. It's safe
because sys/types.h (POSIX) is already required unconditionally by
curl/curl.h. It remains used in feature checks by both autotools and
cmake; to be reviewed in a future step.

Copilot AI review requested due to automatic review settings July 23, 2026 10:05
@github-actions github-actions Bot added the tests label Jul 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tidies up the codebase by removing redundant system header includes from a unit test and several libcurl source files, relying on existing shared headers (notably curl_setup.h) to provide required platform types and socket definitions consistently.

Changes:

  • Remove redundant #include <sys/types.h> blocks from several lib/vtls sources and lib/file.c.
  • Remove redundant #include <sys/types.h> / #include <sys/socket.h> blocks from tests/unit/unit1961.c.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/unit/unit1961.c Drops redundant system includes; required platform headers are already pulled via unitcheck.hfirst.hcurl_setup.h.
lib/vtls/vtls.c Removes redundant sys/types.h include in favor of curl_setup.h’s common header set.
lib/vtls/vtls_scache.c Removes redundant sys/types.h include; curl_setup.h already provides it when available.
lib/vtls/vtls_config.c Removes redundant sys/types.h include; keeps includes minimal and consistent with other vtls sources.
lib/file.c Removes redundant sys/types.h include; relies on curl_setup.h for platform type definitions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings July 23, 2026 10:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

lib/curl_setup.h:833

  • After removing the early <sys/types.h> include, curl_setup.h should still include <sys/types.h> (and do so after config headers, but before <sys/stat.h> which can depend on it). Otherwise code that relied on curl_setup.h to provide off_t/size_t-related typedefs may break.
#include <time.h>
#include <errno.h>

#include <sys/stat.h>

Comment thread lib/curl_setup.h Outdated
vszakats added 5 commits July 23, 2026 14:21
"`<sys/types.h>` is now included before the configuration headers
(`curl_config.h` / `config-*.h`). Some configs set feature macros like
`_FILE_OFFSET_BITS` (e.g. `config-win32.h` for MinGW) that must be
defined before including system headers like `<sys/types.h>` to get
correct typedefs (notably `off_t`). Including `<sys/types.h>` this early
can lock in the wrong definitions.

This issue also appears on line 830 of the same file."
Copilot AI review requested due to automatic review settings July 23, 2026 12:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

lib/curl_setup.h:510

  • curl_setup.h now includes <sys/types.h> unconditionally here, but the file already includes it under #ifdef __APPLE__ near the top. This introduces a redundant double-include on Apple and also bypasses the existing HAVE_SYS_TYPES_H feature check that other source files still use for portability.
#include <limits.h>
#include <sys/types.h>

Copilot AI review requested due to automatic review settings July 23, 2026 12:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comment thread lib/curl_setup.h
/* Include after setting system macros that may affect type sizes
(e.g. 'off_t' or 'time_t'), or suppress warnings
(e.g. '_CRT_SECURE_NO_WARNINGS`), but before including sys/stat.h */
#include <sys/types.h>

@vszakats vszakats Jul 23, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong, it was already included unconditionally via curl/curl.h:

curl/include/curl/curl.h

Lines 73 to 74 in 8734b08

/* The include stuff here below is mainly for time_t! */
#include <sys/types.h>

The __APPLE__ check is overkill, the redundant include was pre-existing and also benign. (and a tough challenge to avoid is possible at all)

Comment thread lib/curl_setup.h
@vszakats vszakats closed this in ebc5212 Jul 25, 2026
@vszakats
vszakats deleted the dropincludes branch July 25, 2026 09:37
vszakats added a commit that referenced this pull request Jul 30, 2026
- schannel: drop redundant parentheses.
- os400sys: drop redundant includes.
  Follow-up to ebc5212 #22374
- pytest: replace `()` with `[]` to match rest of tests.
- libtests: constify some local pointers.
- libtests: drop redundant `(long)` casts.
- lib650: use `CURL_CSTRLEN()`.
  Follow-up to 59dc2bb #22424

Closes #22444
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