Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qfiledevice_p.h
Go to the documentation of this file.
1// Copyright (C) 2022 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// Qt-Security score:significant reason:default
4
5#ifndef QFILEDEVICE_P_H
6#define QFILEDEVICE_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include "private/qiodevice_p.h"
20#include "qfiledevice.h"
21
22#include <memory>
23#if defined(Q_OS_UNIX)
24# include <sys/types.h> // for mode_t
25# include <sys/stat.h> // for mode_t constants
26#elif defined(Q_OS_WINDOWS)
27# include <qt_windows.h>
28# include <winnt.h> // for SECURITY_DESCRIPTOR
29# include <optional>
30# if defined(QT_BOOTSTRAPPED)
31# define QT_FEATURE_fslibs -1
32# else
33# define QT_FEATURE_fslibs 1
34# endif // QT_BOOTSTRAPPED
35#endif
36
37QT_BEGIN_NAMESPACE
38
39class QAbstractFileEngine;
40class QFSFileEngine;
41
43{
44 Q_DECLARE_PUBLIC(QFileDevice)
45protected:
48
49public:
50 virtual QAbstractFileEngine *engine() const;
51
52 virtual QFileDevice::Permissions permissions() const;
53 virtual bool setPermissions(QFileDevice::Permissions perms);
54
55protected:
56 inline bool ensureFlushed() const;
57
58 bool putCharHelper(char c) override;
59
60 void setError(QFileDevice::FileError err);
61 void setError(QFileDevice::FileError err, QString errorString);
62 void setError(QFileDevice::FileError err, int errNum);
63
66
69
71};
72
74{
75 // This function ensures that the write buffer has been flushed (const
76 // because certain const functions need to call it.
77 if (lastWasWrite) {
78 const_cast<QFileDevicePrivate *>(this)->lastWasWrite = false;
79 if (!const_cast<QFileDevice *>(q_func())->flush())
80 return false;
81 }
82 return true;
83}
84
85#ifdef Q_OS_UNIX
86namespace QtPrivate {
87
88constexpr mode_t toMode_t(QFileDevice::Permissions permissions)
89{
90 mode_t mode = 0;
91 if (permissions & (QFileDevice::ReadOwner | QFileDevice::ReadUser))
92 mode |= S_IRUSR;
93 if (permissions & (QFileDevice::WriteOwner | QFileDevice::WriteUser))
94 mode |= S_IWUSR;
95 if (permissions & (QFileDevice::ExeOwner | QFileDevice::ExeUser))
96 mode |= S_IXUSR;
97 if (permissions & QFileDevice::ReadGroup)
98 mode |= S_IRGRP;
99 if (permissions & QFileDevice::WriteGroup)
100 mode |= S_IWGRP;
101 if (permissions & QFileDevice::ExeGroup)
102 mode |= S_IXGRP;
103 if (permissions & QFileDevice::ReadOther)
104 mode |= S_IROTH;
105 if (permissions & QFileDevice::WriteOther)
106 mode |= S_IWOTH;
107 if (permissions & QFileDevice::ExeOther)
108 mode |= S_IXOTH;
109 return mode;
110}
111
112} // namespace QtPrivate
113#elif defined(Q_OS_WINDOWS)
114
115class QNativeFilePermissions
116{
117public:
118 QNativeFilePermissions(std::optional<QFileDevice::Permissions> perms, bool isDir);
119
120 SECURITY_ATTRIBUTES *securityAttributes();
121 bool isOk() const { return ok; }
122
123private:
124 bool ok = false;
125 bool isNull = true;
126
127 // At most 1 allow + 1 deny ACEs for user and group, 1 allow ACE for others
128 static constexpr auto MaxNumACEs = 5;
129
130 static constexpr auto MaxACLSize =
131 sizeof(ACL) + (sizeof(ACCESS_ALLOWED_ACE) + SECURITY_MAX_SID_SIZE) * MaxNumACEs;
132
133 SECURITY_ATTRIBUTES sa;
134#if QT_CONFIG(fslibs)
135 SECURITY_DESCRIPTOR sd;
136 alignas(DWORD) char aclStorage[MaxACLSize];
137#endif
138};
139
140#endif // Q_OS_UNIX
141
142QT_END_NAMESPACE
143
144#endif // QFILEDEVICE_P_H
bool putCharHelper(char c) override
std::unique_ptr< QAbstractFileEngine > fileEngine
bool ensureFlushed() const
void setError(QFileDevice::FileError err, QString errorString)
virtual QAbstractFileEngine * engine() const
void setError(QFileDevice::FileError err)
virtual bool setPermissions(QFileDevice::Permissions perms)
\inmodule QtCore
Definition qfiledevice.h:65
Combined button and popup list for selecting options.
#define QFILE_WRITEBUFFER_SIZE
#define QT_USE_NODISCARD_FILE_OPEN
Definition qfiledevice.h:52