text: // Copyright (c) Microsoft. All rights reserved.
  // Licensed under the MIT license. See LICENSE file in the project root for full license information.
  
  // stdafx-mac-common.h : mac-specific stdafx common to both the interop library and the kext
  
  #include <stddef.h>
  #include <stdint.h>
  
  #define PCWSTR const wchar_t*
  #define WCHAR wchar_t
  
  #define INT8 char
  #define INT16 short
  #define INT32 int
  #define BOOL char
  
  #define CHAR char
  #define PBYTE char*
  #define BYTE INT8
  #define WORD short
  #define PWCHAR wchar_t*
  
  #define HRESULT int
  #define DWORD unsigned int
  #define ANYSIZE_ARRAY 1
  #define WINAPI
  
  // TODO: Fix this type
  #define IO_COUNTERS long long
  #define FILETIME long long
  #define LONG64 long long
  
  #define __in
  #define __out
  #define __in_ecount(nBufferLength)
  #define __out_ecount(nBufferLength)
  
  #define Dbg(format, ...)
  
  typedef long NTSTATUS;
  typedef long long USN;
  typedef const WCHAR *LPCWSTR;
  typedef WCHAR *PWSTR;
  
  // =============== from winerror.h ==================
  
  #define ERROR_PATH_NOT_FOUND 3L
  #define ERROR_ACCESS_DENIED  5L
  #define ERROR_INVALID_NAME   123L
  
  // =============== from fileapi.h =====================
  
  #define CREATE_NEW        1
  #define CREATE_ALWAYS     2
  #define OPEN_EXISTING     3
  #define OPEN_ALWAYS       4
  #define TRUNCATE_EXISTING 5
  
  // =============== from winnt.h =====================
  
  #define GENERIC_READ    (0x80000000)
  #define GENERIC_WRITE   (0x40000000)
  #define GENERIC_EXECUTE (0x20000000)
  #define GENERIC_ALL     (0x10000000)
  #define WIN_DELETE      (0x00010000)
  #define MACOS_DELETE    (0x00010000L)
  #define READ_CONTROL    (0x00020000L)
  #define WRITE_DAC       (0x00040000L)
  #define WRITE_OWNER     (0x00080000L)
  #define SYNCHRONIZE     (0x00100000L)
  
  #define FILE_READ_DATA            ( 0x0001 )    // file & pipe
  #define FILE_LIST_DIRECTORY       ( 0x0001 )    // directory
  #define FILE_WRITE_DATA           ( 0x0002 )    // file & pipe
  #define FILE_ADD_FILE             ( 0x0002 )    // directory
  #define FILE_APPEND_DATA          ( 0x0004 )    // file
  #define FILE_ADD_SUBDIRECTORY     ( 0x0004 )    // directory
  #define FILE_CREATE_PIPE_INSTANCE ( 0x0004 )    // named pipe
  #define FILE_READ_EA              ( 0x0008 )    // file & directory
  #define FILE_WRITE_EA             ( 0x0010 )    // file & directory
  #define FILE_EXECUTE              ( 0x0020 )    // file
  #define FILE_TRAVERSE             ( 0x0020 )    // directory
  #define FILE_DELETE_CHILD         ( 0x0040 )    // directory
  #define FILE_READ_ATTRIBUTES      ( 0x0080 )    // all
  #define FILE_WRITE_ATTRIBUTES     ( 0x0100 )    // all
  
  #define FILE_ALL_ACCESS           (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1FF)
  #define FILE_GENERIC_READ         (STANDARD_RIGHTS_READ | FILE_READ_DATA | FILE_READ_ATTRIBUTES | FILE_READ_EA |SYNCHRONIZE)
  #define FILE_GENERIC_WRITE        (STANDARD_RIGHTS_WRITE | FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA | FILE_APPEND_DATA | SYNCHRONIZE)
  #define FILE_GENERIC_EXECUTE      (STANDARD_RIGHTS_EXECUTE | FILE_READ_ATTRIBUTES | FILE_EXECUTE | SYNCHRONIZE)
  
  #define FILE_SHARE_READ                     0x00000001
  #define FILE_SHARE_WRITE                    0x00000002
  #define FILE_SHARE_DELETE                   0x00000004
  #define FILE_ATTRIBUTE_READONLY             0x00000001
  #define FILE_ATTRIBUTE_HIDDEN               0x00000002
  #define FILE_ATTRIBUTE_SYSTEM               0x00000004
  #define FILE_ATTRIBUTE_DIRECTORY            0x00000010
  #define FILE_ATTRIBUTE_ARCHIVE              0x00000020
  #define FILE_ATTRIBUTE_DEVICE               0x00000040
  #define FILE_ATTRIBUTE_NORMAL               0x00000080
  #define FILE_ATTRIBUTE_TEMPORARY            0x00000100
  #define FILE_ATTRIBUTE_SPARSE_FILE          0x00000200
  #define FILE_ATTRIBUTE_REPARSE_POINT        0x00000400
  #define FILE_ATTRIBUTE_COMPRESSED           0x00000800
  #define FILE_ATTRIBUTE_OFFLINE              0x00001000
  #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED  0x00002000
  #define FILE_ATTRIBUTE_ENCRYPTED            0x00004000
  #define FILE_ATTRIBUTE_INTEGRITY_STREAM     0x00008000
  #define FILE_ATTRIBUTE_VIRTUAL              0x00010000
  #define FILE_ATTRIBUTE_NO_SCRUB_DATA        0x00020000
  #define FILE_ATTRIBUTE_EA                   0x00040000
  #define FILE_NOTIFY_CHANGE_FILE_NAME        0x00000001
  #define FILE_NOTIFY_CHANGE_DIR_NAME         0x00000002
  #define FILE_NOTIFY_CHANGE_ATTRIBUTES       0x00000004
  #define FILE_NOTIFY_CHANGE_SIZE             0x00000008
  #define FILE_NOTIFY_CHANGE_LAST_WRITE       0x00000010
  #define FILE_NOTIFY_CHANGE_LAST_ACCESS      0x00000020
  #define FILE_NOTIFY_CHANGE_CREATION         0x00000040
  #define FILE_NOTIFY_CHANGE_SECURITY         0x00000100
  #define FILE_ACTION_ADDED                   0x00000001
  #define FILE_ACTION_REMOVED                 0x00000002
  #define FILE_ACTION_MODIFIED                0x00000003
  #define FILE_ACTION_RENAMED_OLD_NAME        0x00000004
  #define FILE_ACTION_RENAMED_NEW_NAME        0x00000005
  #define MAILSLOT_NO_MESSAGE                 ((DWORD)-1)
  #define MAILSLOT_WAIT_FOREVER               ((DWORD)-1)
  #define FILE_CASE_SENSITIVE_SEARCH          0x00000001
  #define FILE_CASE_PRESERVED_NAMES           0x00000002
  #define FILE_UNICODE_ON_DISK                0x00000004
  #define FILE_PERSISTENT_ACLS                0x00000008
  #define FILE_FILE_COMPRESSION               0x00000010
  #define FILE_VOLUME_QUOTAS                  0x00000020
  #define FILE_SUPPORTS_SPARSE_FILES          0x00000040
  #define FILE_SUPPORTS_REPARSE_POINTS        0x00000080
  #define FILE_SUPPORTS_REMOTE_STORAGE        0x00000100
  #define FILE_VOLUME_IS_COMPRESSED           0x00008000
  #define FILE_SUPPORTS_OBJECT_IDS            0x00010000
  #define FILE_SUPPORTS_ENCRYPTION            0x00020000
  #define FILE_NAMED_STREAMS                  0x00040000
  #define FILE_READ_ONLY_VOLUME               0x00080000
  #define FILE_SEQUENTIAL_WRITE_ONCE          0x00100000
  #define FILE_SUPPORTS_TRANSACTIONS          0x00200000
  #define FILE_SUPPORTS_HARD_LINKS            0x00400000
  #define FILE_SUPPORTS_EXTENDED_ATTRIBUTES   0x00800000
  #define FILE_SUPPORTS_OPEN_BY_FILE_ID       0x01000000
  #define FILE_SUPPORTS_USN_JOURNAL           0x02000000
  #define FILE_SUPPORTS_INTEGRITY_STREAMS     0x04000000
  #define FILE_SUPPORTS_BLOCK_REFCOUNTING     0x08000000
  #define FILE_SUPPORTS_SPARSE_VDL            0x10000000
  
  #ifdef __cplusplus
  
  // Define operator overloads to enable bit operations on enum values that are
  // used to define flags. Use DEFINE_ENUM_FLAG_OPERATORS(YOUR_TYPE) to enable these
  // operators on YOUR_TYPE.
  
  // Moved here from objbase.w.
  
  // Templates are defined here in order to avoid a dependency on C++ <type_traits> header file,
  // or on compiler-specific contructs.
  extern "C++" {
      
      template <size_t S>
      struct _ENUM_FLAG_INTEGER_FOR_SIZE;
      
      template <>
      struct _ENUM_FLAG_INTEGER_FOR_SIZE<1>
      {
          typedef INT8 type;
      };
      
      template <>
      struct _ENUM_FLAG_INTEGER_FOR_SIZE<2>
      {
          typedef INT16 type;
      };
      
      template <>
      struct _ENUM_FLAG_INTEGER_FOR_SIZE<4>
      {
          typedef INT32 type;
      };
      
      // used as an approximation of std::underlying_type<T>
      template <class T>
      struct _ENUM_FLAG_SIZED_INTEGER
      {
          typedef typename _ENUM_FLAG_INTEGER_FOR_SIZE<sizeof(T)>::type type;
      };
      
  }
  
  #define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) \
  extern "C++" { \
  inline ENUMTYPE operator | (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a) | ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
  inline ENUMTYPE &operator |= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type &)a) |= ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
  inline ENUMTYPE operator & (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a) & ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
  inline ENUMTYPE &operator &= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type &)a) &= ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
  inline ENUMTYPE operator ~ (ENUMTYPE a) { return ENUMTYPE(~((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a)); } \
  inline ENUMTYPE operator ^ (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a) ^ ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
  inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type &)a) ^= ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
  }
  #else
  #define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) // NOP, C allows these operators.
  #endif
  
  #define __success(return)
  
  #define WriteWarningOrErrorF(format, ...)
  #define MaybeBreakOnAccessDenied()
  