make QProcessEnvironment::systemEnvironment() encoding-safe
on unix, don't do the roundtrip over unicode. on windows, use the WinAPI unicode environment instead of the 8-bit CRT environment. Reviewed-by: thiago Reviewed-by: dt (cherry picked from commit 60194ad0ea68d7c82b4729119d122dcfeb909842)
This commit is contained in:
parent
9ff8d1c34a
commit
5a4df43c71
@ -2301,6 +2301,8 @@ QStringList QProcess::systemEnvironment()
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QProcessEnvironment QProcessEnvironment::systemEnvironment()
|
||||
|
||||
\since 4.6
|
||||
|
||||
\brief The systemEnvironment function returns the environment of
|
||||
@ -2316,21 +2318,6 @@ QStringList QProcess::systemEnvironment()
|
||||
|
||||
\sa QProcess::systemEnvironment()
|
||||
*/
|
||||
QProcessEnvironment QProcessEnvironment::systemEnvironment()
|
||||
{
|
||||
QProcessEnvironment env;
|
||||
const char *entry;
|
||||
for (int count = 0; (entry = environ[count]); ++count) {
|
||||
const char *equal = strchr(entry, '=');
|
||||
if (!equal)
|
||||
continue;
|
||||
|
||||
QByteArray name(entry, equal - entry);
|
||||
QByteArray value(equal + 1);
|
||||
env.insert(QString::fromLocal8Bit(name), QString::fromLocal8Bit(value));
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
/*!
|
||||
\typedef Q_PID
|
||||
|
@ -467,6 +467,23 @@ bool QProcessPrivate::createChannel(Channel &channel)
|
||||
}
|
||||
}
|
||||
|
||||
QProcessEnvironment QProcessEnvironment::systemEnvironment()
|
||||
{
|
||||
QProcessEnvironment env;
|
||||
const char *entry;
|
||||
for (int count = 0; (entry = environ[count]); ++count) {
|
||||
const char *equal = strchr(entry, '=');
|
||||
if (!equal)
|
||||
continue;
|
||||
|
||||
QByteArray name(entry, equal - entry);
|
||||
QByteArray value(equal + 1);
|
||||
env.d->hash.insert(QProcessEnvironmentPrivate::Key(name),
|
||||
QProcessEnvironmentPrivate::Value(value));
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
static char **_q_dupEnvironment(const QProcessEnvironmentPrivate::Hash &environment, int *envc)
|
||||
{
|
||||
*envc = 0;
|
||||
|
@ -278,6 +278,26 @@ static QString qt_create_commandline(const QString &program, const QStringList &
|
||||
return args;
|
||||
}
|
||||
|
||||
QProcessEnvironment QProcessEnvironment::systemEnvironment()
|
||||
{
|
||||
QProcessEnvironment env;
|
||||
// Calls to setenv() affect the low-level environment as well.
|
||||
// This is not the case the other way round.
|
||||
wchar_t *envStrings = GetEnvironmentStringsW();
|
||||
for (const wchar_t *entry = envStrings; *entry; ) {
|
||||
int entryLen = wcslen(entry);
|
||||
if (const wchar_t *equal = wcschr(entry, L'=')) {
|
||||
int nameLen = equal - entry;
|
||||
QString name = QString::fromWCharArray(entry, nameLen);
|
||||
QString value = QString::fromWCharArray(equal + 1, entryLen - nameLen - 1);
|
||||
env.d->hash.insert(QProcessEnvironmentPrivate::Key(name), value);
|
||||
}
|
||||
entry += entryLen + 1;
|
||||
}
|
||||
FreeEnvironmentStrings(envStrings);
|
||||
return env;
|
||||
}
|
||||
|
||||
static QByteArray qt_create_environment(const QProcessEnvironmentPrivate::Hash &environment)
|
||||
{
|
||||
QByteArray envlist;
|
||||
|
Loading…
x
Reference in New Issue
Block a user