summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2011-04-21 21:30:34 +0200
committerOlivier Goffart <olivier.goffart@nokia.com>2011-05-10 12:54:52 +0200
commit5a4df43c71e7a7f45248a7f8cadd7f8b7c09500c (patch)
treeeb700e2734dcfc0fc54280afcff6c72027821129 /src
parent9ff8d1c34a74bd852a7eb2016b46ab2904340b05 (diff)
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)
Diffstat (limited to 'src')
-rw-r--r--src/corelib/io/qprocess.cpp17
-rw-r--r--src/corelib/io/qprocess_unix.cpp17
-rw-r--r--src/corelib/io/qprocess_win.cpp20
3 files changed, 39 insertions, 15 deletions
diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp
index 80e0b0f36f..9ce9fd855c 100644
--- a/src/corelib/io/qprocess.cpp
+++ b/src/corelib/io/qprocess.cpp
@@ -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
diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp
index 7edefd3820..4e50bc546b 100644
--- a/src/corelib/io/qprocess_unix.cpp
+++ b/src/corelib/io/qprocess_unix.cpp
@@ -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;
diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp
index 82043a5c06..7739bbdab9 100644
--- a/src/corelib/io/qprocess_win.cpp
+++ b/src/corelib/io/qprocess_win.cpp
@@ -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;