Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qfilesystemiterator_unix.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qplatformdefs.h"
6
7#include <private/qstringconverter_p.h>
8
9#ifndef QT_NO_FILESYSTEMITERATOR
10
11#include <memory>
12
13#include <stdlib.h>
14#include <errno.h>
15
17
18static bool checkNameDecodable(const char *d_name, qsizetype len)
19{
20 // This function is called in a loop from advance() below, but the loop is
21 // usually run only once.
22
24}
25
27 const QStringList &nameFilters, QDirIterator::IteratorFlags flags)
28 : nativePath(entry.nativeFilePath())
29 , dir(nullptr)
30 , dirEntry(nullptr)
31 , lastError(0)
32{
34 Q_UNUSED(nameFilters);
36
37 if ((dir = QT_OPENDIR(nativePath.constData())) == nullptr) {
38 lastError = errno;
39 } else {
40 if (!nativePath.endsWith('/'))
41 nativePath.append('/');
42 }
43}
44
46{
47 if (dir)
48 QT_CLOSEDIR(dir);
49}
50
52{
53 if (!dir)
54 return false;
55
56 for (;;) {
57 dirEntry = QT_READDIR(dir);
58
59 if (dirEntry) {
60 qsizetype len = strlen(dirEntry->d_name);
61 if (checkNameDecodable(dirEntry->d_name, len)) {
62 fileEntry = QFileSystemEntry(nativePath + QByteArray(dirEntry->d_name, len), QFileSystemEntry::FromNativePath());
63 metaData.fillFromDirEnt(*dirEntry);
64 return true;
65 }
66 } else {
67 break;
68 }
69 }
70
71 lastError = errno;
72 return false;
73}
74
76
77#endif // QT_NO_FILESYSTEMITERATOR
\inmodule QtCore
Definition qbytearray.h:57
bool endsWith(char c) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qbytearray.h:174
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
Definition qbytearray.h:122
QByteArray & append(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool advance(QFileSystemEntry &fileEntry, QFileSystemMetaData &metaData)
QFileSystemIterator(const QFileSystemEntry &entry, QDir::Filters filters, const QStringList &nameFilters, QDirIterator::IteratorFlags flags=QDirIterator::FollowSymlinks|QDirIterator::Subdirectories)
\inmodule QtCore
Combined button and popup list for selecting options.
static QT_BEGIN_NAMESPACE bool checkNameDecodable(const char *d_name, qsizetype len)
GLbitfield flags
GLuint entry
GLenum GLsizei len
#define Q_UNUSED(x)
ptrdiff_t qsizetype
Definition qtypes.h:70
QObject::connect nullptr
QString dir
[11]
const QStringList filters({"Image files (*.png *.xpm *.jpg)", "Text files (*.txt)", "Any files (*)" })
[6]
static ValidUtf8Result isValidUtf8(QByteArrayView in)