subprocess: replace __USING_WINDOWS__ with WIN32
This commit is contained in:
1 file changed
+17
-21
+17
-21
@@ -55,16 +55,12 @@ Documentation for C++ subprocessing library.
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if (defined _MSC_VER) || (defined __MINGW32__)
|
#ifdef WIN32
|
||||||
#define __USING_WINDOWS__
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __USING_WINDOWS__
|
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#ifdef __USING_WINDOWS__
|
#ifdef WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <cwchar>
|
#include <cwchar>
|
||||||
@@ -171,7 +167,7 @@ public:
|
|||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
namespace util
|
namespace util
|
||||||
{
|
{
|
||||||
#ifdef __USING_WINDOWS__
|
#ifdef WIN32
|
||||||
inline void quote_argument(const std::wstring &argument, std::wstring &command_line,
|
inline void quote_argument(const std::wstring &argument, std::wstring &command_line,
|
||||||
bool force)
|
bool force)
|
||||||
{
|
{
|
||||||
@@ -332,7 +328,7 @@ namespace util
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef __USING_WINDOWS__
|
#ifndef WIN32
|
||||||
/*!
|
/*!
|
||||||
* Function: set_clo_on_exec
|
* Function: set_clo_on_exec
|
||||||
* Sets/Resets the FD_CLOEXEC flag on the provided file descriptor
|
* Sets/Resets the FD_CLOEXEC flag on the provided file descriptor
|
||||||
@@ -424,7 +420,7 @@ namespace util
|
|||||||
static inline
|
static inline
|
||||||
int read_atmost_n(FILE* fp, char* buf, size_t read_upto)
|
int read_atmost_n(FILE* fp, char* buf, size_t read_upto)
|
||||||
{
|
{
|
||||||
#ifdef __USING_WINDOWS__
|
#ifdef WIN32
|
||||||
return (int)fread(buf, 1, read_upto, fp);
|
return (int)fread(buf, 1, read_upto, fp);
|
||||||
#else
|
#else
|
||||||
int fd = subprocess_fileno(fp);
|
int fd = subprocess_fileno(fp);
|
||||||
@@ -497,7 +493,7 @@ namespace util
|
|||||||
return total_bytes_read;
|
return total_bytes_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __USING_WINDOWS__
|
#ifndef WIN32
|
||||||
/*!
|
/*!
|
||||||
* Function: wait_for_child_exit
|
* Function: wait_for_child_exit
|
||||||
* Waits for the process with pid `pid` to exit
|
* Waits for the process with pid `pid` to exit
|
||||||
@@ -598,7 +594,7 @@ struct input
|
|||||||
}
|
}
|
||||||
explicit input(IOTYPE typ) {
|
explicit input(IOTYPE typ) {
|
||||||
assert (typ == PIPE && "STDOUT/STDERR not allowed");
|
assert (typ == PIPE && "STDOUT/STDERR not allowed");
|
||||||
#ifndef __USING_WINDOWS__
|
#ifndef WIN32
|
||||||
std::tie(rd_ch_, wr_ch_) = util::pipe_cloexec();
|
std::tie(rd_ch_, wr_ch_) = util::pipe_cloexec();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -631,7 +627,7 @@ struct output
|
|||||||
}
|
}
|
||||||
explicit output(IOTYPE typ) {
|
explicit output(IOTYPE typ) {
|
||||||
assert (typ == PIPE && "STDOUT/STDERR not allowed");
|
assert (typ == PIPE && "STDOUT/STDERR not allowed");
|
||||||
#ifndef __USING_WINDOWS__
|
#ifndef WIN32
|
||||||
std::tie(rd_ch_, wr_ch_) = util::pipe_cloexec();
|
std::tie(rd_ch_, wr_ch_) = util::pipe_cloexec();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -663,7 +659,7 @@ struct error
|
|||||||
explicit error(IOTYPE typ) {
|
explicit error(IOTYPE typ) {
|
||||||
assert ((typ == PIPE || typ == STDOUT) && "STDERR not allowed");
|
assert ((typ == PIPE || typ == STDOUT) && "STDERR not allowed");
|
||||||
if (typ == PIPE) {
|
if (typ == PIPE) {
|
||||||
#ifndef __USING_WINDOWS__
|
#ifndef WIN32
|
||||||
std::tie(rd_ch_, wr_ch_) = util::pipe_cloexec();
|
std::tie(rd_ch_, wr_ch_) = util::pipe_cloexec();
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
@@ -738,7 +734,7 @@ private:
|
|||||||
Popen* popen_ = nullptr;
|
Popen* popen_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef __USING_WINDOWS__
|
#ifndef WIN32
|
||||||
/*!
|
/*!
|
||||||
* A helper class to Popen.
|
* A helper class to Popen.
|
||||||
* This takes care of all the fork-exec logic
|
* This takes care of all the fork-exec logic
|
||||||
@@ -882,7 +878,7 @@ public:// Yes they are public
|
|||||||
std::shared_ptr<FILE> output_ = nullptr;
|
std::shared_ptr<FILE> output_ = nullptr;
|
||||||
std::shared_ptr<FILE> error_ = nullptr;
|
std::shared_ptr<FILE> error_ = nullptr;
|
||||||
|
|
||||||
#ifdef __USING_WINDOWS__
|
#ifdef WIN32
|
||||||
HANDLE g_hChildStd_IN_Rd = nullptr;
|
HANDLE g_hChildStd_IN_Rd = nullptr;
|
||||||
HANDLE g_hChildStd_IN_Wr = nullptr;
|
HANDLE g_hChildStd_IN_Wr = nullptr;
|
||||||
HANDLE g_hChildStd_OUT_Rd = nullptr;
|
HANDLE g_hChildStd_OUT_Rd = nullptr;
|
||||||
@@ -932,7 +928,7 @@ class Popen
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
friend struct detail::ArgumentDeducer;
|
friend struct detail::ArgumentDeducer;
|
||||||
#ifndef __USING_WINDOWS__
|
#ifndef WIN32
|
||||||
friend class detail::Child;
|
friend class detail::Child;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1010,7 +1006,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
detail::Streams stream_;
|
detail::Streams stream_;
|
||||||
|
|
||||||
#ifdef __USING_WINDOWS__
|
#ifdef WIN32
|
||||||
HANDLE process_handle_;
|
HANDLE process_handle_;
|
||||||
std::future<void> cleanup_future_;
|
std::future<void> cleanup_future_;
|
||||||
#else
|
#else
|
||||||
@@ -1049,7 +1045,7 @@ inline void Popen::populate_c_argv()
|
|||||||
|
|
||||||
inline int Popen::wait() noexcept(false)
|
inline int Popen::wait() noexcept(false)
|
||||||
{
|
{
|
||||||
#ifdef __USING_WINDOWS__
|
#ifdef WIN32
|
||||||
int ret = WaitForSingleObject(process_handle_, INFINITE);
|
int ret = WaitForSingleObject(process_handle_, INFINITE);
|
||||||
|
|
||||||
// WaitForSingleObject with INFINITE should only return when process has signaled
|
// WaitForSingleObject with INFINITE should only return when process has signaled
|
||||||
@@ -1082,7 +1078,7 @@ inline int Popen::wait() noexcept(false)
|
|||||||
|
|
||||||
inline void Popen::execute_process() noexcept(false)
|
inline void Popen::execute_process() noexcept(false)
|
||||||
{
|
{
|
||||||
#ifdef __USING_WINDOWS__
|
#ifdef WIN32
|
||||||
if (exe_name_.length()) {
|
if (exe_name_.length()) {
|
||||||
this->vargs_.insert(this->vargs_.begin(), this->exe_name_);
|
this->vargs_.insert(this->vargs_.begin(), this->exe_name_);
|
||||||
this->populate_c_argv();
|
this->populate_c_argv();
|
||||||
@@ -1262,7 +1258,7 @@ namespace detail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef __USING_WINDOWS__
|
#ifndef WIN32
|
||||||
inline void Child::execute_child() {
|
inline void Child::execute_child() {
|
||||||
int sys_ret = -1;
|
int sys_ret = -1;
|
||||||
auto& stream = parent_->stream_;
|
auto& stream = parent_->stream_;
|
||||||
@@ -1329,7 +1325,7 @@ namespace detail {
|
|||||||
|
|
||||||
inline void Streams::setup_comm_channels()
|
inline void Streams::setup_comm_channels()
|
||||||
{
|
{
|
||||||
#ifdef __USING_WINDOWS__
|
#ifdef WIN32
|
||||||
util::configure_pipe(&this->g_hChildStd_IN_Rd, &this->g_hChildStd_IN_Wr, &this->g_hChildStd_IN_Wr);
|
util::configure_pipe(&this->g_hChildStd_IN_Rd, &this->g_hChildStd_IN_Wr, &this->g_hChildStd_IN_Wr);
|
||||||
this->input(util::file_from_handle(this->g_hChildStd_IN_Wr, "w"));
|
this->input(util::file_from_handle(this->g_hChildStd_IN_Wr, "w"));
|
||||||
this->write_to_child_ = subprocess_fileno(this->input());
|
this->write_to_child_ = subprocess_fileno(this->input());
|
||||||
|
|||||||
Reference in new issue
Block a user