Re: [AD] Windows unicode filename support

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Sunday 30 April 2006 04:55, Michal Molhanec wrote:
> Trent Gamblin napsal(a):
> As I expected, wstat is not supported. So somebody should decide if it's
> OK to drop old Windows or revert back the patch. (IMHO probably OK for
> 4.3 and newer, the 4.2 line should stay compatible with old Windows,
> IMHO this patch does not bring anything which would justify the breakage)

Leave it to Windows to supply older systems with functions that don't do 
anything for forwards "compatibility". Here's an alternative that uses the 
original _stat/_findfirst/etc, but passes it UTF-8 data instead. I doubt 
it'll work with the extended chars in Win9x (where I don't think they can 
have extended chars), but hopefully it'll work in WinNT/2K/XP. Can anyone 
test if it works properly with files that use extended characters? If not, 
then I guess I'll either figure something else out.
Index: src/win/wfile.c
===================================================================
--- src/win/wfile.c	(revision 5781)
+++ src/win/wfile.c	(working copy)
@@ -51,7 +51,7 @@
    struct _stat s;
    char tmp[1024];
 
-   if (_stat(uconvert_toascii(filename, tmp), &s) != 0) {
+   if (_stat(uconvert(filename, U_CURRENT, tmp, U_UTF8, sizeof(tmp)), &s) != 0) {
       *allegro_errno = errno;
       return 0;
    }
@@ -69,7 +69,7 @@
    struct _stat s;
    char tmp[1024];
 
-   if (_stat(uconvert_toascii(filename, tmp), &s) != 0) {
+   if (_stat(uconvert(filename, U_CURRENT, tmp, U_UTF8, sizeof(tmp)), &s) != 0) {
       *allegro_errno = errno;
       return 0;
    }
@@ -100,7 +100,8 @@
    info->time = ff_data->data.time_write;
    info->size = ff_data->data.size;
 
-   do_uconvert(ff_data->data.name, U_ASCII, info->name, U_CURRENT, sizeof(info->name));
+   do_uconvert((const char*)ff_data->data.name, U_UTF8, info->name, U_CURRENT,
+               sizeof(info->name));
 }
 
 
@@ -141,7 +142,8 @@
    /* start the search */
    errno = *allegro_errno = 0;
 
-   ff_data->handle = _findfirst(uconvert_toascii(pattern, tmp), &ff_data->data);
+   ff_data->handle = _findfirst(uconvert(pattern, U_CURRENT, tmp,
+                                 U_UTF8, sizeof(tmp)), &ff_data->data);
 
    if (ff_data->handle < 0) {
       *allegro_errno = errno;
@@ -229,8 +231,8 @@
 {
    char tmp[1024];
 
-   if (_getdcwd(drive+1, tmp, sizeof(tmp)))
-      do_uconvert(tmp, U_ASCII, buf, U_CURRENT, size);
+   if (_getdcwd(drive+1, tmp, sizeof(tmp)/sizeof(tmp[0])))
+      do_uconvert((const char*)tmp, U_UTF8, buf, U_CURRENT, size);
    else
       usetc(buf, 0);
 }


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/