This is the mail archive of the
mailing list for the Cygwin project.
Re: Accessing filenames with different charsets
> > Qt (from Trolltech) encodes Unicode filenames before they are used. In
> > Cygwin we could do the reverse, i.e. use Find*FileW and then encode the
> > Unicode as a local ANSI string. If we do the encoding manually in
> > rather than let Windows do it for us, this would overcome the problem. I
> > will try to put together a patch for this that you can test. One
> > is to encode Unicode strings as UTF-8.
> Another idea that comes into mind: use the cAlternateFileName field from
> WIN32_FIND_DATA - that is, the 8.3 filename. I tried it, and I can access
> the file via it's 8.3 name in cygwin:
> wc F305~1.TES
> 318 1214 10141 F305~1.TES
> So all that'd have to be done is make cygwin readdir (and friends) return
> the 8.3 name if the normal name is inaccessible (different charset, too
> name... I'm not yet sure how to detect this).
> The advantage over encoding the wide char name somehow is that the 8.3
> is usable in DOS/windows as well. The disadvantage is that a name like
> F305~1 doesn't really tell anything about the real filename. And, if you
> back it up (say, with tar), and then restore it, you lose the original
> While not perfect that's still better than losing the whole file.
I wrote a patch for Cygwin yesterday that converts Unicode filenames to UTF8
and back for some file operations. This should do what you want and allow
you to restore the names correctly later. I will post it to cygwin-patches
sometime today, but I'm not sure whether the patch will appear in a Cygwin
snapshot anytime soon, if not I can send you the modified binary and the
patch directly for you to try. The only disadvantage with this method is it
still makes the filenames impossible to type. However, if you have your
terminal set up correctly, it is certainly possible to read them as they
should be (e.g. in xterm with UTF8 support turned on). If you are using a
graphical file browser like konqueror then that makes things even easier.
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html