[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Proposal: Virtualization of Filesystem Operations for Lua 5.2.
- From: Patrick Rapin <toupie300@...>
- Date: Thu, 3 Nov 2011 22:02:58 +0100
> With that said, what does fopen() under Windows do when given a UTF-8
> encoded filename?
It does not work (returning NULL), unless the filename is pure ASCII.
Windows uses UTF-16 throughout the kernel for all strings, including filenames.
For all C functions expecting const char* strings, like fopen, the
current locale is used to convert into wchar_t* wide strings.
And for some (stupid?) reason, it is impossible to set UTF-8 as the
current locale on Windows !
So to support full Unicode stings while keeping ASCII compatibility,
you have to hack a little.
First convert strings from UTF-8 to UTF-16, and then call the wide
string version of the function, in that case _wfopen.
This is why there would be a need for filesystem virtualization.
Instead of directly calling fopen, Lua should call a pointer to an
The pointer default would of course be fopen, but could be an UTF-8
adapter function using _wfopen, or something else (imagine opening
from a ZIP file).