xref: /aosp_15_r20/external/pdfium/core/fxcrt/cfx_fileaccess_posix.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
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 #ifndef CORE_FXCRT_CFX_FILEACCESS_POSIX_H_
8 #define CORE_FXCRT_CFX_FILEACCESS_POSIX_H_
9 
10 #include <stddef.h>
11 #include <stdint.h>
12 
13 #include "build/build_config.h"
14 #include "core/fxcrt/fileaccess_iface.h"
15 #include "core/fxcrt/fx_types.h"
16 
17 #if !BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_FUCHSIA)
18 #error "Included on the wrong platform"
19 #endif
20 
21 class CFX_FileAccess_Posix final : public FileAccessIface {
22  public:
23   CFX_FileAccess_Posix();
24   ~CFX_FileAccess_Posix() override;
25 
26   // FileAccessIface:
27   bool Open(ByteStringView fileName) override;
28   void Close() override;
29   FX_FILESIZE GetSize() const override;
30   FX_FILESIZE GetPosition() const override;
31   FX_FILESIZE SetPosition(FX_FILESIZE pos) override;
32   size_t Read(void* pBuffer, size_t szBuffer) override;
33   size_t Write(const void* pBuffer, size_t szBuffer) override;
34   size_t ReadPos(void* pBuffer, size_t szBuffer, FX_FILESIZE pos) override;
35   size_t WritePos(const void* pBuffer,
36                   size_t szBuffer,
37                   FX_FILESIZE pos) override;
38   bool Flush() override;
39   bool Truncate(FX_FILESIZE szFile) override;
40 
41  private:
42   int32_t m_nFD = -1;
43 };
44 
45 #endif  // CORE_FXCRT_CFX_FILEACCESS_POSIX_H_
46