Source: Add cm_fileno wrapper

And use it where appropriate.
stage/master/nightly/2023/08/09
Kyle Edwards 2023-08-04 14:08:17 -04:00
parent 21edd5af1f
commit fbdb1fd843
5 changed files with 34 additions and 14 deletions

View File

@ -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

15
Source/cm_fileno.cxx Normal file
View File

@ -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);
}

7
Source/cm_fileno.hxx Normal file
View File

@ -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);

View File

@ -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();

View File

@ -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();