Permalink
Browse files

[io] Convert filenames to right encoding

  • Loading branch information...
1 parent 108b021 commit 569b6cb4296cc28dd4e84d7e5799c5eea3dcc7f5 @nwellnhof nwellnhof committed Jan 8, 2011
Showing with 24 additions and 7 deletions.
  1. +4 −0 src/io/unix.c
  2. +16 −5 src/io/win32.c
  3. +4 −2 src/string/api.c
View
@@ -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);
View
@@ -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) {
@@ -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;
}
View
@@ -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;
}
}

0 comments on commit 569b6cb

Please sign in to comment.