diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2021-04-23 14:11:46 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2021-04-29 19:54:37 -0700 |
commit | ccd47237ee027af64b531ba9beca9397d3cde04c (patch) | |
tree | ae6e3c912526ea3822425aab3ce5f5100b98f2ea /src/corelib/kernel | |
parent | f3446acbcdbbee9811bbcd5ca97698d04080453a (diff) |
QCoreApplication::applicationFilePath: simplify by merging some code
And by introducing a local qAppFileName() for non-Windows and non-Mac.
This merges the simplification that each OS does to the obtained file
path to a common procedure, removing differences in behavior.
Previously, some would get the canonical file path and some wouldn't.
Change-Id: I6cdea00671e8479b9c50fffd167899036eaaa23e
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r-- | src/corelib/kernel/qcoreapplication.cpp | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index bf397c14da..2e718d11fc 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -105,6 +105,8 @@ # include <langinfo.h> # include <unistd.h> # include <sys/types.h> + +# include "qcore_unix_p.h" #endif #ifdef Q_OS_VXWORKS @@ -2283,6 +2285,17 @@ QString QCoreApplication::applicationDirPath() return d->cachedApplicationDirPath; } +#if !defined(Q_OS_WIN) && !defined(Q_OS_DARWIN) // qcoreapplication_win.cpp or qcoreapplication_mac.cpp +static QString qAppFileName() +{ +# if defined(Q_OS_LINUX) && (!defined(Q_OS_ANDROID) || defined(Q_OS_ANDROID_EMBEDDED)) + return QFile::decodeName(qt_readlink("/proc/self/exe")); +# endif + + return QString(); +} +#endif + /*! Returns the file path of the application executable. @@ -2319,10 +2332,6 @@ QString QCoreApplication::applicationFilePath() if (QCoreApplicationPrivate::cachedApplicationFilePath) return *QCoreApplicationPrivate::cachedApplicationFilePath; -#if defined(Q_OS_WIN) - QCoreApplicationPrivate::setApplicationFilePath(QFileInfo(qAppFileName()).filePath()); - return *QCoreApplicationPrivate::cachedApplicationFilePath; -#elif defined(Q_OS_MAC) QString qAppFileName_str = qAppFileName(); if (!qAppFileName_str.isEmpty()) { QFileInfo fi(qAppFileName_str); @@ -2331,17 +2340,7 @@ QString QCoreApplication::applicationFilePath() return *QCoreApplicationPrivate::cachedApplicationFilePath; } } -#endif -#if defined( Q_OS_UNIX ) -# if defined(Q_OS_LINUX) && (!defined(Q_OS_ANDROID) || defined(Q_OS_ANDROID_EMBEDDED)) - // Try looking for a /proc/<pid>/exe symlink first which points to - // the absolute path of the executable - QFileInfo pfi(QStringLiteral("/proc/self/exe")); - if (pfi.exists() && pfi.isSymLink()) { - QCoreApplicationPrivate::setApplicationFilePath(pfi.canonicalFilePath()); - return *QCoreApplicationPrivate::cachedApplicationFilePath; - } -# endif + if (!arguments().isEmpty()) { QString argv0 = QFile::decodeName(arguments().at(0).toLocal8Bit()); QString absPath; @@ -2375,7 +2374,6 @@ QString QCoreApplication::applicationFilePath() } } -#endif return QString(); } |