Changeset 215 for trunk/src


Ignore:
Timestamp:
Oct 7, 2009, 9:22:41 PM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

corelib: QProcess: Implicitly prepend the path to the executable to BEGINLIBPATH to make sure DLLs are searched there first (#84).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/corelib/io/qprocess_os2.cpp

    r214 r215  
    870870        errno = ENOENT;
    871871    } else {
     872        // add the program's dir to BEGINLIBPATH to make sure the DLLs are
     873        // serached there first (no, the OS/2 loader does't do it itself)
     874        QFileInfo fullProgramInfo(QFile::decodeName(fullProgramName));
     875        QString fullPath = QDir::toNativeSeparators(fullProgramInfo.absolutePath());
     876
     877        APIRET arc;
     878        QStringList paths;
     879        char libPathBuf[4096]; // @todo isn't it too small?
     880        bool prependedLibPath = false;
     881
     882        DosQueryExtLIBPATH(libPathBuf, BEGIN_LIBPATH);
     883        Q_ASSERT(arc == NO_ERROR);
     884        if (arc == NO_ERROR) {
     885            QString path = QFile::decodeName(libPathBuf);
     886            paths = path.split(';', QString::SkipEmptyParts);
     887            if (paths.contains(fullPath, Qt::CaseInsensitive)) {
     888#if defined(QPROCESS_DEBUG)
     889                qDebug("qt_startProcess: \"%s\" is already in BEGINLIBPATH",
     890                       qPrintable(fullPath));
     891#endif
     892            } else {
     893#if defined(QPROCESS_DEBUG)
     894                qDebug("qt_startProcess: prepending \"%s\" to BEGINLIBPATH",
     895                       qPrintable(fullPath));
     896#endif
     897                prependedLibPath = true;
     898                QByteArray newLibPath = libPathBuf;
     899                newLibPath.prepend(';').prepend(QFile::encodeName(fullPath));
     900                DosSetExtLIBPATH(newLibPath, BEGIN_LIBPATH);
     901            }
     902        }
     903
     904        // finally, start the thing
    872905        pid = spawnvpe(mode, fullProgramName, argv, envv);
     906
     907        if (prependedLibPath) {
     908            // restore BEGINLIBPATH
     909            DosSetExtLIBPATH(libPathBuf, BEGIN_LIBPATH);
     910        }
    873911    }
    874912
Note: See TracChangeset for help on using the changeset viewer.