Skip to content

Commit

Permalink
[io] Convert filenames to right encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
nwellnhof committed Jan 9, 2011
1 parent 108b021 commit 569b6cb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/io/unix.c
Expand Up @@ -161,6 +161,10 @@ Parrot_io_open_unix(PARROT_INTERP, ARGIN(STRING *path), INTVAL flags)
PIOHANDLE fd;
char *spath;

if (path->encoding != Parrot_ascii_encoding_ptr
&& path->encoding != Parrot_utf8_encoding_ptr)
path = Parrot_utf8_encoding_ptr->to_encoding(interp, path);

oflags = convert_flags_to_unix(flags);
spath = Parrot_str_to_cstring(interp, path);

Expand Down
21 changes: 16 additions & 5 deletions src/io/win32.c
Expand Up @@ -206,8 +206,9 @@ PIOHANDLE
Parrot_io_open_win32(PARROT_INTERP, ARGIN(STRING *path), INTVAL flags)
{
ASSERT_ARGS(Parrot_io_open_win32)
DWORD fAcc, fShare, fCreat;
PIOHANDLE fd;
DWORD fAcc, fShare, fCreat;
PIOHANDLE fd;
char *spath;

# if 0
if ((Interp_flags_TEST(interp, PARROT_DEBUG_FLAG)) != 0) {
Expand All @@ -219,12 +220,22 @@ Parrot_io_open_win32(PARROT_INTERP, ARGIN(STRING *path), INTVAL flags)
/* add ? and ! for block/non-block */
convert_flags_to_win32(flags, &fAcc, &fShare, &fCreat);

{ /* enclosing scope for temporary C string */
char * const spath = Parrot_str_to_cstring(interp, path);
if (path->encoding == Parrot_ascii_encoding_ptr) {
spath = Parrot_str_to_cstring(interp, path);
fd = CreateFile(spath, fAcc, fShare, NULL, fCreat,
FILE_ATTRIBUTE_NORMAL, NULL);
Parrot_str_free_cstring(spath);
}
else {
if (path->encoding != Parrot_ucs2_encoding_ptr
&& path->encoding != Parrot_utf16_encoding_ptr)
path = Parrot_utf16_encoding_ptr->to_encoding(interp, path);

spath = Parrot_str_to_cstring(interp, path);
fd = CreateFileW((LPCWSTR)spath, fAcc, fShare, NULL, fCreat,
FILE_ATTRIBUTE_NORMAL, NULL);
}

Parrot_str_free_cstring(spath);

return fd;
}
Expand Down
6 changes: 4 additions & 2 deletions src/string/api.c
Expand Up @@ -2092,9 +2092,11 @@ string_to_cstring_nullable(SHIM_INTERP, ARGIN_NULLOK(const STRING *s))
if (STRING_IS_NULL(s))
return NULL;
else {
char * const p = (char*)mem_internal_allocate(s->bufused + 1);
char * const p = (char*)mem_internal_allocate(s->bufused + 2);
memcpy(p, s->strstart, s->bufused);
p[s->bufused] = '\0';
/* Two trailing NULs for wide char strings */
p[s->bufused] = '\0';
p[s->bufused+1] = '\0';
return p;
}
}
Expand Down

0 comments on commit 569b6cb

Please sign in to comment.