OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fxcrt/fxcrt_posix.h" | 7 #include "core/fxcrt/fxcrt_posix.h" |
8 | 8 |
9 #include "core/fxcrt/fx_basic.h" | 9 #include "core/fxcrt/fx_basic.h" |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 if (dwModes & FX_FILEMODE_Truncate) { | 29 if (dwModes & FX_FILEMODE_Truncate) { |
30 nFlags |= O_TRUNC; | 30 nFlags |= O_TRUNC; |
31 } | 31 } |
32 nMasks = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; | 32 nMasks = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; |
33 } | 33 } |
34 } | 34 } |
35 CFXCRT_FileAccess_Posix::CFXCRT_FileAccess_Posix() : m_nFD(-1) {} | 35 CFXCRT_FileAccess_Posix::CFXCRT_FileAccess_Posix() : m_nFD(-1) {} |
36 CFXCRT_FileAccess_Posix::~CFXCRT_FileAccess_Posix() { | 36 CFXCRT_FileAccess_Posix::~CFXCRT_FileAccess_Posix() { |
37 Close(); | 37 Close(); |
38 } | 38 } |
39 FX_BOOL CFXCRT_FileAccess_Posix::Open(const CFX_ByteStringC& fileName, | 39 |
40 uint32_t dwMode) { | 40 bool CFXCRT_FileAccess_Posix::Open(const CFX_ByteStringC& fileName, |
41 if (m_nFD > -1) { | 41 uint32_t dwMode) { |
42 return FALSE; | 42 if (m_nFD > -1) |
43 } | 43 return false; |
44 int32_t nFlags, nMasks; | 44 |
| 45 int32_t nFlags; |
| 46 int32_t nMasks; |
45 FXCRT_Posix_GetFileMode(dwMode, nFlags, nMasks); | 47 FXCRT_Posix_GetFileMode(dwMode, nFlags, nMasks); |
46 m_nFD = open(fileName.c_str(), nFlags, nMasks); | 48 m_nFD = open(fileName.c_str(), nFlags, nMasks); |
47 return m_nFD > -1; | 49 return m_nFD > -1; |
48 } | 50 } |
49 FX_BOOL CFXCRT_FileAccess_Posix::Open(const CFX_WideStringC& fileName, | 51 |
50 uint32_t dwMode) { | 52 bool CFXCRT_FileAccess_Posix::Open(const CFX_WideStringC& fileName, |
| 53 uint32_t dwMode) { |
51 return Open(FX_UTF8Encode(fileName).AsStringC(), dwMode); | 54 return Open(FX_UTF8Encode(fileName).AsStringC(), dwMode); |
52 } | 55 } |
| 56 |
53 void CFXCRT_FileAccess_Posix::Close() { | 57 void CFXCRT_FileAccess_Posix::Close() { |
54 if (m_nFD < 0) { | 58 if (m_nFD < 0) { |
55 return; | 59 return; |
56 } | 60 } |
57 close(m_nFD); | 61 close(m_nFD); |
58 m_nFD = -1; | 62 m_nFD = -1; |
59 } | 63 } |
60 FX_FILESIZE CFXCRT_FileAccess_Posix::GetSize() const { | 64 FX_FILESIZE CFXCRT_FileAccess_Posix::GetSize() const { |
61 if (m_nFD < 0) { | 65 if (m_nFD < 0) { |
62 return 0; | 66 return 0; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 size_t szBuffer, | 112 size_t szBuffer, |
109 FX_FILESIZE pos) { | 113 FX_FILESIZE pos) { |
110 if (m_nFD < 0) { | 114 if (m_nFD < 0) { |
111 return 0; | 115 return 0; |
112 } | 116 } |
113 if (SetPosition(pos) == (FX_FILESIZE)-1) { | 117 if (SetPosition(pos) == (FX_FILESIZE)-1) { |
114 return 0; | 118 return 0; |
115 } | 119 } |
116 return Write(pBuffer, szBuffer); | 120 return Write(pBuffer, szBuffer); |
117 } | 121 } |
118 FX_BOOL CFXCRT_FileAccess_Posix::Flush() { | 122 |
119 if (m_nFD < 0) { | 123 bool CFXCRT_FileAccess_Posix::Flush() { |
120 return FALSE; | 124 if (m_nFD < 0) |
121 } | 125 return false; |
| 126 |
122 return fsync(m_nFD) > -1; | 127 return fsync(m_nFD) > -1; |
123 } | 128 } |
124 FX_BOOL CFXCRT_FileAccess_Posix::Truncate(FX_FILESIZE szFile) { | 129 |
125 if (m_nFD < 0) { | 130 bool CFXCRT_FileAccess_Posix::Truncate(FX_FILESIZE szFile) { |
126 return FALSE; | 131 if (m_nFD < 0) |
127 } | 132 return false; |
| 133 |
128 return !ftruncate(m_nFD, szFile); | 134 return !ftruncate(m_nFD, szFile); |
129 } | 135 } |
130 | 136 |
131 #endif | 137 #endif |
OLD | NEW |