From 9644d46dac3aa5a6d290b7fee5fb326f37021c08 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 8 Jan 2024 17:52:05 +0100 Subject: [PATCH] add shim for closefrom to support systems without that function (glibc before 2.34) --- src/webfuse/util/authenticator.cpp | 16 ++++++++++++++++ test-src/integration/webfuse/test/process.cpp | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/webfuse/util/authenticator.cpp b/src/webfuse/util/authenticator.cpp index 579aaab..990aab9 100644 --- a/src/webfuse/util/authenticator.cpp +++ b/src/webfuse/util/authenticator.cpp @@ -4,6 +4,22 @@ #include #include +#ifndef closefrom +namespace +{ + +void closefrom(int fd) +{ + int const max_fd = sysconf(_SC_OPEN_MAX); + for(int i = fd; i < max_fd; i++) + { + close(i); + } +} + +} +#endif + namespace webfuse { diff --git a/test-src/integration/webfuse/test/process.cpp b/test-src/integration/webfuse/test/process.cpp index 2866565..86e657e 100644 --- a/test-src/integration/webfuse/test/process.cpp +++ b/test-src/integration/webfuse/test/process.cpp @@ -9,6 +9,23 @@ #include +#ifndef closefrom +namespace +{ + +void closefrom(int fd) +{ + int const max_fd = sysconf(_SC_OPEN_MAX); + for(int i = fd; i < max_fd; i++) + { + close(i); + } +} + +} +#endif + + namespace webfuse {