42 #include "qplatformdefs.h" 49 #include "private/qiodevice_p.h" 50 #include "private/qfile_p.h" 51 #include "private/qsystemerror_p.h" 52 #if defined(QT_BUILD_CORE_LIB) 57 #define tr(X) QString::fromLatin1(X) 66 #if defined(Q_OS_DARWIN) 69 #elif defined(Q_OS_SYMBIAN) 78 #if defined(Q_OS_DARWIN) 81 #elif defined(Q_OS_SYMBIAN) 93 : fileEngine(0), lastWasWrite(false),
108 #ifdef QT_NO_FSFILEENGINE 117 return fe->
open(QIODevice::OpenMode(flags), fd, handleFlags);
124 #ifdef QT_NO_FSFILEENGINE 133 return fe->
open(QIODevice::OpenMode(flags), fh, handleFlags);
140 #ifdef QT_NO_FSFILEENGINE 149 return fe->
open(QIODevice::OpenMode(flags), f, handleFlags);
160 if (!const_cast<QFile *>(q_func())->flush())
407 d_func()->fileName =
name;
498 qWarning(
"QFile::setFileName: File (%s) is already opened",
503 delete d->fileEngine;
718 if (
d->fileName.isEmpty()) {
719 qWarning(
"QFile::remove: Empty or null file name");
750 return QFile(fileName).remove();
769 if (
d->fileName.isEmpty()) {
770 qWarning(
"QFile::rename: Empty or null file name");
786 d->fileEngine->setFileName(newName);
787 d->fileName = newName;
802 while ((bytes =
read(block,
sizeof(block))) > 0) {
803 if (bytes != out.
write(block, bytes)) {
822 d->fileEngine->setFileName(newName);
855 return QFile(oldName).rename(newName);
880 if (
d->fileName.isEmpty()) {
881 qWarning(
"QFile::link: Empty or null file name");
910 return QFile(fileName).link(linkName);
929 if (
d->fileName.isEmpty()) {
930 qWarning(
"QFile::copy: Empty or null file name");
953 #ifdef QT_NO_TEMPORARYFILE 977 if(in != out.write(block, in)) {
985 if (totalRead !=
size()) {
990 if (!error && !out.rename(newName)) {
995 #ifdef QT_NO_TEMPORARYFILE 1000 out.setAutoRemove(
false);
1033 return QFile(fileName).copy(newName);
1047 return d->fileEngine &&
d->fileEngine->isSequential();
1076 qWarning(
"QIODevice::open: File access not specified");
1089 if (mode & Append) {
1099 d->setError(err,
d->fileEngine->errorString());
1203 bool QFile::open(FILE *fh, OpenMode mode, FileHandleFlags handleFlags)
1214 qWarning(
"QFile::open: File access not specified");
1217 if (
d->openExternalFile(mode, fh, handleFlags)) {
1219 if (mode & Append) {
1319 qWarning(
"QFile::open: File access not specified");
1322 if (
d->openExternalFile(mode, fd, handleFlags)) {
1324 if (mode & Append) {
1357 bool QFile::open(
const RFile &f, OpenMode mode, FileHandleFlags handleFlags)
1368 qWarning(
"QFile::open: File access not specified");
1371 if (
d->openExternalFile(mode, f, handleFlags)) {
1374 if (mode & Append) {
1379 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API 1380 err =
static_cast<const RFile64&
>(f).Seek(ESeekCurrent, pos);
1383 err = f.Seek(ESeekCurrent, pos32);
1386 ok = ok && (err == KErrNone);
1387 ok = ok &&
seek(pos);
1422 if (!
isOpen() || !
d->fileEngine)
1425 return d->fileEngine->handle();
1466 uchar *address =
d->fileEngine->map(offset, size, flags);
1468 d->setError(
d->fileEngine->error(),
d->fileEngine->errorString());
1491 bool success =
d->fileEngine->unmap(address);
1493 d->setError(
d->fileEngine->error(),
d->fileEngine->errorString());
1496 d->setError(
PermissionsError,
tr(
"No file engine available or engine does not support UnMapExtension"));
1531 if (!
d->ensureFlushed())
1534 if (
isOpen() &&
d->fileEngine->pos() > sz)
1536 if(
d->fileEngine->setSize(sz)) {
1563 return QFile(fileName).resize(sz);
1577 return QFile::Permissions((
int)perms);
1593 return QFile(fileName).permissions();
1628 return QFile(fileName).setPermissions(permissions);
1648 if (!
d->fileEngine) {
1649 qWarning(
"QFile::flush: No file engine. Is IODevice open?");
1653 if (!
d->writeBuffer.isEmpty()) {
1659 d->setError(err,
d->fileEngine->errorString());
1664 if (!
d->fileEngine->flush()) {
1668 d->setError(err,
d->fileEngine->errorString());
1685 bool flushed =
flush();
1689 d->lastWasWrite =
false;
1690 d->writeBuffer.clear();
1693 if (
d->fileEngine->close() && flushed)
1696 d->setError(
d->fileEngine->error(),
d->fileEngine->errorString());
1710 if (!
d->ensureFlushed())
1713 return d->cachedSize;
1740 if (!
d->buffer.isEmpty())
1746 if (!
d->ensureFlushed())
1753 return d->fileEngine->atEnd();
1758 if (
pos() <
d->cachedSize)
1788 qWarning(
"QFile::seek: IODevice is not open");
1792 if (off ==
d->pos && off ==
d->devicePos)
1795 if (!
d->ensureFlushed())
1802 d->setError(err,
d->fileEngine->errorString());
1815 if (!
d->ensureFlushed())
1820 read =
d->fileEngine->readLine(data, maxlen);
1827 if (read < maxlen) {
1843 if (!
d->ensureFlushed())
1851 d->setError(err,
d->fileEngine->errorString());
1867 #ifdef QT_NO_QOBJECT 1872 int writeBufferSize = writeBuffer.size();
1883 qWarning(
"QIODevice::putChar: Closed device");
1885 qWarning(
"QIODevice::putChar: ReadOnly device");
1891 if (
pos != devicePos && !sequential && !q_func()->
seek(
pos))
1894 lastWasWrite =
true;
1898 if ((
openMode & QIODevice::Text) && c ==
'\n') {
1900 *writeBuffer.reserve(1) =
'\r';
1905 *writeBuffer.reserve(1) =
c;
1910 if (!buffer.isEmpty())
1927 d->lastWasWrite =
true;
1939 qint64 ret =
d->fileEngine->write(data, len);
1944 d->setError(err,
d->fileEngine->errorString());
1950 char *writePointer =
d->writeBuffer.reserve(len);
1952 *writePointer = *
data;
1954 ::memcpy(writePointer, data, len);
1970 return d->fileEngine;
virtual FileFlags fileFlags(FileFlags type=FileInfoAll) const
This function should return the set of OR'd flags that are true for the file engine's file...
QString qt_error_string(int errorCode)
QString fileName() const
Returns the name set by setFileName() or to the QFile constructors.
qint64 writeData(const char *data, qint64 len)
Reimplemented Function
bool rename(const QString &newName)
Renames the file currently specified by fileName() to newName.
bool isSequential() const
Returns true if the file can only be manipulated sequentially; otherwise returns false.
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
bool openExternalFile(int flags, int fd, QFile::FileHandleFlags handleFlags)
#define QT_END_NAMESPACE
This macro expands to.
QByteArray(* EncoderFn)(const QString &fileName)
This is a typedef for a pointer to a function with the following signature:
const char * readPointer() const
virtual void close()
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen.
virtual QString fileName(FileName file=DefaultName) const
Return the file engine's current file name in the format specified by file.
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
static qint64 _qfile_writeData(QAbstractFileEngine *engine, QRingBuffer *buffer)
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
int nextDataBlockSize() const
The QByteArray class provides an array of bytes.
The QTemporaryFile class is an I/O device that operates on temporary files.
QString errorString() const
Returns a human-readable description of the last device error that occurred.
virtual qint64 pos() const
For random-access devices, this function returns the position that data is written to or read from...
virtual QAbstractFileEngine * fileEngine() const
Returns the QIOEngine for this QFile object.
void setError(QFile::FileError err)
static QString locale_decode(const QByteArray &f)
QString absoluteFilePath() const
Returns an absolute path including the file name.
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool exists() const
Returns true if the file exists; otherwise returns false.
FileFlag
The permissions and types of a file, suitable for OR'ing together.
bool ensureFlushed() const
The QString class provides a Unicode character string.
QString normalized(NormalizationForm mode) const Q_REQUIRED_RESULT
Returns the string in the given Unicode normalization mode.
bool resize(qint64 sz)
Sets the file size (in bytes) sz.
The QObject class is the base class of all Qt objects.
virtual qint64 readLineData(char *data, qint64 maxlen)
Reads up to maxSize characters into data and returns the number of characters read.
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
bool exists() const
Returns true if the file specified by fileName() exists; otherwise returns false. ...
QAbstractFileEngine * fileEngine
#define QT_BEGIN_NAMESPACE
This macro expands to.
bool isOpen() const
Returns true if the device is open; otherwise returns false.
qint64 readData(char *data, qint64 maxlen)
Reimplemented Function
virtual bool seek(qint64 pos)
Sets the file position to the given offset.
virtual bool putCharHelper(char c)
qint64 readLineData(char *data, qint64 maxlen)
Reimplemented Function
bool open(QIODevice::OpenMode openMode)
Reimplemented Function
bool flush()
Flushes any buffered data to the file.
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Q_CORE_EXPORT void qWarning(const char *,...)
The QAbstractFileEngine class provides an abstraction for accessing the filesystem.
static const char * data(const QByteArray &arr)
qint64 pos() const
Reimplemented Function
QString(* DecoderFn)(const QByteArray &localfileName)
This is a typedef for a pointer to a function with the following signature:
~QFile()
Destroys the file object, closing it if necessary.
static QAbstractFileEngine * create(const QString &fileName)
Creates and returns a QAbstractFileEngine suitable for processing fileName.
static QFile::EncoderFn encoder
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
int handle() const
Returns the file handle of the file.
static QFile::DecoderFn decoder
static const int QFILE_WRITEBUFFER_SIZE
qint64 size() const
Returns the size of the file.
static QString tempPath()
Returns the absolute path of the system's temporary directory.
virtual qint64 write(const char *data, qint64 len)
Writes len bytes from data to the file.
void unsetError()
Sets the file's error to QFile::NoError.
static void setEncodingFunction(EncoderFn)
Sets the function for encoding Unicode file names.
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
The QFile class provides an interface for reading from and writing to files.
bool unmap(uchar *address)
Unmaps the memory address.
void clear()
Clears the contents of the string and makes it empty.
OpenMode openMode() const
Returns the mode in which the device has been opened; i.e.
QObject * parent() const
Returns a pointer to the parent object.
static QByteArray locale_encode(const QString &f)
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
bool putCharHelper(char c)
bool setPermissions(Permissions permissionSpec)
Sets the permissions for the file to the permissions specified.
bool copy(const QString &newName)
Copies the file currently specified by fileName() to a file called newName.
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
bool remove()
Removes the file specified by fileName().
Permissions permissions() const
Returns the complete OR-ed together combination of QFile::Permission for the file.
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user's loca...
void setFileTemplate(const QString &name)
Sets the static portion of the file name to name.
QString readLink() const
Use symLinkTarget() instead.
MemoryMapFlags
This enum describes special options that may be used by the map() function.
FileError
This enum describes the errors that may be returned by the error() function.
FileError error() const
Returns the file error status.
uchar * map(qint64 offset, qint64 size, MemoryMapFlags flags=NoOptions)
Maps size bytes of the file into memory starting at offset.
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
The QFileInfo class provides system-independent file information.
bool atEnd() const
Returns true if the end of the file has been reached; otherwise returns false.
The QIODevice class is the base interface class of all I/O devices in Qt.
virtual void close()
Calls QFile::flush() and closes the file.
#define qPrintable(string)
QString readLink() const
Use symLinkTarget() instead.
bool seek(qint64 offset)
For random-access devices, this function sets the current position to pos, returning true on success...
virtual qint64 size() const
Returns the size of the file.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success...
static void setDecodingFunction(DecoderFn)
Sets the function for decoding 8-bit file names.
void setFileName(const QString &name)
Sets the name of the file.
bool link(const QString &newName)
Creates a link named linkName that points to the file currently specified by fileName().
The QFSFileEngine class implements Qt's default file engine.