diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2011-04-21 19:30:34 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2011-04-29 10:59:53 (GMT) |
commit | 60194ad0ea68d7c82b4729119d122dcfeb909842 (patch) | |
tree | 25c55543b3bf4c6a36f865292c21444047286148 /src | |
parent | 18f1613aa8ece72d24ac10e28f06e3db1d8ce400 (diff) | |
download | Qt-60194ad0ea68d7c82b4729119d122dcfeb909842.zip Qt-60194ad0ea68d7c82b4729119d122dcfeb909842.tar.gz Qt-60194ad0ea68d7c82b4729119d122dcfeb909842.tar.bz2 |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/io/qprocess.cpp | 17 | ||||
-rw-r--r-- | src/corelib/io/qprocess_unix.cpp | 17 | ||||
-rw-r--r-- | src/corelib/io/qprocess_win.cpp | 20 |
3 files changed, 39 insertions, 15 deletions
diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 80e0b0f..9ce9fd8 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 b79054a..451bf61 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -453,6 +453,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 82043a5..7739bbd 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; |