"Fossies" - the Fresh Open Source Software Archive

Member "src/Platform/PlatformBase.h" (10 Oct 2018, 3581 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "PlatformBase.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  Derived from source code of TrueCrypt 7.1a, which is
    3  Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
    4  by the TrueCrypt License 3.0.
    5 
    6  Modifications and additions to the original source code (contained in this file)
    7  and all other portions of this file are Copyright (c) 2013-2017 IDRIX
    8  and are governed by the Apache License 2.0 the full text of which is
    9  contained in the file License.txt included in VeraCrypt binary and source
   10  code distribution packages.
   11 */
   12 
   13 #ifndef TC_HEADER_Platform_PlatformBase
   14 #define TC_HEADER_Platform_PlatformBase
   15 
   16 #include <cstddef>
   17 #include <list>
   18 #include <map>
   19 #include <memory>
   20 #include <sstream>
   21 #include <string>
   22 #include <vector>
   23 
   24 #ifndef _MSC_VER
   25 #include <inttypes.h>
   26 #endif
   27 
   28 using namespace std;
   29 
   30 #ifdef nullptr
   31 #undef nullptr
   32 #endif
   33 
   34 #if !(defined(_MSC_VER) && _MSC_VER >= 1600)
   35 #define nullptr 0
   36 #endif
   37 
   38 namespace VeraCrypt
   39 {
   40 #ifdef _MSC_VER
   41 #   ifndef TC_INT_TYPES_DEFINED
   42     typedef __int8 int8;
   43     typedef __int16 int16;
   44     typedef __int32 int32;
   45     typedef __int64 int64;
   46     typedef unsigned __int8 byte;
   47     typedef unsigned __int16 uint16;
   48     typedef unsigned __int32 uint32;
   49     typedef unsigned __int64 uint64;
   50 #   endif
   51 #else
   52     typedef int8_t int8;
   53     typedef int16_t int16;
   54     typedef int32_t int32;
   55     typedef int64_t int64;
   56     typedef uint8_t byte;
   57     typedef uint16_t uint16;
   58     typedef uint32_t uint32;
   59     typedef uint64_t uint64;
   60 #endif
   61 }
   62 
   63 #if (defined(_WIN32) || defined(_WIN64)) && !defined(TC_WINDOWS)
   64 #   define TC_WINDOWS
   65 #endif
   66 
   67 #if defined(_DEBUG) && !defined(DEBUG)
   68 #   define DEBUG
   69 #endif
   70 
   71 #ifndef TC_TO_STRING
   72 #   define TC_TO_STRING2(n) #n
   73 #   define TC_TO_STRING(n) TC_TO_STRING2(n)
   74 #endif
   75 
   76 #define TC_JOIN_ARGS(a,b) a##b
   77 #define TC_JOIN(a,b) TC_JOIN_ARGS(a,b)
   78 
   79 #ifdef __GNUC__
   80     template <class T> string GetFunctionName (T pos)
   81     {
   82         string s (pos);
   83         size_t p = s.find ('(');
   84         if (p == string::npos)
   85             return s;
   86         s = s.substr (0, p);
   87         p = s.find_last_of (" ");
   88         if (p == string::npos)
   89             return s;
   90         return s.substr (p + 1);
   91     }
   92 #   define SRC_POS (GetFunctionName (__PRETTY_FUNCTION__) += ":" TC_TO_STRING(__LINE__))
   93 #   define TC_UNUSED_VAR __attribute__ ((unused))
   94 #else
   95 #   define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
   96 #   define TC_UNUSED_VAR
   97 #endif
   98 
   99 #ifdef trace_point
  100 #   undef trace_point
  101 #endif
  102 
  103 #ifdef trace_msg
  104 #   undef trace_msg
  105 #endif
  106 
  107 #ifdef DEBUG
  108 #   define if_debug(...) __VA_ARGS__
  109 
  110 #   ifdef TC_WINDOWS
  111 #       define trace_point OutputDebugStringA ((string (SRC_POS) + "\n").c_str())
  112 #       define trace_msg(stream_args) do { stringstream s; s << (SRC_POS) << ": " << stream_args << endl; OutputDebugStringA (s.str().c_str()); } while (0)
  113 #       define trace_msgw(stream_args) do { wstringstream s; s << (SRC_POS) << L": " << stream_args << endl; OutputDebugStringW (s.str().c_str()); } while (0)
  114 #   else
  115 #       include <iostream>
  116 #       define trace_point cerr << (SRC_POS) << endl
  117 #       define trace_msg(stream_args) cerr << (SRC_POS) << ": " << stream_args << endl
  118 #       define trace_msgw(stream_args) cerr << (SRC_POS); wcerr << L": " << stream_args << endl
  119 #   endif
  120 
  121 #   include "Platform/SystemLog.h"
  122 #   define trace_log_point SystemLog::WriteError (SRC_POS)
  123 #   define trace_log_msg(stream_args) do { stringstream s; s << (SRC_POS) << ": " << stream_args; SystemLog::WriteError (s.str()); } while (0)
  124 
  125 #else
  126 #   define if_debug(...)
  127 #   define trace_point
  128 #   define trace_msg(...)
  129 #   define trace_msgw(...)
  130 #   define trace_log_point
  131 #   define trace_log_msg(...)
  132 #endif
  133 
  134 #define trace_val(VAL) trace_msg (#VAL << '=' << (VAL));
  135 
  136 #define array_capacity(arr) (sizeof (arr) / sizeof ((arr)[0]))
  137 
  138 #endif // TC_HEADER_Platform_PlatformBase