From 0ff2676a2594aa6a26de7232e605640c28021f28 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Mon, 6 Oct 2025 11:13:53 +0100 Subject: [PATCH] Implement getdtablecount(3) for Darwin, from Chip Davis in GitHub issue 4636. --- compat/getdtablecount.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/compat/getdtablecount.c b/compat/getdtablecount.c index 1f9a0aa7..e26d1c7b 100644 --- a/compat/getdtablecount.c +++ b/compat/getdtablecount.c @@ -18,13 +18,28 @@ #include #include +#if defined(HAVE_LIBPROC_H) +#include +#endif #include "compat.h" void fatal(const char *, ...); void fatalx(const char *, ...); -#ifdef HAVE_PROC_PID +#if defined(HAVE_LIBPROC_H) && defined(HAVE_PROC_PIDINFO) +int +getdtablecount(void) +{ + int sz; + pid_t pid = getpid(); + + sz = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, NULL, 0); + if (sz == -1) + return (0); + return (sz / PROC_PIDLISTFD_SIZE); +} +#elif defined(HAVE_PROC_PID) int getdtablecount(void) {