Skip to content

Use Windows system headers for POSIX read()/write()/getpid() (rebased #45)#63

Merged
karypis merged 1 commit into
masterfrom
fix/issue-45-windows-posix-io
May 30, 2026
Merged

Use Windows system headers for POSIX read()/write()/getpid() (rebased #45)#63
karypis merged 1 commit into
masterfrom
fix/issue-45-windows-posix-io

Conversation

@karypis
Copy link
Copy Markdown
Contributor

@karypis karypis commented May 30, 2026

What & why

On Windows, the POSIX read()/write() functions are declared in <io.h> and
getpid() in <process.h>. They are not pulled in by GKlib's Windows include
path, so modern Clang/clang-cl — which treat implicit declarations as hard
errors (-Wimplicit-function-declaration) — fail to compile src/io.c:

src/io.c(63,18): error: call to undeclared function 'read'
src/io.c(84,17): error: call to undeclared function 'write'

This is now reproduced by our own CI (the clang-cl Ninja and -TClangCL
MSBuild jobs) after the CI workflow was added in #46.

Change

  • In the __MSC__ branch of include/gk_arch.h, include <io.h> (declares
    read/write) and <process.h> (declares getpid), and typedef int pid_t;.
  • Remove the bundled win32/adapt.{c,h} shim, which existed only to provide a
    getpid() wrapper via <windows.h>; <process.h> supplies it directly. The
    one in-tree getpid() caller (src/memory.c) is unaffected.
  • Drop the shim from target_sources in CMakeLists.txt.

Net +4 / −30 (a shim removal).

Provenance

This is a rebased version of #45 by @MarijnS95, re-applied onto current master
so it composes with the _MSC_VER >= 1600 stdint guard added by #59 and runs
through the new CI. Original authorship preserved via Co-authored-by.

Validation

  • Non-Windows build (cmake -DNO_X86=ON): clean, 0 warnings / 0 errors — the
    #else path is untouched.
  • Windows: validated by this PR's CI run (the previously-failing io.c
    read/write errors should clear). Other compilers' pre-existing deprecation
    / unused-variable warnings remain but are non-fatal.

Closes #45.

On Windows, read()/write() are declared in <io.h> and getpid() in <process.h>; modern Clang/clang-cl treat the missing declarations as hard errors (-Wimplicit-function-declaration), breaking src/io.c. Include those headers in the __MSC__ branch of gk_arch.h and drop the bundled win32/adapt.{c,h} shim (which only wrapped getpid() via <windows.h>) along with its target_sources entry.

Co-authored-by: Marijn Suijten <marijn@traverseresearch.nl>

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@karypis karypis force-pushed the fix/issue-45-windows-posix-io branch from 01e20ef to e8cb336 Compare May 30, 2026 18:55
@karypis karypis merged commit 4fb2907 into master May 30, 2026
12 checks passed
@karypis karypis deleted the fix/issue-45-windows-posix-io branch May 30, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant