summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/CMakeLists.txt2
-rw-r--r--Source/cm_fileno.cxx15
-rw-r--r--Source/cm_fileno.hxx7
-rw-r--r--Source/cmake.cxx19
-rw-r--r--Tests/CMakeLib/testUVProcessChain.cxx5
5 files changed, 34 insertions, 14 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index 6581e0d..3690357 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -738,6 +738,8 @@ add_library(
cm_utf8.c
cm_codecvt.hxx
cm_codecvt.cxx
+ cm_fileno.hxx
+ cm_fileno.cxx
cmDuration.h
cmDuration.cxx
diff --git a/Source/cm_fileno.cxx b/Source/cm_fileno.cxx
new file mode 100644
index 0000000..a40c5ca
--- /dev/null
+++ b/Source/cm_fileno.cxx
@@ -0,0 +1,15 @@
+/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+ file Copyright.txt or https://cmake.org/licensing for details. */
+#if !defined(_POSIX_C_SOURCE) && !defined(_WIN32) && !defined(__sun) && \
+ !defined(__OpenBSD__)
+/* POSIX APIs are needed */
+// NOLINTNEXTLINE(bugprone-reserved-identifier)
+# define _POSIX_C_SOURCE 200809L
+#endif
+
+#include "cm_fileno.hxx"
+
+int cm_fileno(FILE* f)
+{
+ return fileno(f);
+}
diff --git a/Source/cm_fileno.hxx b/Source/cm_fileno.hxx
new file mode 100644
index 0000000..3abcdcf
--- /dev/null
+++ b/Source/cm_fileno.hxx
@@ -0,0 +1,7 @@
+/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+ file Copyright.txt or https://cmake.org/licensing for details. */
+#pragma once
+
+#include <cstdio>
+
+int cm_fileno(FILE* f);
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index b8ebca5..ae96cf9 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -23,14 +23,11 @@
#include <cmext/algorithm>
#include <cmext/string_view>
-#if !defined(CMAKE_BOOTSTRAP) && !defined(_WIN32)
-# include <unistd.h>
-#endif
-
#include "cmsys/FStream.hxx"
#include "cmsys/Glob.hxx"
#include "cmsys/RegularExpression.hxx"
+#include "cm_fileno.hxx"
#include "cm_sys_stat.h"
#include "cmBuildOptions.h"
@@ -3913,15 +3910,11 @@ std::function<int()> cmake::BuildWorkflowStep(
const std::vector<std::string>& args)
{
cmUVProcessChainBuilder builder;
- builder
- .AddCommand(args)
-# ifdef _WIN32
- .SetExternalStream(cmUVProcessChainBuilder::Stream_OUTPUT, _fileno(stdout))
- .SetExternalStream(cmUVProcessChainBuilder::Stream_ERROR, _fileno(stderr));
-# else
- .SetExternalStream(cmUVProcessChainBuilder::Stream_OUTPUT, STDOUT_FILENO)
- .SetExternalStream(cmUVProcessChainBuilder::Stream_ERROR, STDERR_FILENO);
-# endif
+ builder.AddCommand(args)
+ .SetExternalStream(cmUVProcessChainBuilder::Stream_OUTPUT,
+ cm_fileno(stdout))
+ .SetExternalStream(cmUVProcessChainBuilder::Stream_ERROR,
+ cm_fileno(stderr));
return [builder]() -> int {
auto chain = builder.Start();
chain.Wait();
diff --git a/Tests/CMakeLib/testUVProcessChain.cxx b/Tests/CMakeLib/testUVProcessChain.cxx
index fc84bb0..aab084b 100644
--- a/Tests/CMakeLib/testUVProcessChain.cxx
+++ b/Tests/CMakeLib/testUVProcessChain.cxx
@@ -12,6 +12,8 @@
#include <cm3p/uv.h>
+#include "cm_fileno.hxx"
+
#include "cmGetPipes.h"
#include "cmStringAlgorithms.h"
#include "cmUVHandlePtr.h"
@@ -630,7 +632,8 @@ bool testUVProcessChainInputFile(const char* helperCommand)
cmUVProcessChainBuilder builder;
builder.AddCommand({ helperCommand, "dedup" })
- .SetExternalStream(cmUVProcessChainBuilder::Stream_INPUT, fileno(f.get()))
+ .SetExternalStream(cmUVProcessChainBuilder::Stream_INPUT,
+ cm_fileno(f.get()))
.SetBuiltinStream(cmUVProcessChainBuilder::Stream_OUTPUT);
auto chain = builder.Start();