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
cfx_fileaccess_posix.cpp
Go to the documentation of this file.
1
// Copyright 2014 The PDFium Authors
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7
#
include
"core/fxcrt/cfx_fileaccess_posix.h"
8
9
#
include
<
fcntl
.
h
>
10
#
include
<
sys
/
stat
.
h
>
11
#
include
<
unistd
.
h
>
12
13
#
include
<
memory
>
14
15
#
include
"core/fxcrt/fx_stream.h"
16
#
include
"core/fxcrt/numerics/safe_conversions.h"
17
18
#
ifndef
O_BINARY
19
#
define
O_BINARY
0
20
#
endif
// O_BINARY
21
22
#
ifndef
O_LARGEFILE
23
#
define
O_LARGEFILE
0
24
#
endif
// O_LARGEFILE
25
26
// static
27
std::unique_ptr<FileAccessIface>
FileAccessIface
::Create() {
28
return
std
::make_unique<CFX_FileAccess_Posix>();
29
}
30
31
CFX_FileAccess_Posix::
CFX_FileAccess_Posix
() : m_nFD(-1) {}
32
33
CFX_FileAccess_Posix::~
CFX_FileAccess_Posix
() {
34
Close
(
)
;
35
}
36
37
bool
CFX_FileAccess_Posix::
Open
(
ByteStringView
fileName) {
38
if
(m_nFD > -1)
39
return
false
;
40
41
// TODO(tsepez): check usage of c_str() below.
42
m_nFD =
43
open(fileName.unterminated_c_str(),
O_BINARY
|
O_LARGEFILE
| O_RDONLY);
44
return
m_nFD > -1;
45
}
46
47
void
CFX_FileAccess_Posix::
Close
() {
48
if
(m_nFD < 0) {
49
return
;
50
}
51
close(m_nFD);
52
m_nFD = -1;
53
}
54
55
FX_FILESIZE
CFX_FileAccess_Posix::
GetSize
()
const
{
56
if
(m_nFD < 0) {
57
return
0;
58
}
59
struct
stat s = {};
60
fstat(m_nFD, &s);
61
return
pdfium
::checked_cast<
FX_FILESIZE
>(s.st_size);
62
}
63
64
FX_FILESIZE
CFX_FileAccess_Posix::
GetPosition
()
const
{
65
if
(m_nFD < 0) {
66
return
(
FX_FILESIZE
)-1;
67
}
68
return
lseek(m_nFD, 0, SEEK_CUR);
69
}
70
71
FX_FILESIZE
CFX_FileAccess_Posix::
SetPosition
(
FX_FILESIZE
pos) {
72
if
(m_nFD < 0) {
73
return
(
FX_FILESIZE
)-1;
74
}
75
return
lseek(m_nFD, pos, SEEK_SET);
76
}
77
78
size_t
CFX_FileAccess_Posix::
Read
(pdfium::span<uint8_t> buffer) {
79
if
(m_nFD < 0) {
80
return
0;
81
}
82
return
read(m_nFD, buffer.data(), buffer.size());
83
}
84
85
size_t
CFX_FileAccess_Posix::
Write
(pdfium::span<
const
uint8_t> buffer) {
86
if
(m_nFD < 0) {
87
return
0;
88
}
89
return
write(m_nFD, buffer.data(), buffer.size());
90
}
91
92
size_t
CFX_FileAccess_Posix::
ReadPos
(pdfium::span<uint8_t> buffer,
93
FX_FILESIZE
pos) {
94
if
(m_nFD < 0) {
95
return
0;
96
}
97
if
(pos >=
GetSize
(
)
) {
98
return
0;
99
}
100
if
(
SetPosition
(
pos
)
== (
FX_FILESIZE
)-1) {
101
return
0;
102
}
103
return
Read(buffer);
104
}
105
106
bool
CFX_FileAccess_Posix::
Flush
() {
107
if
(m_nFD < 0)
108
return
false
;
109
110
return
fsync(m_nFD) > -1;
111
}
112
113
bool
CFX_FileAccess_Posix::
Truncate
(
FX_FILESIZE
szFile) {
114
if
(m_nFD < 0)
115
return
false
;
116
117
return
!ftruncate(m_nFD, szFile);
118
}
O_LARGEFILE
#define O_LARGEFILE
Definition
cfx_fileaccess_posix.cpp:23
O_BINARY
#define O_BINARY
Definition
cfx_fileaccess_posix.cpp:19
CFX_FileAccess_Posix::~CFX_FileAccess_Posix
~CFX_FileAccess_Posix() override
Definition
cfx_fileaccess_posix.cpp:33
CFX_FileAccess_Posix::ReadPos
size_t ReadPos(pdfium::span< uint8_t > buffer, FX_FILESIZE pos) override
Definition
cfx_fileaccess_posix.cpp:92
CFX_FileAccess_Posix::Write
size_t Write(pdfium::span< const uint8_t > buffer) override
Definition
cfx_fileaccess_posix.cpp:85
CFX_FileAccess_Posix::CFX_FileAccess_Posix
CFX_FileAccess_Posix()
Definition
cfx_fileaccess_posix.cpp:31
CFX_FileAccess_Posix::GetSize
FX_FILESIZE GetSize() const override
Definition
cfx_fileaccess_posix.cpp:55
CFX_FileAccess_Posix::Flush
bool Flush() override
Definition
cfx_fileaccess_posix.cpp:106
CFX_FileAccess_Posix::Read
size_t Read(pdfium::span< uint8_t > buffer) override
Definition
cfx_fileaccess_posix.cpp:78
CFX_FileAccess_Posix::SetPosition
FX_FILESIZE SetPosition(FX_FILESIZE pos) override
Definition
cfx_fileaccess_posix.cpp:71
CFX_FileAccess_Posix::Open
bool Open(ByteStringView fileName) override
Definition
cfx_fileaccess_posix.cpp:37
CFX_FileAccess_Posix::Close
void Close() override
Definition
cfx_fileaccess_posix.cpp:47
CFX_FileAccess_Posix::Truncate
bool Truncate(FX_FILESIZE szFile) override
Definition
cfx_fileaccess_posix.cpp:113
CFX_FileAccess_Posix::GetPosition
FX_FILESIZE GetPosition() const override
Definition
cfx_fileaccess_posix.cpp:64
FileAccessIface
Definition
fileaccess_iface.h:15
pdfium::CFDETextOutLargeBitmapTest
Definition
cfde_textout_unittest.cpp:117
FX_FILESIZE
#define FX_FILESIZE
Definition
fx_types.h:19
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
ByteStringView
fxcrt::ByteStringView ByteStringView
Definition
string_view_template.h:325
qtwebengine
src
3rdparty
chromium
third_party
pdfium
core
fxcrt
cfx_fileaccess_posix.cpp
Generated on
for Qt by
1.18.0