mirror of
https://github.com/pocoproject/poco.git
synced 2025-07-04 09:37:11 +02:00
fixes for compatibility
This commit is contained in:
parent
3b51cbdfb6
commit
3e0d788162
@ -99,8 +99,7 @@ void ProcessImpl::timesImpl(long& userTime, long& kernelTime)
|
|||||||
time.LowPart = ftUser.dwLowDateTime;
|
time.LowPart = ftUser.dwLowDateTime;
|
||||||
time.HighPart = ftUser.dwHighDateTime;
|
time.HighPart = ftUser.dwHighDateTime;
|
||||||
userTime = long(time.QuadPart / 10000000L);
|
userTime = long(time.QuadPart / 10000000L);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
userTime = kernelTime = -1;
|
userTime = kernelTime = -1;
|
||||||
}
|
}
|
||||||
@ -109,7 +108,7 @@ void ProcessImpl::timesImpl(long& userTime, long& kernelTime)
|
|||||||
|
|
||||||
static bool argNeedsEscaping(const std::string& arg)
|
static bool argNeedsEscaping(const std::string& arg)
|
||||||
{
|
{
|
||||||
bool containsQuotableChar = arg.npos != arg.find_first_of(" \t\n\v\"");
|
bool containsQuotableChar = std::string::npos != arg.find_first_of(" \t\n\v\"");
|
||||||
// Assume args that start and end with quotes are already quoted and do not require further quoting.
|
// Assume args that start and end with quotes are already quoted and do not require further quoting.
|
||||||
// There is probably code out there written before launch() escaped the arguments that does its own
|
// There is probably code out there written before launch() escaped the arguments that does its own
|
||||||
// escaping of arguments. This ensures we do not interfere with those arguments.
|
// escaping of arguments. This ensures we do not interfere with those arguments.
|
||||||
@ -124,7 +123,7 @@ static std::string escapeArg(const std::string& arg)
|
|||||||
if (argNeedsEscaping(arg))
|
if (argNeedsEscaping(arg))
|
||||||
{
|
{
|
||||||
std::string quotedArg("\"");
|
std::string quotedArg("\"");
|
||||||
for (auto it = arg.begin(); ; ++it)
|
for (std::string::const_iterator it = arg.begin(); ; ++it)
|
||||||
{
|
{
|
||||||
unsigned backslashCount = 0;
|
unsigned backslashCount = 0;
|
||||||
while (it != arg.end() && '\\' == *it)
|
while (it != arg.end() && '\\' == *it)
|
||||||
@ -137,13 +136,11 @@ static std::string escapeArg(const std::string& arg)
|
|||||||
{
|
{
|
||||||
quotedArg.append(2 * backslashCount, '\\');
|
quotedArg.append(2 * backslashCount, '\\');
|
||||||
break;
|
break;
|
||||||
}
|
} else if ('"' == *it)
|
||||||
else if ('"' == *it)
|
|
||||||
{
|
{
|
||||||
quotedArg.append(2 * backslashCount + 1, '\\');
|
quotedArg.append(2 * backslashCount + 1, '\\');
|
||||||
quotedArg.push_back('"');
|
quotedArg.push_back('"');
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
quotedArg.append(backslashCount, '\\');
|
quotedArg.append(backslashCount, '\\');
|
||||||
quotedArg.push_back(*it);
|
quotedArg.push_back(*it);
|
||||||
@ -151,8 +148,7 @@ static std::string escapeArg(const std::string& arg)
|
|||||||
}
|
}
|
||||||
quotedArg.push_back('"');
|
quotedArg.push_back('"');
|
||||||
return quotedArg;
|
return quotedArg;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return arg;
|
return arg;
|
||||||
}
|
}
|
||||||
@ -185,13 +181,11 @@ ProcessHandleImpl* ProcessImpl::launchImpl(const std::string& command, const Arg
|
|||||||
DuplicateHandle(hProc, inPipe->readHandle(), hProc, &startupInfo.hStdInput, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
DuplicateHandle(hProc, inPipe->readHandle(), hProc, &startupInfo.hStdInput, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
||||||
mustInheritHandles = true;
|
mustInheritHandles = true;
|
||||||
inPipe->close(Pipe::CLOSE_READ);
|
inPipe->close(Pipe::CLOSE_READ);
|
||||||
}
|
} else if (GetStdHandle(STD_INPUT_HANDLE))
|
||||||
else if (GetStdHandle(STD_INPUT_HANDLE))
|
|
||||||
{
|
{
|
||||||
DuplicateHandle(hProc, GetStdHandle(STD_INPUT_HANDLE), hProc, &startupInfo.hStdInput, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
DuplicateHandle(hProc, GetStdHandle(STD_INPUT_HANDLE), hProc, &startupInfo.hStdInput, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
||||||
mustInheritHandles = true;
|
mustInheritHandles = true;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
startupInfo.hStdInput = 0;
|
startupInfo.hStdInput = 0;
|
||||||
}
|
}
|
||||||
@ -200,13 +194,11 @@ ProcessHandleImpl* ProcessImpl::launchImpl(const std::string& command, const Arg
|
|||||||
{
|
{
|
||||||
DuplicateHandle(hProc, outPipe->writeHandle(), hProc, &startupInfo.hStdOutput, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
DuplicateHandle(hProc, outPipe->writeHandle(), hProc, &startupInfo.hStdOutput, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
||||||
mustInheritHandles = true;
|
mustInheritHandles = true;
|
||||||
}
|
} else if (GetStdHandle(STD_OUTPUT_HANDLE))
|
||||||
else if (GetStdHandle(STD_OUTPUT_HANDLE))
|
|
||||||
{
|
{
|
||||||
DuplicateHandle(hProc, GetStdHandle(STD_OUTPUT_HANDLE), hProc, &startupInfo.hStdOutput, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
DuplicateHandle(hProc, GetStdHandle(STD_OUTPUT_HANDLE), hProc, &startupInfo.hStdOutput, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
||||||
mustInheritHandles = true;
|
mustInheritHandles = true;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
startupInfo.hStdOutput = 0;
|
startupInfo.hStdOutput = 0;
|
||||||
}
|
}
|
||||||
@ -214,13 +206,11 @@ ProcessHandleImpl* ProcessImpl::launchImpl(const std::string& command, const Arg
|
|||||||
{
|
{
|
||||||
DuplicateHandle(hProc, errPipe->writeHandle(), hProc, &startupInfo.hStdError, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
DuplicateHandle(hProc, errPipe->writeHandle(), hProc, &startupInfo.hStdError, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
||||||
mustInheritHandles = true;
|
mustInheritHandles = true;
|
||||||
}
|
} else if (GetStdHandle(STD_ERROR_HANDLE))
|
||||||
else if (GetStdHandle(STD_ERROR_HANDLE))
|
|
||||||
{
|
{
|
||||||
DuplicateHandle(hProc, GetStdHandle(STD_ERROR_HANDLE), hProc, &startupInfo.hStdError, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
DuplicateHandle(hProc, GetStdHandle(STD_ERROR_HANDLE), hProc, &startupInfo.hStdError, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
||||||
mustInheritHandles = true;
|
mustInheritHandles = true;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
startupInfo.hStdError = 0;
|
startupInfo.hStdError = 0;
|
||||||
}
|
}
|
||||||
@ -263,8 +253,7 @@ ProcessHandleImpl* ProcessImpl::launchImpl(const std::string& command, const Arg
|
|||||||
{
|
{
|
||||||
CloseHandle(processInfo.hThread);
|
CloseHandle(processInfo.hThread);
|
||||||
return new ProcessHandleImpl(processInfo.hProcess, processInfo.dwProcessId);
|
return new ProcessHandleImpl(processInfo.hProcess, processInfo.dwProcessId);
|
||||||
}
|
} else throw SystemException("Cannot launch process", command);
|
||||||
else throw SystemException("Cannot launch process", command);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -292,8 +281,7 @@ void ProcessImpl::killImpl(PIDImpl pid)
|
|||||||
throw SystemException("cannot kill process");
|
throw SystemException("cannot kill process");
|
||||||
}
|
}
|
||||||
CloseHandle(hProc);
|
CloseHandle(hProc);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
switch (GetLastError())
|
switch (GetLastError())
|
||||||
{
|
{
|
||||||
|
@ -100,8 +100,7 @@ void ProcessImpl::timesImpl(long& userTime, long& kernelTime)
|
|||||||
time.LowPart = ftUser.dwLowDateTime;
|
time.LowPart = ftUser.dwLowDateTime;
|
||||||
time.HighPart = ftUser.dwHighDateTime;
|
time.HighPart = ftUser.dwHighDateTime;
|
||||||
userTime = long(time.QuadPart / 10000000L);
|
userTime = long(time.QuadPart / 10000000L);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
userTime = kernelTime = -1;
|
userTime = kernelTime = -1;
|
||||||
}
|
}
|
||||||
@ -110,7 +109,7 @@ void ProcessImpl::timesImpl(long& userTime, long& kernelTime)
|
|||||||
|
|
||||||
static bool argNeedsEscaping(const std::string& arg)
|
static bool argNeedsEscaping(const std::string& arg)
|
||||||
{
|
{
|
||||||
bool containsQuotableChar = arg.npos != arg.find_first_of(" \t\n\v\"");
|
bool containsQuotableChar = std::string::npos != arg.find_first_of(" \t\n\v\"");
|
||||||
// Assume args that start and end with quotes are already quoted and do not require further quoting.
|
// Assume args that start and end with quotes are already quoted and do not require further quoting.
|
||||||
// There is probably code out there written before launch() escaped the arguments that does its own
|
// There is probably code out there written before launch() escaped the arguments that does its own
|
||||||
// escaping of arguments. This ensures we do not interfere with those arguments.
|
// escaping of arguments. This ensures we do not interfere with those arguments.
|
||||||
@ -125,7 +124,7 @@ static std::string escapeArg(const std::string& arg)
|
|||||||
if (argNeedsEscaping(arg))
|
if (argNeedsEscaping(arg))
|
||||||
{
|
{
|
||||||
std::string quotedArg("\"");
|
std::string quotedArg("\"");
|
||||||
for (auto it = arg.begin(); ; ++it)
|
for (std::string::const_iterator it = arg.begin(); ; ++it)
|
||||||
{
|
{
|
||||||
unsigned backslashCount = 0;
|
unsigned backslashCount = 0;
|
||||||
while (it != arg.end() && '\\' == *it)
|
while (it != arg.end() && '\\' == *it)
|
||||||
@ -138,13 +137,11 @@ static std::string escapeArg(const std::string& arg)
|
|||||||
{
|
{
|
||||||
quotedArg.append(2 * backslashCount, '\\');
|
quotedArg.append(2 * backslashCount, '\\');
|
||||||
break;
|
break;
|
||||||
}
|
} else if ('"' == *it)
|
||||||
else if ('"' == *it)
|
|
||||||
{
|
{
|
||||||
quotedArg.append(2 * backslashCount + 1, '\\');
|
quotedArg.append(2 * backslashCount + 1, '\\');
|
||||||
quotedArg.push_back('"');
|
quotedArg.push_back('"');
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
quotedArg.append(backslashCount, '\\');
|
quotedArg.append(backslashCount, '\\');
|
||||||
quotedArg.push_back(*it);
|
quotedArg.push_back(*it);
|
||||||
@ -152,8 +149,7 @@ static std::string escapeArg(const std::string& arg)
|
|||||||
}
|
}
|
||||||
quotedArg.push_back('"');
|
quotedArg.push_back('"');
|
||||||
return quotedArg;
|
return quotedArg;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return arg;
|
return arg;
|
||||||
}
|
}
|
||||||
@ -189,13 +185,11 @@ ProcessHandleImpl* ProcessImpl::launchImpl(const std::string& command, const Arg
|
|||||||
DuplicateHandle(hProc, inPipe->readHandle(), hProc, &startupInfo.hStdInput, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
DuplicateHandle(hProc, inPipe->readHandle(), hProc, &startupInfo.hStdInput, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
||||||
mustInheritHandles = true;
|
mustInheritHandles = true;
|
||||||
inPipe->close(Pipe::CLOSE_READ);
|
inPipe->close(Pipe::CLOSE_READ);
|
||||||
}
|
} else if (GetStdHandle(STD_INPUT_HANDLE))
|
||||||
else if (GetStdHandle(STD_INPUT_HANDLE))
|
|
||||||
{
|
{
|
||||||
DuplicateHandle(hProc, GetStdHandle(STD_INPUT_HANDLE), hProc, &startupInfo.hStdInput, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
DuplicateHandle(hProc, GetStdHandle(STD_INPUT_HANDLE), hProc, &startupInfo.hStdInput, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
||||||
mustInheritHandles = true;
|
mustInheritHandles = true;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
startupInfo.hStdInput = 0;
|
startupInfo.hStdInput = 0;
|
||||||
}
|
}
|
||||||
@ -204,13 +198,11 @@ ProcessHandleImpl* ProcessImpl::launchImpl(const std::string& command, const Arg
|
|||||||
{
|
{
|
||||||
DuplicateHandle(hProc, outPipe->writeHandle(), hProc, &startupInfo.hStdOutput, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
DuplicateHandle(hProc, outPipe->writeHandle(), hProc, &startupInfo.hStdOutput, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
||||||
mustInheritHandles = true;
|
mustInheritHandles = true;
|
||||||
}
|
} else if (GetStdHandle(STD_OUTPUT_HANDLE))
|
||||||
else if (GetStdHandle(STD_OUTPUT_HANDLE))
|
|
||||||
{
|
{
|
||||||
DuplicateHandle(hProc, GetStdHandle(STD_OUTPUT_HANDLE), hProc, &startupInfo.hStdOutput, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
DuplicateHandle(hProc, GetStdHandle(STD_OUTPUT_HANDLE), hProc, &startupInfo.hStdOutput, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
||||||
mustInheritHandles = true;
|
mustInheritHandles = true;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
startupInfo.hStdOutput = 0;
|
startupInfo.hStdOutput = 0;
|
||||||
}
|
}
|
||||||
@ -218,13 +210,11 @@ ProcessHandleImpl* ProcessImpl::launchImpl(const std::string& command, const Arg
|
|||||||
{
|
{
|
||||||
DuplicateHandle(hProc, errPipe->writeHandle(), hProc, &startupInfo.hStdError, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
DuplicateHandle(hProc, errPipe->writeHandle(), hProc, &startupInfo.hStdError, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
||||||
mustInheritHandles = true;
|
mustInheritHandles = true;
|
||||||
}
|
} else if (GetStdHandle(STD_ERROR_HANDLE))
|
||||||
else if (GetStdHandle(STD_ERROR_HANDLE))
|
|
||||||
{
|
{
|
||||||
DuplicateHandle(hProc, GetStdHandle(STD_ERROR_HANDLE), hProc, &startupInfo.hStdError, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
DuplicateHandle(hProc, GetStdHandle(STD_ERROR_HANDLE), hProc, &startupInfo.hStdError, 0, TRUE, DUPLICATE_SAME_ACCESS);
|
||||||
mustInheritHandles = true;
|
mustInheritHandles = true;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
startupInfo.hStdError = 0;
|
startupInfo.hStdError = 0;
|
||||||
}
|
}
|
||||||
@ -269,8 +259,7 @@ ProcessHandleImpl* ProcessImpl::launchImpl(const std::string& command, const Arg
|
|||||||
{
|
{
|
||||||
CloseHandle(processInfo.hThread);
|
CloseHandle(processInfo.hThread);
|
||||||
return new ProcessHandleImpl(processInfo.hProcess, processInfo.dwProcessId);
|
return new ProcessHandleImpl(processInfo.hProcess, processInfo.dwProcessId);
|
||||||
}
|
} else throw SystemException("Cannot launch process", command);
|
||||||
else throw SystemException("Cannot launch process", command);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -298,8 +287,7 @@ void ProcessImpl::killImpl(PIDImpl pid)
|
|||||||
throw SystemException("cannot kill process");
|
throw SystemException("cannot kill process");
|
||||||
}
|
}
|
||||||
CloseHandle(hProc);
|
CloseHandle(hProc);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
switch (GetLastError())
|
switch (GetLastError())
|
||||||
{
|
{
|
||||||
|
@ -149,16 +149,9 @@ void ProcessTest::testLaunchEnv()
|
|||||||
|
|
||||||
void ProcessTest::testLaunchArgs()
|
void ProcessTest::testLaunchArgs()
|
||||||
{
|
{
|
||||||
#if !defined(_WIN32_WCE)
|
#if defined (_WIN32) && !defined(_WIN32_WCE)
|
||||||
std::string name("TestApp");
|
std::string name("TestApp");
|
||||||
std::string cmd;
|
std::string cmd = name;
|
||||||
|
|
||||||
#if defined(POCO_OS_FAMILY_UNIX)
|
|
||||||
cmd = "./";
|
|
||||||
cmd += name;
|
|
||||||
#else
|
|
||||||
cmd = name;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
args.push_back("-echo-args");
|
args.push_back("-echo-args");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user