Skip to content

Commit 9cb7831

Browse files
committed
Fix missing declarations of "POSIX" read()/write() on Windows with Clang
When (cross?) compiling this crate to Windows (in a Rust project) using Clang 16 or newer, we're seeing these declaration errors: > cargo b --target x86_64-pc-windows-msvc warning: [email protected]: /usr/local/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/metis-sys-0.3.1/vendor/GKlib/io.c(63,18): error: call to undeclared function 'read'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] warning: [email protected]: 63 | if ((rsize = read(fd, buf, tsize)) == -1) warning: [email protected]: | ^ ... warning: [email protected]: /usr/local/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/metis-sys-0.3.1/vendor/GKlib/io.c(84,17): error: call to undeclared function 'write'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] warning: [email protected]: 84 | if ((size = write(fd, buf, tsize)) == -1) warning: [email protected]: | ^ (LIHPC-Computational-Geometry/metis-rs#43 (comment)) Now it's yet unknown (we haven't checked) if older Clang had these declarations in a header, or didn't treat this warning as error yet, but the functions are POSIX which Windows isn't required to implement. Fortunately they provide it but with a deprecation warning and a recommended replacement of `_read()` (and `_write()`), but for this `<io.h>` needs to be included: https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/posix-read https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/read The same is true for `getpid()` that commit a8e7e25 ("port to vs2017") used to provide a `win32/adapt.c/h` workaround for, but this can instead be pulled from `<process.h>` (equally with a deprecation warning, but we should probably address these all in a consistent manner instead of defining a workaround). Let's take this as a starting point and go from there.
1 parent 8bd6bad commit 9cb7831

File tree

4 files changed

+4
-34
lines changed

4 files changed

+4
-34
lines changed

CMakeLists.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,7 @@ unset(abs)
99
include(GKlibSystem.cmake)
1010

1111
include_directories(".")
12-
if(MSVC)
13-
include_directories("win32")
14-
file(GLOB win32_sources RELATIVE "win32" "*.c")
15-
else(MSVC)
16-
set(win32_sources, "")
17-
endif(MSVC)
18-
19-
add_library(GKlib ${GKlib_sources} ${win32_sources})
12+
add_library(GKlib ${GKlib_sources})
2013

2114
if(UNIX)
2215
target_link_libraries(GKlib m)

gk_arch.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
#include "gk_ms_stdint.h"
3636
#include "gk_ms_inttypes.h"
3737
#include "gk_ms_stat.h"
38-
#include "win32/adapt.h"
38+
#include <io.h>
39+
#include <process.h>
40+
typedef int pid_t;
3941
#else
4042
#ifndef SUNOS
4143
#include <stdint.h>

win32/adapt.c

Lines changed: 0 additions & 11 deletions
This file was deleted.

win32/adapt.h

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)