text: //-------------------------------------------------------------------------------------------------------
  // Copyright (C) Microsoft Corporation. All rights reserved.
  // Licensed under the MIT license. See LICENSE file in the project root for full license information.
  //-------------------------------------------------------------------------------------------------------
  
  #include "FunctionImplementations.h"
  #include "PathRedirection.h"
  
  template <typename CharT>
  HANDLE __stdcall CreateFileFixup(
      _In_ const CharT* fileName,
      _In_ DWORD desiredAccess,
      _In_ DWORD shareMode,
      _In_opt_ LPSECURITY_ATTRIBUTES securityAttributes,
      _In_ DWORD creationDisposition,
      _In_ DWORD flagsAndAttributes,
      _In_opt_ HANDLE templateFile) noexcept
  {
      auto guard = g_reentrancyGuard.enter();
      try
      {
          if (guard)
          {
              // FUTURE: If 'creationDisposition' is something like 'CREATE_ALWAYS', we could get away with something
              //         cheaper than copy-on-read, but we'd also need to be mindful of ensuring the correct error if so
              auto [shouldRedirect, redirectPath] = ShouldRedirect(fileName, redirect_flags::copy_on_read);
              if (shouldRedirect)
              {
                  return impl::CreateFile(redirectPath.c_str(), desiredAccess, shareMode, securityAttributes, creationDisposition, flagsAndAttributes, templateFile);
              }
          }
      }
      catch (...)
      {
          // Fall back to assuming no redirection is necessary
      }
  
      return impl::CreateFile(fileName, desiredAccess, shareMode, securityAttributes, creationDisposition, flagsAndAttributes, templateFile);
  }
  DECLARE_STRING_FIXUP(impl::CreateFile, CreateFileFixup);
  
  HANDLE __stdcall CreateFile2Fixup(
      _In_ LPCWSTR fileName,
      _In_ DWORD desiredAccess,
      _In_ DWORD shareMode,
      _In_ DWORD creationDisposition,
      _In_opt_ LPCREATEFILE2_EXTENDED_PARAMETERS createExParams) noexcept
  {
      auto guard = g_reentrancyGuard.enter();
      try
      {
          if (guard)
          {
              // FUTURE: See comment in CreateFileFixup about using 'creationDisposition' to choose a potentially better
              //         redirect flags value
              auto [shouldRedirect, redirectPath] = ShouldRedirect(fileName, redirect_flags::copy_on_read);
              if (shouldRedirect)
              {
                  return impl::CreateFile2(redirectPath.c_str(), desiredAccess, shareMode, creationDisposition, createExParams);
              }
          }
      }
      catch (...)
      {
          // Fall back to assuming no redirection is necessary
      }
  
      return impl::CreateFile2(fileName, desiredAccess, shareMode, creationDisposition, createExParams);
  }
  DECLARE_FIXUP(impl::CreateFile2, CreateFile2Fixup);
  