Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: core/fxcrt/fxcrt_platforms.cpp

Issue 1994323002: Remove Release() from IFXCRT_FileAccess (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: include <utility>. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fxcrt/fxcrt_platforms.h ('k') | core/fxcrt/fxcrt_posix.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 PDFium Authors. All rights reserved.
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/fxcrt_platforms.h"
8
9 #include "core/fxcrt/include/fx_basic.h"
10
11 #if (_FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ && \
12 _FXM_PLATFORM_ != _FXM_PLATFORM_LINUX_ && \
13 _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ && \
14 _FXM_PLATFORM_ != _FXM_PLATFORM_ANDROID_)
15 IFXCRT_FileAccess* FXCRT_FileAccess_Create() {
16 return new CFXCRT_FileAccess_CRT;
17 }
18 void FXCRT_GetFileModeString(uint32_t dwModes, CFX_ByteString& bsMode) {
19 if (dwModes & FX_FILEMODE_ReadOnly) {
20 bsMode = "rb";
21 } else if (dwModes & FX_FILEMODE_Truncate) {
22 bsMode = "w+b";
23 } else {
24 bsMode = "a+b";
25 }
26 }
27 void FXCRT_GetFileModeString(uint32_t dwModes, CFX_WideString& wsMode) {
28 if (dwModes & FX_FILEMODE_ReadOnly) {
29 wsMode = FX_WSTRC(L"rb");
30 } else if (dwModes & FX_FILEMODE_Truncate) {
31 wsMode = FX_WSTRC(L"w+b");
32 } else {
33 wsMode = FX_WSTRC(L"a+b");
34 }
35 }
36 CFXCRT_FileAccess_CRT::CFXCRT_FileAccess_CRT() : m_hFile(NULL) {}
37 CFXCRT_FileAccess_CRT::~CFXCRT_FileAccess_CRT() {
38 Close();
39 }
40 FX_BOOL CFXCRT_FileAccess_CRT::Open(const CFX_ByteStringC& fileName,
41 uint32_t dwMode) {
42 if (m_hFile) {
43 return FALSE;
44 }
45 CFX_ByteString strMode;
46 FXCRT_GetFileModeString(dwMode, strMode);
47 m_hFile = FXSYS_fopen(fileName.c_str(), strMode.c_str());
48 return m_hFile != NULL;
49 }
50 FX_BOOL CFXCRT_FileAccess_CRT::Open(const CFX_WideStringC& fileName,
51 uint32_t dwMode) {
52 if (m_hFile) {
53 return FALSE;
54 }
55 CFX_WideString strMode;
56 FXCRT_GetFileModeString(dwMode, strMode);
57 m_hFile = FXSYS_wfopen(fileName.raw_str(), strMode.c_str());
58 return m_hFile != NULL;
59 }
60 void CFXCRT_FileAccess_CRT::Close() {
61 if (!m_hFile) {
62 return;
63 }
64 FXSYS_fclose(m_hFile);
65 m_hFile = NULL;
66 }
67 void CFXCRT_FileAccess_CRT::Release() {
68 delete this;
69 }
70 FX_FILESIZE CFXCRT_FileAccess_CRT::GetSize() const {
71 if (!m_hFile) {
72 return 0;
73 }
74 FX_FILESIZE pos = (FX_FILESIZE)FXSYS_ftell(m_hFile);
75 FXSYS_fseek(m_hFile, 0, FXSYS_SEEK_END);
76 FX_FILESIZE size = (FX_FILESIZE)FXSYS_ftell(m_hFile);
77 FXSYS_fseek(m_hFile, pos, FXSYS_SEEK_SET);
78 return size;
79 }
80 FX_FILESIZE CFXCRT_FileAccess_CRT::GetPosition() const {
81 if (!m_hFile) {
82 return (FX_FILESIZE)-1;
83 }
84 return (FX_FILESIZE)FXSYS_ftell(m_hFile);
85 }
86 FX_FILESIZE CFXCRT_FileAccess_CRT::SetPosition(FX_FILESIZE pos) {
87 if (!m_hFile) {
88 return (FX_FILESIZE)-1;
89 }
90 FXSYS_fseek(m_hFile, pos, FXSYS_SEEK_SET);
91 return (FX_FILESIZE)FXSYS_ftell(m_hFile);
92 }
93 size_t CFXCRT_FileAccess_CRT::Read(void* pBuffer, size_t szBuffer) {
94 if (!m_hFile) {
95 return 0;
96 }
97 return FXSYS_fread(pBuffer, 1, szBuffer, m_hFile);
98 }
99 size_t CFXCRT_FileAccess_CRT::Write(const void* pBuffer, size_t szBuffer) {
100 if (!m_hFile) {
101 return 0;
102 }
103 return FXSYS_fwrite(pBuffer, 1, szBuffer, m_hFile);
104 }
105 size_t CFXCRT_FileAccess_CRT::ReadPos(void* pBuffer,
106 size_t szBuffer,
107 FX_FILESIZE pos) {
108 if (!m_hFile) {
109 return (FX_FILESIZE)-1;
110 }
111 FXSYS_fseek(m_hFile, pos, FXSYS_SEEK_SET);
112 return FXSYS_fread(pBuffer, 1, szBuffer, m_hFile);
113 }
114 size_t CFXCRT_FileAccess_CRT::WritePos(const void* pBuffer,
115 size_t szBuffer,
116 FX_FILESIZE pos) {
117 if (!m_hFile) {
118 return (FX_FILESIZE)-1;
119 }
120 FXSYS_fseek(m_hFile, pos, FXSYS_SEEK_SET);
121 return FXSYS_fwrite(pBuffer, 1, szBuffer, m_hFile);
122 }
123 FX_BOOL CFXCRT_FileAccess_CRT::Flush() {
124 if (!m_hFile) {
125 return FALSE;
126 }
127 return !FXSYS_fflush(m_hFile);
128 }
129 FX_BOOL CFXCRT_FileAccess_CRT::Truncate(FX_FILESIZE szFile) {
130 return FALSE;
131 }
132 #endif
OLDNEW
« no previous file with comments | « core/fxcrt/fxcrt_platforms.h ('k') | core/fxcrt/fxcrt_posix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698