[Gdal-dev] Wide-character filenames with GDAL file IO?

Frank Warmerdam warmerdam at pobox.com
Sat Sep 9 14:29:38 EDT 2006


On 9/9/06, Ben Discoe <ben at vterrain.org> wrote:
>
> I am tring to convert my GDAL-based application to support international
> characters in filenames.  So far, this has gone pretty well.  On Windows,
> there are the _wfopen etc. methods which can take wide strings.  On Mac OS
> X, the standard C library accepts UTF-8 in normal fopen().
>
> However, i've got code calling GDAL functions like this one:
>         char **CSLLoad(const char *pszFname)
>
> I don't know how to pass my wide-string filenames to CSLLoad.  It seems to
> expect only local charset encoded strings, which means i can't pass it a
> filename containing e.g. Chinese characters.
>
> Perhaps there is support for this somewhere in GDAL that i just haven't
> found yet?

Ben,

There is currently no suppot in GDAL for wide strings, or
wide string filenames.  It seems it is not an issue on MacOS X
since you can use a utf-8 encoding.  As far as I know fopen()
is the only low level open function used by GDAL (well there
might be a few exceptions in sublibraries using open()
instead).

> Another option is for me to open the file first, e.g. for Windows:
>         std::wstring fname;
>         FILE *fp = _wfopen(fname, L"rb");
>         int fd = _fileno(fp);
> Then i could pass the fd into GDAL, if it had a way of accepting it.

There is no support for this in GDAL.

For something like CSLLoad(), it is easy enough to
reimplement yourself.  But it is a big issue for all the
files opened through GDALOpen().

Actually, in thinking about it, you could in theory
implement some sort of special VSI*L handler that
knows how to handle wide strings.  This would be
fairly involved though, and would still only work
for those drivers that use the VSIFOpenL() function
as opposed to VSIFOpen() or their own direct
fopen() or open() calls.

Are you sure there isn't someway of turning wide
string filenames into something compatible with
fopen() on windows?  I have tried opening a variety
of unusual filenames in different character sets,
including double byte names, on windows successfully
(I think). I believe I just passed whatever got passed
in as a filename after using shell completion.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the Gdal-dev mailing list