mirror of
https://github.com/LibreOffice/core.git
synced 2025-08-15 20:47:46 +00:00
Simplify a bit
WinLaunchChild takes the same kind of argv as execv, terminated by a null pointer; so no need to pass argc. Change-Id: I280c8da0c613a7d0d1a208831a87f0e4648719f8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179952 Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Tested-by: Jenkins
This commit is contained in:
@ -126,17 +126,14 @@ static wchar_t* ArgToString(wchar_t *d, const wchar_t *s)
|
||||
/**
|
||||
* Creates a command line from a list of arguments. The returned
|
||||
* string is allocated with "malloc" and should be "free"d.
|
||||
*
|
||||
* argv is UTF8
|
||||
*/
|
||||
wchar_t*
|
||||
MakeCommandLine(int argc, wchar_t **argv)
|
||||
static wchar_t* MakeCommandLine(wchar_t **argv)
|
||||
{
|
||||
int i;
|
||||
int len = 0;
|
||||
|
||||
// The + 1 of the last argument handles the allocation for null termination
|
||||
for (i = 0; i < argc && argv[i]; ++i)
|
||||
for (i = 0; argv[i]; ++i)
|
||||
len += ArgStrLen(argv[i]) + 1;
|
||||
|
||||
// Protect against callers that pass 0 arguments
|
||||
@ -148,10 +145,10 @@ MakeCommandLine(int argc, wchar_t **argv)
|
||||
return nullptr;
|
||||
|
||||
wchar_t *c = s;
|
||||
for (i = 0; i < argc && argv[i]; ++i)
|
||||
for (i = 0; argv[i]; ++i)
|
||||
{
|
||||
c = ArgToString(c, argv[i]);
|
||||
if (i + 1 != argc)
|
||||
if (argv[i + 1])
|
||||
{
|
||||
*c = ' ';
|
||||
++c;
|
||||
@ -165,7 +162,6 @@ MakeCommandLine(int argc, wchar_t **argv)
|
||||
|
||||
BOOL
|
||||
WinLaunchChild(const wchar_t *exePath,
|
||||
int argc,
|
||||
wchar_t **argv,
|
||||
HANDLE userToken,
|
||||
HANDLE *hProcess)
|
||||
@ -173,7 +169,7 @@ WinLaunchChild(const wchar_t *exePath,
|
||||
wchar_t *cl;
|
||||
bool ok;
|
||||
|
||||
cl = MakeCommandLine(argc, argv);
|
||||
cl = MakeCommandLine(argv);
|
||||
if (!cl)
|
||||
{
|
||||
return FALSE;
|
||||
|
@ -175,7 +175,7 @@ void createStr(const OUString& rStr, CharT** pArgs, size_t i)
|
||||
pArgs[i] = pStr;
|
||||
}
|
||||
|
||||
CharT** createCommandLine(OUString const & argv0, int * argc)
|
||||
CharT** createCommandLine(OUString const & argv0)
|
||||
{
|
||||
OUString aInstallDir = Updater::getInstallationPath();
|
||||
|
||||
@ -238,7 +238,6 @@ CharT** createCommandLine(OUString const & argv0, int * argc)
|
||||
|
||||
pArgs[nArgs - 1] = nullptr;
|
||||
|
||||
*argc = nArgs - 1;
|
||||
return pArgs;
|
||||
}
|
||||
|
||||
@ -305,8 +304,7 @@ bool update()
|
||||
OUString aUpdaterPath = getPathFromURL(aTempDirURL + "/" + OUString::fromUtf8(pUpdaterName));
|
||||
|
||||
Updater::log("Calling the updater with parameters: ");
|
||||
int argc;
|
||||
CharT** pArgs = createCommandLine(aUpdaterPath, &argc);
|
||||
CharT** pArgs = createCommandLine(aUpdaterPath);
|
||||
|
||||
bool bSuccess = true;
|
||||
const char* pUpdaterTestReplace = std::getenv("LIBO_UPDATER_TEST_REPLACE");
|
||||
@ -320,7 +318,7 @@ bool update()
|
||||
bSuccess = false;
|
||||
}
|
||||
#elif defined(_WIN32)
|
||||
bSuccess = WinLaunchChild(o3tl::toW(aUpdaterPath.getStr()), argc, pArgs);
|
||||
bSuccess = WinLaunchChild(o3tl::toW(aUpdaterPath.getStr()), pArgs);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
|
@ -15,13 +15,12 @@
|
||||
|
||||
/**
|
||||
* Launch a child process with the specified arguments.
|
||||
* argv must be terminated by a null pointer, similar to execv.
|
||||
* @note argv[0] is ignored
|
||||
*/
|
||||
BOOL
|
||||
WinLaunchChild(const wchar_t *exePath, int argc,
|
||||
WinLaunchChild(const wchar_t *exePath,
|
||||
wchar_t **argv, HANDLE userToken = nullptr,
|
||||
HANDLE *hProcess = nullptr);
|
||||
|
||||
wchar_t* MakeCommandLine(int argc, wchar_t **argv);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user