⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qfsfileengine_unix.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.**** This file is part of the QtCore module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://www.trolltech.com/products/qt/opensource.html**** If you are unsure which license is appropriate for your use, please** review the following information:** http://www.trolltech.com/products/qt/licensing.html or contact the** sales department at sales@trolltech.com.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qplatformdefs.h"#include "qabstractfileengine.h"#include "private/qfsfileengine_p.h"#ifndef QT_NO_REGEXP# include "qregexp.h"#endif#include "qfile.h"#include "qdir.h"#include "qdatetime.h"#include "qdebug.h"#include "qvarlengtharray.h"#include <stdlib.h>#include <limits.h>#include <errno.h>#if !defined(QWS) && defined(Q_OS_MAC)# include <private/qcore_mac_p.h>#endifvoid QFSFileEnginePrivate::init(){}int QFSFileEnginePrivate::sysOpen(const QString &fileName, int flags){    return QT_OPEN(QFile::encodeName(fileName), flags, 0666);}bool QFSFileEngine::remove(){    Q_D(QFSFileEngine);    return unlink(QFile::encodeName(d->file)) == 0;}bool QFSFileEngine::copy(const QString &){    return false;}bool QFSFileEngine::rename(const QString &newName){    Q_D(QFSFileEngine);    return ::rename(QFile::encodeName(d->file), QFile::encodeName(newName)) == 0;}bool QFSFileEngine::link(const QString &newName){    Q_D(QFSFileEngine);    return ::symlink(QFile::encodeName(d->file), QFile::encodeName(newName)) == 0;}qint64 QFSFileEngine::size() const{    Q_D(const QFSFileEngine);    QT_STATBUF st;    int ret = 0;    if(d->fd != -1)        ret = QT_FSTAT(d->fd, &st);    else        ret = QT_STAT(QFile::encodeName(d->file), &st);    if(ret == -1)        return 0;    return st.st_size;}bool QFSFileEngine::mkdir(const QString &name, bool createParentDirectories) const{    QString dirName = name;    if(createParentDirectories) {        dirName = QDir::cleanPath(dirName);        for(int oldslash = -1, slash=0; slash != -1; oldslash = slash) {            slash = dirName.indexOf(QDir::separator(), oldslash+1);            if(slash == -1) {                if(oldslash == dirName.length())                    break;                slash = dirName.length();            }            if(slash) {                QByteArray chunk = QFile::encodeName(dirName.left(slash));                QT_STATBUF st;                if(QT_STAT(chunk, &st) != -1) {                    if((st.st_mode & S_IFMT) != S_IFDIR)                        return false;                } else if(::mkdir(chunk, 0777) != 0) {                        return false;                }            }        }        return true;    }#if defined(Q_OS_DARWIN)  // Mac X doesn't support trailing /'s    if(dirName[dirName.length() - 1] == '/')        dirName = dirName.left(dirName.length() - 1);#endif    return (::mkdir(QFile::encodeName(dirName), 0777) == 0);}bool QFSFileEngine::rmdir(const QString &name, bool recurseParentDirectories) const{    QString dirName = name;    if(recurseParentDirectories) {        dirName = QDir::cleanPath(dirName);        for(int oldslash = 0, slash=dirName.length(); slash > 0; oldslash = slash) {            QByteArray chunk = QFile::encodeName(dirName.left(slash));            QT_STATBUF st;            if(QT_STAT(chunk, &st) != -1) {                if((st.st_mode & S_IFMT) != S_IFDIR)                    return false;                if(::rmdir(chunk) != 0)                    return oldslash != 0;            } else {                return false;            }            slash = dirName.lastIndexOf(QDir::separator(), oldslash-1);        }        return true;    }    return ::rmdir(QFile::encodeName(dirName)) == 0;}QStringList QFSFileEngine::entryList(QDir::Filters filters, const QStringList &filterNames) const{    Q_D(const QFSFileEngine);    QStringList ret;    DIR *dir = opendir(QFile::encodeName(d->file));    if(!dir)        return ret; // cannot read the directory    const bool filterPermissions = ((filters & QDir::PermissionMask) && (filters & QDir::PermissionMask) != QDir::PermissionMask);    const bool skipDirs     = !(filters & (QDir::Dirs | QDir::AllDirs));    const bool skipFiles    = !(filters & QDir::Files);    const bool skipSymlinks = (filters & QDir::NoSymLinks);    const bool doReadable   = !filterPermissions || (filters & QDir::Readable);    const bool doWritable   = !filterPermissions || (filters & QDir::Writable);    const bool doExecutable = !filterPermissions || (filters & QDir::Executable);    const bool includeHidden = (filters & QDir::Hidden);    const bool includeSystem = (filters & QDir::System);#ifndef QT_NO_REGEXP    // Prepare name filters    QList<QRegExp> regexps;    for (int i = 0; i < filterNames.size(); ++i) {        regexps << QRegExp(filterNames.at(i),                           (filters & QDir::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive,                           QRegExp::Wildcard);    }#endif    QFileInfo fi;    dirent   *file;#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_CYGWIN)    union {        struct dirent mt_file;        char b[sizeof(struct dirent) + MAXNAMLEN + 1];    } u;    while (readdir_r(dir, &u.mt_file, &file) == 0 && file)#else    while ((file = readdir(dir)))#endif // _POSIX_THREAD_SAFE_FUNCTIONS    {        QString fn = QFile::decodeName(QByteArray(file->d_name));        fi.setFile(d->file + QLatin1Char('/') + fn);#ifndef QT_NO_REGEXP        if(!((filters & QDir::AllDirs) && fi.isDir())) {            bool matched = false;            for (int i = 0; i < regexps.size(); ++i) {                if (regexps.at(i).exactMatch(fn)) {                    matched = true;                    break;                }            }            if (!matched)                continue;        }#else        Q_UNUSED(filterNames);#endif        if ((filters & QDir::NoDotAndDotDot) && ((fn == QLatin1String(".") || fn == QLatin1String(".."))))            continue;        bool isHidden = (fn.at(0) == QLatin1Char('.') && fn.length() > 1 && fn != QLatin1String(".."));        if (!includeHidden && isHidden)            continue;        bool alwaysShow = (filters & QDir::TypeMask) == 0                          && ((isHidden && includeHidden)                              || (includeSystem && ((fi.exists() && !fi.isFile() && !fi.isDir() && !fi.isSymLink())                                                    || (!fi.exists() && fi.isSymLink()))));        // Skip files and directories        if ((filters & QDir::AllDirs) == 0 && skipDirs && fi.isDir()) {            if (!alwaysShow)                continue;        }        if ((skipFiles && (fi.isFile() || !fi.exists()))            || (skipSymlinks && fi.isSymLink())) {            if (!alwaysShow)                continue;        }        if (filterPermissions            && !((doReadable && fi.isReadable())                 || (doWritable && fi.isWritable())                 || (doExecutable && fi.isExecutable()))) {            continue;        }        if (!includeSystem && ((fi.exists() && !fi.isFile() && !fi.isDir() && !fi.isSymLink())                               || (!fi.exists() && fi.isSymLink()))) {            continue;        }        ret.append(fn);    }    if (closedir(dir) != 0) {        qWarning("QDir::readDirEntries: Cannot close the directory: %s", d->file.toLocal8Bit().data());    }    return ret;}bool QFSFileEngine::caseSensitive() const{    return true;}bool QFSFileEngine::setCurrentPath(const QString &path){    int r;    r = ::chdir(QFile::encodeName(path));    return r >= 0;}QString QFSFileEngine::currentPath(const QString &){    QString result;    QT_STATBUF st;    if(QT_STAT(".", &st) == 0) {        char currentName[PATH_MAX+1];        if(::getcwd(currentName, PATH_MAX))            result = QFile::decodeName(QByteArray(currentName));#if defined(QT_DEBUG)        if(result.isNull())            qWarning("QDir::currentPath: getcwd() failed");#endif    } else {#if defined(QT_DEBUG)        qWarning("QDir::currentPath: stat(\".\") failed");#endif    }    return result;}QString QFSFileEngine::homePath(){    QString home = QFile::decodeName(qgetenv("HOME"));    if(home.isNull())        home = rootPath();    return home;}QString QFSFileEngine::rootPath(){    return QString::fromLatin1("/");}QString QFSFileEngine::tempPath(){    QString temp = QFile::decodeName(qgetenv("TMPDIR"));    if(temp.isEmpty())        temp = QString::fromLatin1("/tmp/");    return temp;}QFileInfoList QFSFileEngine::drives(){    QFileInfoList ret;    ret.append(rootPath());    return ret;}bool QFSFileEnginePrivate::doStat() const{    if (tried_stat == 0) {        QFSFileEnginePrivate *that = const_cast<QFSFileEnginePrivate*>(this);        if (fd != -1) {            that->could_stat = (QT_FSTAT(fd, &st) == 0);        } else {            that->could_stat = (QT_STAT(QFile::encodeName(file), &st) == 0);        }	that->tried_stat = 1;    }    return could_stat;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -