Skip to content

Commit

Permalink
corelib: Restore qAppFileName on OS/2.
Browse files Browse the repository at this point in the history
This is needed for QProcess. Using QCoreApplication::applicationFilePath
is not correct as it requires a QCoreApplication instance which is not
required by QProcess itself. While we could still make it work on OS/2
but it's not safe too because the value returned by this method may be
changed by QCoreApplicationPrivate::setApplicationFilePath to an
arbitrary value while QProcess needs a path to the real EXE image.
  • Loading branch information
dmik committed Dec 17, 2018
1 parent cafa8fe commit 25df848
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/corelib/io/qprocess_os2.cpp
Expand Up @@ -95,6 +95,9 @@ QT_END_NAMESPACE

QT_BEGIN_NAMESPACE

// defined in qcoreapplication.cpp
extern QString qAppFileName();

#if QT_CONFIG(process)

// NOTE: Copied over from qprocess_unix.cpp.
Expand Down Expand Up @@ -945,7 +948,7 @@ static int qt_startProcess(const QString &program, const QStringList &arguments,
// morphing from VIO to PM which doesn't cancel the fact that we
// are VIO from the OS/2 loader's POV.
ULONG flags;
arc = DosQueryAppType(QFile::encodeName(QCoreApplication::applicationFilePath()), &flags);
arc = DosQueryAppType(QFile::encodeName(qAppFileName()), &flags);
if (arc == NO_ERROR && (flags & 0x7) != FAPPTYP_WINDOWAPI) {
// we are originally not the PM application and thus DosExecPgm()
// won't be able to start PM applications directly (note that the
Expand Down
30 changes: 18 additions & 12 deletions src/corelib/kernel/qcoreapplication.cpp
Expand Up @@ -2213,6 +2213,23 @@ QString QCoreApplication::applicationDirPath()
return d->cachedApplicationDirPath;
}

#ifdef Q_OS_OS2
Q_CORE_EXPORT QString qAppFileName()
{
char appPath[PATH_MAX + 1];
if (_execname(appPath, sizeof(appPath)) == 0) {
// _execname returns the uppercased path, try to get the real case
char *path = appPath;
char realAppPath[PATH_MAX + 1];
if (_realrealpath(appPath, realAppPath, sizeof(realAppPath)))
path = realAppPath;
return QFile::decodeName(path);
}

return QString();
}
#endif

/*!
Returns the file path of the application executable.
Expand Down Expand Up @@ -2249,7 +2266,7 @@ QString QCoreApplication::applicationFilePath()
if (QCoreApplicationPrivate::cachedApplicationFilePath)
return *QCoreApplicationPrivate::cachedApplicationFilePath;

#if defined(Q_OS_WIN)
#if defined(Q_OS_DOSLIKE)
QCoreApplicationPrivate::setApplicationFilePath(QFileInfo(qAppFileName()).filePath());
return *QCoreApplicationPrivate::cachedApplicationFilePath;
#elif defined(Q_OS_MAC)
Expand All @@ -2261,17 +2278,6 @@ QString QCoreApplication::applicationFilePath()
return *QCoreApplicationPrivate::cachedApplicationFilePath;
}
}
#elif defined(Q_OS_OS2)
char appPath[PATH_MAX + 1];
if (_execname(appPath, sizeof(appPath)) == 0) {
// _execname returns the uppercased path, try to get the real case
char *path = appPath;
char realAppPath[PATH_MAX + 1];
if (_realrealpath(appPath, realAppPath, sizeof(realAppPath)))
path = realAppPath;
QCoreApplicationPrivate::setApplicationFilePath(QFileInfo(QFile::decodeName(path)).canonicalFilePath());
return *QCoreApplicationPrivate::cachedApplicationFilePath;
}
#endif
#if defined( Q_OS_UNIX )
# if defined(Q_OS_LINUX) && (!defined(Q_OS_ANDROID) || defined(Q_OS_ANDROID_EMBEDDED))
Expand Down

0 comments on commit 25df848

Please sign in to comment.