Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-04 09:53:08

0001 // Copyright (C) 2020 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 // Qt-Security score:significant reason:default
0004 
0005 #ifndef QFILEDEVICE_H
0006 #define QFILEDEVICE_H
0007 
0008 #include <QtCore/qiodevice.h>
0009 #include <QtCore/qstring.h>
0010 
0011 QT_BEGIN_NAMESPACE
0012 
0013 class QDateTime;
0014 class QFileDevicePrivate;
0015 
0016 #if !defined(QT_USE_NODISCARD_FILE_OPEN) && !defined(QT_NO_USE_NODISCARD_FILE_OPEN)
0017 #  if QT_VERSION < QT_VERSION_CHECK(6, 10, 0)
0018 #    define QT_NO_USE_NODISCARD_FILE_OPEN
0019 #  else
0020 #    define QT_USE_NODISCARD_FILE_OPEN
0021 #  endif
0022 #endif
0023 
0024 #if defined(QT_USE_NODISCARD_FILE_OPEN) && defined(QT_NO_USE_NODISCARD_FILE_OPEN)
0025 #error "Inconsistent macro definition for nodiscard QFile::open"
0026 #elif defined(QT_USE_NODISCARD_FILE_OPEN)
0027 #define QFILE_MAYBE_NODISCARD [[nodiscard]]
0028 #else /* QT_NO_USE_NODISCARD_FILE_OPEN */
0029 #define QFILE_MAYBE_NODISCARD
0030 #endif
0031 
0032 class Q_CORE_EXPORT QFileDevice : public QIODevice
0033 {
0034 #ifndef QT_NO_QOBJECT
0035     Q_OBJECT
0036 #endif
0037     Q_DECLARE_PRIVATE(QFileDevice)
0038 
0039 public:
0040     enum FileError {
0041         NoError = 0,
0042         ReadError = 1,
0043         WriteError = 2,
0044         FatalError = 3,
0045         ResourceError = 4,
0046         OpenError = 5,
0047         AbortError = 6,
0048         TimeOutError = 7,
0049         UnspecifiedError = 8,
0050         RemoveError = 9,
0051         RenameError = 10,
0052         PositionError = 11,
0053         ResizeError = 12,
0054         PermissionsError = 13,
0055         CopyError = 14
0056     };
0057 
0058     enum FileTime {
0059         FileAccessTime,
0060         FileBirthTime,
0061         FileMetadataChangeTime,
0062         FileModificationTime
0063     };
0064 
0065     enum Permission {
0066         ReadOwner = 0x4000, WriteOwner = 0x2000, ExeOwner = 0x1000,
0067         ReadUser  = 0x0400, WriteUser  = 0x0200, ExeUser  = 0x0100,
0068         ReadGroup = 0x0040, WriteGroup = 0x0020, ExeGroup = 0x0010,
0069         ReadOther = 0x0004, WriteOther = 0x0002, ExeOther = 0x0001
0070     };
0071     Q_DECLARE_FLAGS(Permissions, Permission)
0072 
0073     enum FileHandleFlag {
0074         AutoCloseHandle = 0x0001,
0075         DontCloseHandle = 0
0076     };
0077     Q_DECLARE_FLAGS(FileHandleFlags, FileHandleFlag)
0078 
0079     ~QFileDevice();
0080 
0081     FileError error() const;
0082     void unsetError();
0083 
0084     void close() override;
0085 
0086     bool isSequential() const override;
0087 
0088     int handle() const;
0089     virtual QString fileName() const;
0090 
0091     qint64 pos() const override;
0092     bool seek(qint64 offset) override;
0093     bool atEnd() const override;
0094     bool flush();
0095 
0096     qint64 size() const override;
0097 
0098     virtual bool resize(qint64 sz);
0099     virtual Permissions permissions() const;
0100     virtual bool setPermissions(Permissions permissionSpec);
0101 
0102     enum MemoryMapFlag {
0103         NoOptions = 0,
0104         MapPrivateOption = 0x0001
0105     };
0106     Q_DECLARE_FLAGS(MemoryMapFlags, MemoryMapFlag)
0107 
0108     uchar *map(qint64 offset, qint64 size, MemoryMapFlags flags = NoOptions);
0109     bool unmap(uchar *address);
0110 
0111     QDateTime fileTime(QFileDevice::FileTime time) const;
0112     bool setFileTime(const QDateTime &newDate, QFileDevice::FileTime fileTime);
0113 
0114 protected:
0115     QFileDevice();
0116 #ifdef QT_NO_QOBJECT
0117     QFileDevice(QFileDevicePrivate &dd);
0118 #else
0119     explicit QFileDevice(QObject *parent);
0120     QFileDevice(QFileDevicePrivate &dd, QObject *parent = nullptr);
0121 #endif
0122 
0123     qint64 readData(char *data, qint64 maxlen) override;
0124     qint64 writeData(const char *data, qint64 len) override;
0125     qint64 readLineData(char *data, qint64 maxlen) override;
0126 
0127 private:
0128     Q_DISABLE_COPY(QFileDevice)
0129 };
0130 
0131 Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDevice::Permissions)
0132 Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDevice::FileHandleFlags)
0133 Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDevice::MemoryMapFlags)
0134 
0135 QT_END_NAMESPACE
0136 
0137 #endif // QFILEDEVICE_H