Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
5 | ** | - |
6 | ** This file is part of the QtCore module of the Qt Toolkit. | - |
7 | ** | - |
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
9 | ** Commercial License Usage | - |
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
11 | ** accordance with the commercial license agreement provided with the | - |
12 | ** Software or, alternatively, in accordance with the terms contained in | - |
13 | ** a written agreement between you and Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
16 | ** | - |
17 | ** GNU Lesser General Public License Usage | - |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
19 | ** General Public License version 2.1 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | #include "qplatformdefs.h" | - |
43 | #include "qfilesystemiterator_p.h" | - |
44 | | - |
45 | #ifndef QT_NO_FILESYSTEMITERATOR | - |
46 | | - |
47 | #include <stdlib.h> | - |
48 | #include <errno.h> | - |
49 | | - |
50 | QT_BEGIN_NAMESPACE | - |
51 | | - |
52 | QFileSystemIterator::QFileSystemIterator(const QFileSystemEntry &entry, QDir::Filters filters, | - |
53 | const QStringList &nameFilters, QDirIterator::IteratorFlags flags) | - |
54 | : nativePath(entry.nativeFilePath()) | - |
55 | , dir(0) | - |
56 | , dirEntry(0) | - |
57 | #if defined(Q_OS_QNX) && defined(__EXT_QNX__READDIR_R) | - |
58 | , direntSize(0) | - |
59 | #endif | - |
60 | , lastError(0) | - |
61 | { | - |
62 | Q_UNUSED(filters) executed (the execution status of this line is deduced): (void)filters; | - |
63 | Q_UNUSED(nameFilters) executed (the execution status of this line is deduced): (void)nameFilters; | - |
64 | Q_UNUSED(flags) executed (the execution status of this line is deduced): (void)flags; | - |
65 | | - |
66 | if ((dir = QT_OPENDIR(nativePath.constData())) == 0) { evaluated: (dir = ::opendir(nativePath.constData())) == 0 yes Evaluation Count:24 | yes Evaluation Count:5816 |
| 24-5816 |
67 | lastError = errno; executed (the execution status of this line is deduced): lastError = (*__errno_location ()); | - |
68 | } else { executed: } Execution Count:24 | 24 |
69 | | - |
70 | if (!nativePath.endsWith('/')) evaluated: !nativePath.endsWith('/') yes Evaluation Count:5649 | yes Evaluation Count:167 |
| 167-5649 |
71 | nativePath.append('/'); executed: nativePath.append('/'); Execution Count:5649 | 5649 |
72 | | - |
73 | #if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_CYGWIN) | - |
74 | // ### Race condition; we should use fpathconf and dirfd(). | - |
75 | size_t maxPathName = ::pathconf(nativePath.constData(), _PC_NAME_MAX); executed (the execution status of this line is deduced): size_t maxPathName = ::pathconf(nativePath.constData(), _PC_NAME_MAX); | - |
76 | if (maxPathName == size_t(-1)) partially evaluated: maxPathName == size_t(-1) no Evaluation Count:0 | yes Evaluation Count:5816 |
| 0-5816 |
77 | maxPathName = FILENAME_MAX; never executed: maxPathName = 4096; | 0 |
78 | maxPathName += sizeof(QT_DIRENT) + 1; executed (the execution status of this line is deduced): maxPathName += sizeof(struct dirent64) + 1; | - |
79 | | - |
80 | QT_DIRENT *p = reinterpret_cast<QT_DIRENT*>(::malloc(maxPathName)); executed (the execution status of this line is deduced): struct dirent64 *p = reinterpret_cast<struct dirent64*>(::malloc(maxPathName)); | - |
81 | Q_CHECK_PTR(p); never executed: qBadAlloc(); executed: } Execution Count:5816 partially evaluated: !(p) no Evaluation Count:0 | yes Evaluation Count:5816 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:5816 |
| 0-5816 |
82 | | - |
83 | mt_file.reset(p); executed (the execution status of this line is deduced): mt_file.reset(p); | - |
84 | #if defined(Q_OS_QNX) && defined(__EXT_QNX__READDIR_R) | - |
85 | direntSize = maxPathName; | - |
86 | | - |
87 | // Include extra stat information in the readdir() call (d_stat member of dirent_extra_stat). | - |
88 | // This is used in QFileSystemMetaData::fillFromDirEnt() to avoid extra stat() calls when iterating | - |
89 | // over directories | - |
90 | if (dircntl(dir, D_SETFLAG, D_FLAG_STAT) == -1) | - |
91 | lastError = errno; | - |
92 | #endif | - |
93 | #endif | - |
94 | } executed: } Execution Count:5816 | 5816 |
95 | } | - |
96 | | - |
97 | QFileSystemIterator::~QFileSystemIterator() | - |
98 | { | - |
99 | if (dir) evaluated: dir yes Evaluation Count:5816 | yes Evaluation Count:24 |
| 24-5816 |
100 | QT_CLOSEDIR(dir); executed: ::closedir(dir); Execution Count:5816 | 5816 |
101 | } executed: } Execution Count:5840 | 5840 |
102 | | - |
103 | bool QFileSystemIterator::advance(QFileSystemEntry &fileEntry, QFileSystemMetaData &metaData) | - |
104 | { | - |
105 | if (!dir) evaluated: !dir yes Evaluation Count:24 | yes Evaluation Count:92600 |
| 24-92600 |
106 | return false; executed: return false; Execution Count:24 | 24 |
107 | | - |
108 | #if defined(Q_OS_QNX) && defined(__EXT_QNX__READDIR_R) | - |
109 | lastError = _readdir_r(dir, mt_file.data(), &dirEntry, direntSize); | - |
110 | if (lastError) | - |
111 | return false; | - |
112 | #elif defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_CYGWIN) | - |
113 | lastError = QT_READDIR_R(dir, mt_file.data(), &dirEntry); executed (the execution status of this line is deduced): lastError = ::readdir64_r(dir, mt_file.data(), &dirEntry); | - |
114 | if (lastError) partially evaluated: lastError no Evaluation Count:0 | yes Evaluation Count:92606 |
| 0-92606 |
115 | return false; never executed: return false; | 0 |
116 | #else | - |
117 | // ### add local lock to prevent breaking reentrancy | - |
118 | dirEntry = QT_READDIR(dir); | - |
119 | #endif // _POSIX_THREAD_SAFE_FUNCTIONS | - |
120 | | - |
121 | if (dirEntry) { evaluated: dirEntry yes Evaluation Count:86844 | yes Evaluation Count:5763 |
| 5763-86844 |
122 | fileEntry = QFileSystemEntry(nativePath + QByteArray(dirEntry->d_name), QFileSystemEntry::FromNativePath()); executed (the execution status of this line is deduced): fileEntry = QFileSystemEntry(nativePath + QByteArray(dirEntry->d_name), QFileSystemEntry::FromNativePath()); | - |
123 | metaData.fillFromDirEnt(*dirEntry); executed (the execution status of this line is deduced): metaData.fillFromDirEnt(*dirEntry); | - |
124 | return true; executed: return true; Execution Count:86823 | 86823 |
125 | } | - |
126 | | - |
127 | lastError = errno; executed (the execution status of this line is deduced): lastError = (*__errno_location ()); | - |
128 | return false; executed: return false; Execution Count:5763 | 5763 |
129 | } | - |
130 | | - |
131 | QT_END_NAMESPACE | - |
132 | | - |
133 | #endif // QT_NO_FILESYSTEMITERATOR | - |
134 | | - |
| | |