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
52protected:
53 inline bool ensureFlushed() const;
54
55 bool putCharHelper(char c) override;
56
57 void setError(QFileDevice::FileError err);
58 void setError(QFileDevice::FileError err, const QString &errorString);
59 void setError(QFileDevice::FileError err, int errNum);
60
63
66
68};
69
71{
72 // This function ensures that the write buffer has been flushed (const
73 // because certain const functions need to call it.
74 if (lastWasWrite) {
75 const_cast<QFileDevicePrivate *>(this)->lastWasWrite = false;
76 if (!const_cast<QFileDevice *>(q_func())->flush())
77 return false;
78 }
79 return true;
80}
81
82#ifdef Q_OS_UNIX
83namespace QtPrivate {
84
85constexpr mode_t toMode_t(QFileDevice::Permissions permissions)
86{
87 mode_t mode = 0;
88 if (permissions & (QFileDevice::ReadOwner | QFileDevice::ReadUser))
89 mode |= S_IRUSR;
90 if (permissions & (QFileDevice::WriteOwner | QFileDevice::WriteUser))
91 mode |= S_IWUSR;
92 if (permissions & (QFileDevice::ExeOwner | QFileDevice::ExeUser))
93 mode |= S_IXUSR;
94 if (permissions & QFileDevice::ReadGroup)
95 mode |= S_IRGRP;
96 if (permissions & QFileDevice::WriteGroup)
97 mode |= S_IWGRP;
98 if (permissions & QFileDevice::ExeGroup)
99 mode |= S_IXGRP;
100 if (permissions & QFileDevice::ReadOther)
101 mode |= S_IROTH;
102 if (permissions & QFileDevice::WriteOther)
103 mode |= S_IWOTH;
104 if (permissions & QFileDevice::ExeOther)
105 mode |= S_IXOTH;
106 return mode;
107}
108
109} // namespace QtPrivate
110#elif defined(Q_OS_WINDOWS)
111
112class QNativeFilePermissions
113{
114public:
115 QNativeFilePermissions(std::optional<QFileDevice::Permissions> perms, bool isDir);
116
117 SECURITY_ATTRIBUTES *securityAttributes();
118 bool isOk() const { return ok; }
119
120private:
121 bool ok = false;
122 bool isNull = true;
123
124 // At most 1 allow + 1 deny ACEs for user and group, 1 allow ACE for others
125 static constexpr auto MaxNumACEs = 5;
126
127 static constexpr auto MaxACLSize =
128 sizeof(ACL) + (sizeof(ACCESS_ALLOWED_ACE) + SECURITY_MAX_SID_SIZE) * MaxNumACEs;
129
130 SECURITY_ATTRIBUTES sa;
131#if QT_CONFIG(fslibs)
132 SECURITY_DESCRIPTOR sd;
133 alignas(DWORD) char aclStorage[MaxACLSize];
134#endif
135};
136
137#endif // Q_OS_UNIX
138
139QT_END_NAMESPACE
140
141#endif // QFILEDEVICE_P_H
void setError(QFileDevice::FileError err, int errNum)
bool putCharHelper(char c) override
std::unique_ptr< QAbstractFileEngine > fileEngine
bool ensureFlushed() const
virtual QAbstractFileEngine * engine() const
void setError(QFileDevice::FileError err)
void setError(QFileDevice::FileError err, const QString &errorString)
\inmodule QtCore
Definition qfiledevice.h:33
#define QFILE_WRITEBUFFER_SIZE
#define QT_USE_NODISCARD_FILE_OPEN
Definition qfiledevice.h:20