0

I wrote a simple test, but it's not working. Why CreateFile with FILE_FLAG_POSIX_SEMANTICS flag allows me to open the file named "stamp.oS" on an NTFS disk in the second case?

#include "stdafx.h"
#include <windows.h>
#include <iostream>

int main()
{
  auto h = CreateFileA("c:\\stamp.oS", GENERIC_READ, 0, NULL, OPEN_EXISTING, 
    FILE_FLAG_POSIX_SEMANTICS, NULL);

  if (h == INVALID_HANDLE_VALUE)
    std::cout << "bad first try" << std::endl;
  else
  {
    std::cout << "yeah first" << std::endl;
    CloseHandle(h);
  }


  h = CreateFileA("c:\\stamp.os", GENERIC_READ, 0, NULL, OPEN_EXISTING,
    FILE_FLAG_POSIX_SEMANTICS, NULL);

  if (h == INVALID_HANDLE_VALUE)
    std::cout << "bad second try" << std::endl;
  else
  {
    std::cout << "yeah second" << std::endl;
    CloseHandle(h);
  }

  system("pause");
    return 0;
}

Output:

yeah first
yeah second
Carles Araguz
  • 1,157
  • 1
  • 17
  • 37
fsmoke
  • 135
  • 6
  • because file system, which handle this request, ignore `OBJ_CASE_INSENSITIVE` flag in object attributes. better question - why you use `CreateFileA` instead `CreateFileW` – RbMm Jun 21 '18 at 16:54
  • 2
    The obcaseinsensitive registry key matters. https://stackoverflow.com/a/39116635/17034 – Hans Passant Jun 21 '18 at 17:04

0 Answers0