develooper Front page | perl.perl5.porters | Postings from March 2013

RE: [perl #117265] [PATCH] e213661 no warnings 'safesyscalls', fatal nul checks

Thread Previous | Thread Next
Steve Hay
March 25, 2013 14:42
RE: [perl #117265] [PATCH] e213661 no warnings 'safesyscalls', fatal nul checks
Message ID:
Leon Timmermans wrote on 2013-03-25:
> On Mon, Mar 25, 2013 at 3:14 PM, demerphq <> wrote:
>> Reini, on Win32 filenames are stored internally as UTF-16. What affect
>> does your patch proposal have on opening files with widecharacters in
>> them? (Widecharacters as you know could easily contain nuls).
> Perl uses legacy interfaces on Windows (that is, it accesses the
> filesystem using 8-bit interfaces, the encoding is system-defined but
> tends to be latin-1, which saves our ass most of the time).
> I'd consider this our number one Windows bug (because it screws up
> badly when trying to open files with Unicode in their names), but
> fixing this will be non-trivial, and few people have the appropriate
> Windows knowledge anyway.

It is possible to open Unicode filenames on Windows using Win32API::File (see below). I assume this will at least still work?

use Encode qw(encode);
use Fcntl;
use Win32API::File qw(CreateFileW OsFHandleOpenFd :Misc :GENERIC_);

my $filename = "\x{65e5}.txt\0";
my $utf16le_filename = encode('UTF-16LE', $filename, 1);

my $h = CreateFileW($utf16le_filename, GENERIC_WRITE, 0, [], CREATE_NEW, 0, []);
	die "[write] CreateFileW: $^E\n" unless $h > 0;
my $fd = OsFHandleOpenFd($h, O_WRONLY);
	die "[write] OsFHandleOpenFd: $^E\n" unless $fd > 0;
open my $fh, ">&=$fd";
	die "[write] open: $!\n" unless $fh;
print $fh "Hello, world.\n";
close $fh;

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About