Home | History | Annotate | Download | only in fxcrt
      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 #ifndef CORE_FXCRT_EXTENSION_H_
      8 #define CORE_FXCRT_EXTENSION_H_
      9 
     10 #include <algorithm>
     11 #include <memory>
     12 
     13 #include "core/fxcrt/fx_basic.h"
     14 #include "core/fxcrt/fx_safe_types.h"
     15 
     16 class IFXCRT_FileAccess {
     17  public:
     18   static IFXCRT_FileAccess* Create();
     19   virtual ~IFXCRT_FileAccess() {}
     20 
     21   virtual bool Open(const CFX_ByteStringC& fileName, uint32_t dwMode) = 0;
     22   virtual bool Open(const CFX_WideStringC& fileName, uint32_t dwMode) = 0;
     23   virtual void Close() = 0;
     24   virtual FX_FILESIZE GetSize() const = 0;
     25   virtual FX_FILESIZE GetPosition() const = 0;
     26   virtual FX_FILESIZE SetPosition(FX_FILESIZE pos) = 0;
     27   virtual size_t Read(void* pBuffer, size_t szBuffer) = 0;
     28   virtual size_t Write(const void* pBuffer, size_t szBuffer) = 0;
     29   virtual size_t ReadPos(void* pBuffer, size_t szBuffer, FX_FILESIZE pos) = 0;
     30   virtual size_t WritePos(const void* pBuffer,
     31                           size_t szBuffer,
     32                           FX_FILESIZE pos) = 0;
     33   virtual bool Flush() = 0;
     34   virtual bool Truncate(FX_FILESIZE szFile) = 0;
     35 };
     36 
     37 #ifdef __cplusplus
     38 extern "C" {
     39 #endif
     40 #define MT_N 848
     41 #define MT_M 456
     42 #define MT_Matrix_A 0x9908b0df
     43 #define MT_Upper_Mask 0x80000000
     44 #define MT_Lower_Mask 0x7fffffff
     45 struct FX_MTRANDOMCONTEXT {
     46   FX_MTRANDOMCONTEXT() {
     47     mti = MT_N + 1;
     48     bHaveSeed = false;
     49   }
     50   uint32_t mti;
     51   bool bHaveSeed;
     52   uint32_t mt[MT_N];
     53 };
     54 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
     55 bool FX_GenerateCryptoRandom(uint32_t* pBuffer, int32_t iCount);
     56 #endif
     57 #ifdef __cplusplus
     58 }
     59 #endif
     60 
     61 #endif  // CORE_FXCRT_EXTENSION_H_
     62