Skip to content

Instantly share code, notes, and snippets.

@k-takata
Last active August 29, 2015 14:07
Show Gist options
  • Save k-takata/e79e99b7525857dd6214 to your computer and use it in GitHub Desktop.
Save k-takata/e79e99b7525857dd6214 to your computer and use it in GitHub Desktop.
Create a very long file name with ANSI API
#include <windows.h>
main(int argc, char *argv[])
{
char *filename = "あいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえお.txt";
HANDLE h;
h = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
printf("handle:%p, length:%d\n", h, strlen(filename));
CloseHandle(h);
}
@k-takata
Copy link
Author

The length of filename is:

  • 404 bytes in CP932
  • 204 characters in UTF-16LE
  • (604 bytes in UTF-8)

It is obvious that the length is longer then MAX_PATH (=260) bytes, but CreateFileA does create the file.
Why CreateFileA can handle a filename which is longer than MAX_PATH bytes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment