Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
37
QT_BEGIN_NAMESPACE
38
39
class
QAbstractFileEngine;
40
class
QFSFileEngine;
41
42
class
QFileDevicePrivate
:
public
QIODevicePrivate
43
{
44
Q_DECLARE_PUBLIC(QFileDevice)
45
protected
:
46
QFileDevicePrivate
();
47
~
QFileDevicePrivate
();
48
49
public
:
50
virtual
QAbstractFileEngine *
engine
()
const
;
51
52
virtual
QFileDevice
::
Permissions
permissions
()
const
;
53
virtual
bool
setPermissions
(QFileDevice::Permissions perms);
54
55
protected
:
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
64
mutable
std
::
unique_ptr
<
QAbstractFileEngine
>
fileEngine
;
65
mutable
qint64
cachedSize
;
66
67
QFileDevice
::
FileHandleFlags
handleFlags
;
68
QFileDevice
::
FileError
error
;
69
70
bool
lastWasWrite
;
71
};
72
73
inline
bool
QFileDevicePrivate
::
ensureFlushed
()
const
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
86
namespace
QtPrivate {
87
88
constexpr
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
115
class
QNativeFilePermissions
116
{
117
public
:
118
QNativeFilePermissions(std::optional<QFileDevice::Permissions> perms,
bool
isDir);
119
120
SECURITY_ATTRIBUTES *securityAttributes();
121
bool
isOk()
const
{
return
ok; }
122
123
private
:
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
142
QT_END_NAMESPACE
143
144
#
endif
// QFILEDEVICE_P_H
QFileDevicePrivate
Definition
qfiledevice_p.h:43
QFileDevicePrivate::putCharHelper
bool putCharHelper(char c) override
Definition
qfiledevice.cpp:507
QFileDevicePrivate::fileEngine
std::unique_ptr< QAbstractFileEngine > fileEngine
Definition
qfiledevice_p.h:64
QFileDevicePrivate::ensureFlushed
bool ensureFlushed() const
Definition
qfiledevice_p.h:73
QFileDevicePrivate::lastWasWrite
bool lastWasWrite
Definition
qfiledevice_p.h:70
QFileDevicePrivate::setError
void setError(QFileDevice::FileError err, QString errorString)
Definition
qfiledevice.cpp:58
QFileDevicePrivate::engine
virtual QAbstractFileEngine * engine() const
Definition
qfiledevice.cpp:29
QFileDevicePrivate::setError
void setError(QFileDevice::FileError err)
Definition
qfiledevice.cpp:52
QFileDevicePrivate::setPermissions
virtual bool setPermissions(QFileDevice::Permissions perms)
Definition
qfiledevice.cpp:42
QFileDevicePrivate::~QFileDevicePrivate
~QFileDevicePrivate()
QFileDevicePrivate::cachedSize
qint64 cachedSize
Definition
qfiledevice_p.h:65
QFileDevice
\inmodule QtCore
Definition
qfiledevice.h:65
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QFILE_WRITEBUFFER_SIZE
#define QFILE_WRITEBUFFER_SIZE
Definition
qfiledevice.cpp:17
QT_USE_NODISCARD_FILE_OPEN
#define QT_USE_NODISCARD_FILE_OPEN
Definition
qfiledevice.h:52
qtbase
src
corelib
io
qfiledevice_p.h
Generated on
for Qt by
1.18.0