[AD] Windows unicode filename support |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
- To: alleg-developers@xxxxxxxxxx
- Subject: [AD] Windows unicode filename support
- From: Chris <chris.kcat@xxxxxxxxxx>
- Date: Wed, 19 Apr 2006 21:09:32 -0700
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:from:to:subject:date:user-agent:mime-version:content-type:message-id; b=R3oBR7o80dZrybOb+Pbb5/RXd/+noTiJa9JMxn//jD4zcZjj14v4/d/bk7mnIw8z+CB5G72Id5l9Q0KSFRPmegp4C78hNTB2tbTGGnfNtTrpn6OwIkBU2c4Q9D7olqXebHFEbumub/+GCkTtQKEGuE6+AGgtx9GRzmT6pLTG0/M=
Since I made a patch for Unix a while ago to support UTF-8/Unicode filenames,
it'd only be fair for Windows to support Unicode filenames too. I don't
believe Windows' _stat/_findfirst/etc would work properly with UTF-8 names
like the similar routines seem to in Unix, so I opted to change it to use the
wide-char/UTF-16 equivilants (_wstat/_wfindfirst/etc).
I had a Windows user test it and it seems to work in his app.
Index: src/win/wfile.c
===================================================================
--- src/win/wfile.c (revision 5781)
+++ src/win/wfile.c (working copy)
@@ -51,7 +51,8 @@
struct _stat s;
char tmp[1024];
- if (_stat(uconvert_toascii(filename, tmp), &s) != 0) {
+ if (_wstat((wchar_t*)uconvert(filename, U_CURRENT, tmp, U_UNICODE,
+ sizeof(tmp)), &s) != 0) {
*allegro_errno = errno;
return 0;
}
@@ -69,7 +70,8 @@
struct _stat s;
char tmp[1024];
- if (_stat(uconvert_toascii(filename, tmp), &s) != 0) {
+ if (_wstat((wchar_t*)uconvert(filename, U_CURRENT, tmp, U_UNICODE,
+ sizeof(tmp)), &s) != 0) {
*allegro_errno = errno;
return 0;
}
@@ -82,7 +84,7 @@
/* structure for use by the directory scanning routines */
struct FF_DATA
{
- struct _finddata_t data;
+ struct _wfinddata_t data;
long handle;
int attrib;
};
@@ -100,7 +102,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_UNICODE, info->name, U_CURRENT,
+ sizeof(info->name));
}
@@ -141,7 +144,8 @@
/* start the search */
errno = *allegro_errno = 0;
- ff_data->handle = _findfirst(uconvert_toascii(pattern, tmp), &ff_data->data);
+ ff_data->handle = _wfindfirst((wchar_t*)uconvert(pattern, U_CURRENT, tmp,
+ U_UNICODE, sizeof(tmp)), &ff_data->data);
if (ff_data->handle < 0) {
*allegro_errno = errno;
@@ -173,7 +177,7 @@
struct FF_DATA *ff_data = (struct FF_DATA *) info->ff_data;
do {
- if (_findnext(ff_data->handle, &ff_data->data) != 0) {
+ if (_wfindnext(ff_data->handle, &ff_data->data) != 0) {
*allegro_errno = errno;
return -1;
}
@@ -227,10 +231,10 @@
*/
void _al_getdcwd(int drive, char *buf, int size)
{
- char tmp[1024];
+ wchar_t tmp[1024];
- if (_getdcwd(drive+1, tmp, sizeof(tmp)))
- do_uconvert(tmp, U_ASCII, buf, U_CURRENT, size);
+ if (_wgetdcwd(drive+1, tmp, sizeof(tmp)/sizeof(tmp[0])))
+ do_uconvert((const char*)tmp, U_UNICODE, buf, U_CURRENT, size);
else
usetc(buf, 0);
}