From 9f1ee5906852bbb2a60c8012b792f78a457f505a Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Fri, 13 Nov 2026 14:27:04 +0900 Subject: [PATCH] Call fcntl through a non-variadic wrapper ccall cannot call a variadic C function portably. The only uses are F_GETFD and F_GETFL, which take no argument, so the wrapper takes none. Unlike capi (#494), this keeps doctest working. Co-Authored-By: Claude Opus 5.5 --- Network/Socket/Fcntl.hs | 8 ++++---- include/HsNet.h | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Network/Socket/Fcntl.hs b/Network/Socket/Fcntl.hs index 340b1c90..a443ff4a 100644 --- a/Network/Socket/Fcntl.hs +++ b/Network/Socket/Fcntl.hs @@ -34,8 +34,8 @@ setCloseOnExecIfNeeded fd = System.Posix.Internals.setCloseOnExec fd #endif #if !defined(mingw32_HOST_OS) -foreign import ccall unsafe "fcntl" - c_fcntl_read :: CSocket -> CInt -> CInt -> IO CInt +foreign import ccall unsafe "hsnet_fcntl_get" + c_fcntl_get :: CSocket -> CInt -> IO CInt #endif -- | Get the close_on_exec flag. @@ -47,7 +47,7 @@ getCloseOnExec :: CSocket -> IO Bool getCloseOnExec _ = return False #else getCloseOnExec fd = do - flags <- c_fcntl_read fd fGetFd 0 + flags <- c_fcntl_get fd fGetFd let ret = flags .&. fdCloexec return (ret /= 0) #endif @@ -69,7 +69,7 @@ getNonBlock _ = return False # endif #else getNonBlock fd = do - flags <- c_fcntl_read fd fGetFl 0 + flags <- c_fcntl_get fd fGetFl let ret = flags .&. oNonBlock return (ret /= 0) #endif diff --git a/include/HsNet.h b/include/HsNet.h index 97fda7a9..4472a338 100644 --- a/include/HsNet.h +++ b/include/HsNet.h @@ -171,6 +171,13 @@ hsnet_ready_now(int fd, int write) p.revents = 0; return poll(&p, 1, 0) > 0; } + +/* fcntl is variadic, which ccall cannot call portably; this takes no arg. */ +INLINE int +hsnet_fcntl_get(int fd, int cmd) +{ + return fcntl(fd, cmd); +} #endif #ifndef IOV_MAX