10#include <QtCore/qdebug.h>
12#ifndef QT_NO_FSFILEENGINE
16#include "private/qcore_unix_p.h"
20#if defined(Q_OS_DARWIN)
21# include <private/qcore_mac_p.h>
30# define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
33# define S_ISCHR(x) (((x) & S_IFMT) == S_IFCHR)
36# define S_ISFIFO(x) false
39# define S_ISSOCK(x) false
41# ifndef INVALID_FILE_ATTRIBUTES
42# define INVALID_FILE_ATTRIBUTES (DWORD (-1))
54 "Unsupported: read/write return a type with different size as the len parameter");
101 fileHandle = INVALID_HANDLE_VALUE;
140 qWarning(
"NewOnly and ExistingOnly are mutually exclusive");
141 result.error =
"NewOnly and ExistingOnly are mutually exclusive"_L1;
146 qWarning(
"ExistingOnly must be specified alongside ReadOnly, WriteOnly, or ReadWrite");
148 "ExistingOnly must be specified alongside ReadOnly, WriteOnly, or ReadWrite"_L1;
161 result.openMode = openMode;
171 if (
d->closeFileHandle) {
174 }
else if (
d->fd != -1) {
195 std::optional<QFile::Permissions> permissions)
198 "QFSFileEngine no longer supports buffered mode; upper layer must buffer");
201 if (
d->fileEntry.isEmpty()) {
202 qWarning(
"QFSFileEngine::open: No file name specified");
213 d->openMode =
res.openMode;
214 d->lastFlushFailed =
false;
219 return d->nativeOpen(
d->openMode, permissions);
234 "QFSFileEngine no longer supports buffered mode; upper layer must buffer");
244 d->openMode =
res.openMode;
245 d->lastFlushFailed =
false;
247 d->fileEntry.clear();
251 return d->openFh(
d->openMode, fh);
260 "QFSFileEngine no longer supports buffered mode; upper layer must buffer");
270 ret = QT_FSEEK(
fh, 0, SEEK_END);
271 }
while (
ret != 0 && errno == EINTR);
306 d->openMode =
res.openMode;
307 d->lastFlushFailed =
false;
309 d->fileEntry.clear();
314 return d->openFd(
d->openMode,
fd);
332 ret = QT_LSEEK(
fd, 0, SEEK_END);
333 }
while (
ret == -1 && errno == EINTR);
356 return d->nativeClose();
393 if (!flushed || !closed) {
415 return d->nativeFlush();
426 return d->nativeSyncToDisk();
441 int ret = fflush(
fh);
460 return d->nativeSize();
468 if (!
maps.isEmpty()) {
469 const QList<uchar*>
keys =
maps.keys();
470 for (
int i = 0;
i <
keys.size(); ++
i)
498 return d->nativePos();
508 return QT_LSEEK(
fd, 0, SEEK_CUR);
517 return d->nativeSeek(
pos);
533 return d->metaData.fileTime(
time);
559 ret = QT_FSEEK(
fh, QT_OFF_T(
pos), SEEK_SET);
560 }
while (
ret != 0 && errno == EINTR);
568 if (QT_LSEEK(
fd, QT_OFF_T(
pos), SEEK_SET) == -1) {
570 qWarning(
"QFile::at: Cannot set file position %lld",
pos);
583 return d->nativeHandle();
601 return d->nativeRead(
data, maxlen);
630 QT_FSEEK(
fh, QT_FTELL(
fh), SEEK_SET);
634 }
while (!eof && (
result == 0 ? errno == EINTR : readBytes <
len));
636 }
else if (
fd != -1) {
645 UnsignedIOType chunkSize = std::numeric_limits<SignedIOType>::max();
646 if (chunkSize > wantedBytes)
647 chunkSize = wantedBytes;
655 if (!eof && readBytes == 0) {
678 return d->nativeReadLine(
data, maxlen);
688 return q->QAbstractFileEngine::readLine(
data, maxlen);
692 bool seq =
q->isSequential();
695 oldPos = QT_FTELL(
fh);
701 if (!fgets(
data,
int(maxlen + 1),
fh)) {
712 qint64 lineLength = QT_FTELL(
fh) - oldPos;
713 return lineLength > 0 ? lineLength :
qstrlen(
data);
756 result = fwrite(
data + writtenBytes, 1,
size_t(
len - writtenBytes),
fh);
758 }
while (
result == 0 ? errno == EINTR : writtenBytes <
len);
760 }
else if (
fd != -1) {
769 UnsignedIOType chunkSize = std::numeric_limits<SignedIOType>::max();
770 if (chunkSize > wantedBytes)
771 chunkSize = wantedBytes;
778 if (
len && writtenBytes == 0) {
790#ifndef QT_NO_FILESYSTEMITERATOR
798 return std::make_unique<QFSFileEngineIterator>(
path,
filters, filterNames);
817 if (
d->is_sequential == 0)
818 d->is_sequential =
d->nativeIsSequential() ? 1 : 2;
819 return d->is_sequential == 1;
847 return (returnValue->
address !=
nullptr);
1001 d->fileEntry = std::move(
entry);
1004bool QFSFileEngine::rename_helper(
const QString &newName, RenameMode
mode)
1025 std::optional<QFile::Permissions> permissions)
const
QFile::MemoryMapFlags flags
\inmodule QtCore \reentrant
void setError(QFile::FileError error, const QString &str)
Sets the error type to error, and the error string to errorString.
virtual QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const
Requests that a list of all the files matching the filters list based on the filterNames in the file ...
std::unique_ptr< Iterator > IteratorUniquePtr
QFile::FileError error() const
Returns the QFile::FileError that resulted from the last failed operation.
\inmodule QtCore\reentrant
qint64 readFdFh(char *data, qint64 maxlen)
bool openFd(QIODevice::OpenMode flags, int fd)
Opens the file descriptor fd to the file engine, using the open mode flags.
QHash< uchar *, StartAndLength > maps
qint64 writeFdFh(const char *data, qint64 len)
QIODevice::OpenMode openMode
bool doStat(QFileSystemMetaData::MetaDataFlags flags=QFileSystemMetaData::PosixStatFlags) const
QFileSystemMetaData metaData
bool isSequentialFdFh() const
qint64 readLineFdFh(char *data, qint64 maxlen)
bool openFh(QIODevice::OpenMode flags, FILE *fh)
Opens the file handle fh using the open mode flags.
LastIOCommand lastIOCommand
qint64 read(char *data, qint64 maxlen) override
\reimp
qint64 write(const char *data, qint64 len) override
\reimp
bool rmdir(const QString &dirName, bool recurseParentDirectories) const override
\reimp
static QString tempPath()
Returns the temporary path (i.e., a path in which it is safe to store temporary files).
qint64 pos() const override
\reimp
bool close() override
\reimp
bool syncToDisk() override
\reimp
QFSFileEngine()
Constructs a QFSFileEngine.
qint64 size() const override
\reimp
static QString rootPath()
Returns the root path.
QDateTime fileTime(QFile::FileTime time) const override
\reimp
QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const override
bool isSequential() const override
\reimp
bool open(QIODevice::OpenMode openMode, std::optional< QFile::Permissions > permissions) override
\reimp
void setFileName(const QString &file) override
\reimp
bool seek(qint64) override
\reimp
static bool setCurrentPath(const QString &path)
Sets the current path (e.g., for QDir), to path.
bool mkdir(const QString &dirName, bool createParentDirectories, std::optional< QFile::Permissions > permissions) const override
\reimp
bool copy(const QString &newName) override
For Windows or Apple platforms, copy the file to file copyName.
bool supportsExtension(Extension extension) const override
\reimp
int handle() const override
\reimp
bool extension(Extension extension, const ExtensionOption *option=nullptr, ExtensionReturn *output=nullptr) override
\reimp
qint64 readLine(char *data, qint64 maxlen) override
\reimp
void setFileEntry(QFileSystemEntry &&entry)
IteratorUniquePtr beginEntryList(const QString &path, QDir::Filters filters, const QStringList &filterNames) override
static QString homePath()
Returns the home path of the current user.
bool remove() override
\reimp
~QFSFileEngine()
Destructs the QFSFileEngine.
bool flush() override
\reimp
static bool setCurrentPath(const QFileSystemEntry &entry)
static bool copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
static bool renameOverwriteFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
static QString rootPath()
static bool createDirectory(const QFileSystemEntry &entry, bool createParents, std::optional< QFile::Permissions > permissions=std::nullopt)
static QString homePath()
static bool renameFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
static QString tempPath()
static bool removeFile(const QFileSystemEntry &entry, QSystemError &error)
static bool removeDirectory(const QFileSystemEntry &entry, bool removeEmptyParents)
\macro QT_RESTRICTED_CAST_FROM_ASCII
static Q_CORE_EXPORT QString stdString(int errorCode=-1)
Combined button and popup list for selecting options.
size_t qstrlen(const char *str)
#define INVALID_FILE_ATTRIBUTES
ProcessOpenModeResult processOpenModeFlags(QIODevice::OpenMode openMode)
Q_CORE_EXPORT ProcessOpenModeResult processOpenModeFlags(QIODevice::OpenMode mode)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLdouble GLdouble GLdouble GLdouble q
GLsizei const GLchar *const * path
#define Q_ASSERT_X(cond, x, msg)
unsigned long long quint64
QT_BEGIN_NAMESPACE typedef uchar * output
const QStringList filters({"Image files (*.png *.xpm *.jpg)", "Text files (*.txt)", "Any files (*)" })
[6]