@@ -28,15 +28,15 @@ int common_pipe::open(const std::string& cmd, char mode)
28
28
if (!SetHandleInformation (hChildStdinWr, HANDLE_FLAG_INHERIT, 0 )) {
29
29
auto err = GetLastError ();
30
30
CloseHandle (hChildStdinRd);
31
- return err;
31
+ return report ( err, " SetHandleInformation(hChildStdinWr) " ) ;
32
32
}
33
33
34
34
// Create a pipe for the child process's output
35
35
if (!CreatePipe (&hStdin, &hStdout, &saAttr, 0 )) {
36
36
auto err = GetLastError ();
37
37
CloseHandle (hChildStdinRd);
38
38
CloseHandle (hChildStdinWr);
39
- return err;
39
+ return report ( err, " CreatePipe " ) ;
40
40
}
41
41
42
42
// Ensure the read handle to the output pipe is not inherited by child
@@ -46,7 +46,7 @@ int common_pipe::open(const std::string& cmd, char mode)
46
46
CloseHandle (hChildStdinRd);
47
47
CloseHandle (hChildStdinWr);
48
48
CloseHandle (hStdin);
49
- return err;
49
+ return report ( err, " SetHandleInformation(hStdout) " ) ;
50
50
}
51
51
52
52
// Configure STARTUPINFO structure for the new process
@@ -67,7 +67,7 @@ int common_pipe::open(const std::string& cmd, char mode)
67
67
CloseHandle (hChildStdinWr);
68
68
CloseHandle (hStdin);
69
69
CloseHandle (hStdout);
70
- return err;
70
+ return report ( err, " CreateProcess " ) ;
71
71
}
72
72
hProcess = pi.hProcess ;
73
73
hThread = pi.hThread ;
@@ -88,7 +88,7 @@ int common_pipe::open(const std::string& cmd, char mode)
88
88
CloseHandle (hStdin);
89
89
CloseHandle (pi.hProcess );
90
90
CloseHandle (pi.hThread );
91
- return err;
91
+ return report ( err, " _fdopen(_open_osfhandle) " ) ;
92
92
}
93
93
return 0 ;
94
94
}
@@ -189,12 +189,12 @@ int common_pipe::close(int *exit_code)
189
189
190
190
inline int common_pipe::report (int code, const std::string& what)
191
191
{
192
- #if defined(_MSC_VER)
193
- const auto len = strerrorlen_s (code);
194
- error_. assign (len, ' ' );
195
- strerror_s ( error_. c_str (), len+ 1 , code) ;
192
+ #ifdef __STDC_LIB_EXT1__
193
+ char buffer[ 128 ]{}; // MSVC has no strerrorlen_s
194
+ strerror_s (buffer, 128 , code); // MSVC rejects strerror
195
+ error_ = what + " : " + buffer ;
196
196
#else
197
- error_ = std::strerror (code);
197
+ error_ = what + " : " + std::strerror (code); // GCC fixed strerror and has no strerror_s
198
198
#endif
199
199
if (exceptions_)
200
200
throw std::system_error{code, std::generic_category (), what};
0 commit comments