Skip to content

tidy-up: C header use - #999

Closed
vszakats wants to merge 20 commits into
libssh2:masterfrom
vszakats:header-tidy
Closed

vszakats wants to merge 20 commits into
libssh2:masterfrom
vszakats:header-tidy

Conversation

@vszakats

@vszakats vszakats commented Apr 25, 2023 •

Copy link
Copy Markdown
Member
  • drop unused or duplicate C headers.
  • add missing ones (that worked by chance).
    (string.h, stdlib.h)
  • mention the functions that need certain headers.
  • move some headers from crypto header to crypto C source.
  • reorder headers in some places.
  • simplify the #if tree for sys/select.h in libssh2_priv.h.
  • move scp-specific macros next to their header to scp.c
    Follow-up to 5db836b

Closes #999

@vszakats vszakats added the build label Apr 25, 2023
@vszakats
vszakats force-pushed the header-tidy branch 5 times, most recently from 8c1a60d to 200c554 Compare April 27, 2023 09:39
@vszakats vszakats changed the title tidy-up: header use tidy-up: C header use Apr 27, 2023
@vszakats
vszakats deleted the header-tidy branch April 27, 2023 14:32
agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
- drop unused or duplicate C headers.
- add missing ones (that worked by chance).
  (`string.h`, `stdlib.h`)
- mention the functions that need certain headers.
- move some headers from crypto header to crypto C source.
- reorder headers in some places.
- simplify the #if tree for `sys/select.h` in `libssh2_priv.h`.
- move scp-specific macros next to their header to `scp.c`
  Follow-up to 5db836b

Closes libssh2#999
vszakats added a commit to vszakats/libssh2 that referenced this pull request Apr 7, 2026
Follow-up to a683133 libssh2#999

Also causing this strict ISO builds:
```
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:67:20: error: variable has incomplete type 'struct timeval'
   67 |     struct timeval tv;
      |                    ^
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:67:12: note: forward declaration of 'struct timeval'
   67 |     struct timeval tv;
      |            ^
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:249:9: error: use of undeclared identifier 'fd_set'
  249 |         fd_set fds;
      |         ^
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:250:9: error: call to undeclared function 'FD_ZERO'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  250 |         FD_ZERO(&fds);
      |         ^
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:250:18: error: use of undeclared identifier 'fds'
  250 |         FD_ZERO(&fds);
      |                  ^
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:255:9: error: call to undeclared function 'FD_SET'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  255 |         FD_SET(forwardsock, &fds);
      |         ^
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:255:30: error: use of undeclared identifier 'fds'
  255 |         FD_SET(forwardsock, &fds);
      |                              ^
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:261:14: error: call to undeclared function 'select'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  261 |         rc = select((int)(forwardsock + 1), &fds, NULL, NULL, &tv);
      |              ^
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:261:46: error: use of undeclared identifier 'fds'
  261 |         rc = select((int)(forwardsock + 1), &fds, NULL, NULL, &tv);
      |                                              ^
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:270:18: error: call to undeclared function 'FD_ISSET'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  270 |         if(rc && FD_ISSET(forwardsock, &fds)) {
      |                  ^
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:270:41: error: use of undeclared identifier 'fds'
  270 |         if(rc && FD_ISSET(forwardsock, &fds)) {
      |                                         ^
10 errors generated.
```
https://github.com/libssh2/libssh2/actions/runs/24107290427/job/70333563236
vszakats added a commit to vszakats/libssh2 that referenced this pull request Apr 8, 2026
Follow-up to a683133 libssh2#999

Also causing this strict ISO builds:
```
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:67:20: error: variable has incomplete type 'struct timeval'
   67 |     struct timeval tv;
      |                    ^
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:67:12: note: forward declaration of 'struct timeval'
   67 |     struct timeval tv;
      |            ^
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:249:9: error: use of undeclared identifier 'fd_set'
  249 |         fd_set fds;
      |         ^
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:250:9: error: call to undeclared function 'FD_ZERO'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  250 |         FD_ZERO(&fds);
      |         ^
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:250:18: error: use of undeclared identifier 'fds'
  250 |         FD_ZERO(&fds);
      |                  ^
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:255:9: error: call to undeclared function 'FD_SET'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  255 |         FD_SET(forwardsock, &fds);
      |         ^
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:255:30: error: use of undeclared identifier 'fds'
  255 |         FD_SET(forwardsock, &fds);
      |                              ^
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:261:14: error: call to undeclared function 'select'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  261 |         rc = select((int)(forwardsock + 1), &fds, NULL, NULL, &tv);
      |              ^
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:261:46: error: use of undeclared identifier 'fds'
  261 |         rc = select((int)(forwardsock + 1), &fds, NULL, NULL, &tv);
      |                                              ^
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:270:18: error: call to undeclared function 'FD_ISSET'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  270 |         if(rc && FD_ISSET(forwardsock, &fds)) {
      |                  ^
/home/runner/work/libssh2/libssh2/example/direct_tcpip.c:270:41: error: use of undeclared identifier 'fds'
  270 |         if(rc && FD_ISSET(forwardsock, &fds)) {
      |                                         ^
10 errors generated.
```
https://github.com/libssh2/libssh2/actions/runs/24107290427/job/70333563236
vszakats added a commit that referenced this pull request Apr 8, 2026
Note: On Linux with glibc, ISO mode also requires setting
the `_DEFAULT_SOURCE` macro to enable necessary POSIX features when
building tests (for `popen()`, `pclose()` and examples (for `fileno()`,
`tcsetattr()`). On other platforms and environments it may require
something else.

- replace `strdup()` with local implementation.
- replace `getline()` with C89 `fgets()`.
- replace `u_char`, `u_int` with C89 types.
- fix type mismatches in chacha-poly1305 code.
- silence `-Wno-format-nonliteral` locally. The global method was not
  effective (like because it was overridden by `-Wformat=2`) and caused
  these warnings when building in C89 mode.
- GHA: test ISO C89 in zlib-enabled Linux jobs with all crypto backends.
- fix formatting nits along the way.
- configure, cmake: silence silly `-Wno-comma` warnings with clang in
  C89 mode.
- examples: include `select.h` again, where `select()` is used. As its
  canonical header. Seen required on Linux glibc non-GNU/ISO builds.
  Follow-up to a683133 #999

Assisted-by: Raul Tambre
Ref: #1674

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant