diff options
author | Jake Petroules <jake.petroules@qt.io> | 2016-12-14 20:13:29 -0800 |
---|---|---|
committer | Jake Petroules <jake.petroules@qt.io> | 2016-12-16 09:14:24 +0000 |
commit | b9f56751cb926b6b4a6dd8ba2524394dcade9eef (patch) | |
tree | 9450b9d32941f470d51d02980c75b32cae6121b6 /src/corelib/io/qprocess_win.cpp | |
parent | 66c2b87547e29a8c31377b6cac959a7d3bd6076b (diff) |
Introduce a configure option for QProcessEnvironment
This decouples QProcess and QProcessEnvironment, since the latter may
actually be available on platforms where the former is not.
Change-Id: I3dc799ffdf94486b64143ed01a369897fff44a96
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qprocess_win.cpp')
-rw-r--r-- | src/corelib/io/qprocess_win.cpp | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp index 8579db1694..fcdf13fddb 100644 --- a/src/corelib/io/qprocess_win.cpp +++ b/src/corelib/io/qprocess_win.cpp @@ -38,6 +38,7 @@ ** ****************************************************************************/ +//#define QPROCESS_DEBUG #include "qprocess.h" #include "qprocess_p.h" #include "qwindowspipereader_p.h" @@ -59,11 +60,35 @@ #define PIPE_REJECT_REMOTE_CLIENTS 0x08 #endif -#ifndef QT_NO_PROCESS - QT_BEGIN_NAMESPACE -//#define QPROCESS_DEBUG +#if QT_CONFIG(processenvironment) + +QProcessEnvironment QProcessEnvironment::systemEnvironment() +{ + QProcessEnvironment env; + // Calls to setenv() affect the low-level environment as well. + // This is not the case the other way round. + if (wchar_t *envStrings = GetEnvironmentStringsW()) { + for (const wchar_t *entry = envStrings; *entry; ) { + const int entryLen = int(wcslen(entry)); + // + 1 to permit magic cmd variable names starting with = + if (const wchar_t *equal = wcschr(entry + 1, 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; + } + FreeEnvironmentStringsW(envStrings); + } + return env; +} + +#endif // QT_CONFIG(processenvironment) + +#if QT_CONFIG(process) static void qt_create_pipe(Q_PIPE *pipe, bool isInputPipe) { @@ -369,28 +394,6 @@ 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. - if (wchar_t *envStrings = GetEnvironmentStringsW()) { - for (const wchar_t *entry = envStrings; *entry; ) { - const int entryLen = int(wcslen(entry)); - // + 1 to permit magic cmd variable names starting with = - if (const wchar_t *equal = wcschr(entry + 1, 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; - } - FreeEnvironmentStringsW(envStrings); - } - return env; -} - static QByteArray qt_create_environment(const QProcessEnvironmentPrivate::Hash &environment) { QByteArray envlist; @@ -891,6 +894,6 @@ bool QProcessPrivate::startDetached(const QString &program, const QStringList &a return success; } -QT_END_NAMESPACE - #endif // QT_NO_PROCESS + +QT_END_NAMESPACE |