summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qglobal.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/global/qglobal.cpp')
-rw-r--r--src/corelib/global/qglobal.cpp42
1 files changed, 39 insertions, 3 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index 7fd9283579..67d26301a4 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -68,7 +68,7 @@
# endif
#endif
-#if defined(Q_OS_VXWORKS)
+#if defined(Q_OS_VXWORKS) && defined(_WRS_KERNEL)
# include <envLib.h>
#endif
@@ -2189,6 +2189,10 @@ bool qEnvironmentVariableIsSet(const char *varName) Q_DECL_NOEXCEPT
\a varName. It will create the variable if it does not exist. It
returns 0 if the variable could not be set.
+ Calling qputenv with an empty value removes the environment variable on
+ Windows, and makes it set (but empty) on Unix. Prefer using qunsetenv()
+ for fully portable behavior.
+
\note qputenv() was introduced because putenv() from the standard
C library was deprecated in VC2005 (and later versions). qputenv()
uses the replacement function in VC, and calls the standard C
@@ -2215,6 +2219,39 @@ bool qputenv(const char *varName, const QByteArray& value)
#endif
}
+/*!
+ \relates <QtGlobal>
+
+ This function deletes the variable \a varName from the environment.
+
+ Returns true on success.
+
+ \since 5.1
+
+ \sa qputenv(), qgetenv()
+*/
+bool qunsetenv(const char *varName)
+{
+#if defined(_MSC_VER) && _MSC_VER >= 1400
+ return _putenv_s(varName, "") == 0;
+#elif (defined(_POSIX_VERSION) && (_POSIX_VERSION-0) >= 200112L) || defined(Q_OS_BSD4)
+ // POSIX.1-2001 and BSD have unsetenv
+ return unsetenv(varName) == 0;
+#elif defined(Q_CC_MINGW)
+ // On mingw, putenv("var=") removes "var" from the environment
+ QByteArray buffer(varName);
+ buffer += '=';
+ return putenv(buffer.constData()) == 0;
+#else
+ // Fallback to putenv("var=") which will insert an empty var into the
+ // environment and leak it
+ QByteArray buffer(varName);
+ buffer += '=';
+ char *envVar = qstrdup(buffer.constData());
+ return putenv(envVar) == 0;
+#endif
+}
+
#if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD)
# if defined(Q_OS_INTEGRITY) && defined(__GHS_VERSION_NUMBER) && (__GHS_VERSION_NUMBER < 500)
@@ -2810,8 +2847,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
As a rule of thumb, \c QT_BEGIN_NAMESPACE should appear in all Qt header
and Qt source files after the last \c{#include} line and before the first
- declaration. In Qt headers using \c QT_BEGIN_HEADER, \c QT_BEGIN_NAMESPACE
- follows \c QT_BEGIN_HEADER immediately.
+ declaration.
If that rule can't be followed because, e.g., \c{#include} lines and
declarations are wildly mixed, place \c QT_BEGIN_NAMESPACE before