Changeset 177 for trunk/src


Ignore:
Timestamp:
Sep 11, 2009, 2:27:35 AM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

corelib: Fixed: QDir::currentPath() would return the file path without the drive letter.

File:
1 edited

Legend:

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

    r171 r177  
    462462}
    463463
    464 QString QFSFileEngine::currentPath(const QString &)
    465 {
    466     QString result;
    467     QT_STATBUF st;
    468     if (QT_STAT(".", &st) == 0) {
    469 #if defined(__GLIBC__) && !defined(PATH_MAX)
    470         char *currentName = ::get_current_dir_name();
    471         if (currentName) {
    472             result = QFile::decodeName(QByteArray(currentName));
    473             ::free(currentName);
    474         }
    475 #else
    476         char currentName[PATH_MAX+1];
    477         if (::getcwd(currentName, PATH_MAX))
    478             result = QFile::decodeName(QByteArray(currentName));
     464/*!
     465    Returns the canonicalized form of the current path used by the file
     466    engine for the drive specified by \a fileName.
     467
     468    On OS/2, each drive has its own current directory, so a different
     469    path is returned for file names that include different drive names
     470    (e.g. A: or C:).
     471
     472    \sa setCurrentPath()
     473*/
     474QString QFSFileEngine::currentPath(const QString &fileName)
     475{
     476    // if filename starts with X: then get the pwd of that drive; otherwise the
     477    // pwd of the current drive
     478    char drv = _getdrive();
     479    if (fileName.length() >= 2 &&
     480        fileName.at(0).isLetter() && fileName.at(1) == QLatin1Char(':')) {
     481        drv = fileName.at(0).toUpper().toLatin1();
     482    }
     483    char buf[PATH_MAX + 1 + 2 /* X: */];
     484    buf[0] = drv;
     485    buf[1] = ':';
     486    QString ret;
     487    if (!_getcwd1(buf + 2, drv)) {
     488        ret = QFile::decodeName(QByteArray(buf));
     489        ret = QDir::fromNativeSeparators(ret);
     490    }
     491#if defined(QT_DEBUG)
     492    if (ret.isEmpty())
     493        qWarning("QDir::currentPath: _getcwd1(%s, %d) failed (%d)",
     494                 fileName.toUtf8().constData(), drv, errno);
    479495#endif
    480 #if defined(QT_DEBUG)
    481         if (result.isNull())
    482             qWarning("QDir::currentPath: getcwd() failed");
    483 #endif
    484     } else {
    485 #if defined(QT_DEBUG)
    486         qWarning("QDir::currentPath: stat(\".\") failed");
    487 #endif
    488     }
    489     return result;
     496    return ret;
    490497}
    491498
Note: See TracChangeset for help on using the changeset viewer.