[Insight-developers] Unicode filenames, VS6 and fdstream (was:Unicode filenames and borland issue)

Bill Lorensen bill.lorensen at gmail.com
Tue Nov 10 16:25:41 EST 2009


fdstream is the problem on vs6 I think. We might be able to modify the
fdstream header with ifdef's for VS6. Really make fdstream look like
(i/o)stream. Maybe with (uggh!) #defines to redefine fd(i/o)stream to
be (i/o)stream only on VS6 (and maybe VS7).

On Tue, Nov 10, 2009 at 4:11 PM, Tom Vercauteren
<tom.vercauteren at m4x.org> wrote:
> Hi Bill,
>
> Thanks for taking a look at this!
>
> Are the problems you found related to the use of _wfopen and _wopen or
> to the use of fdstream? This is an important distinction for the
> unicode filename porting because the plan I had in mind relies on
> fdstream being used in all cases (ITK_USE_REVIEW_UTF8_STRINGS on or
> off).
>
> Indeed here is what I found (VS6 not taken into account here):
>
> 1) c-style file IO can be ported relatively easily to utf8 on windows
> (msvc, borland, mingw). Just replace fopen by _wfopen and open by
> _wopen together with some string conversion
>
> 2) c++-style IO is more involved. There is a wide string version of
> ofstream.open() and ifstream.open() on msvc but not on mingw (did not
> try with on borland).
>
> Since the fstreams cannot be opened with a unicode filename on mingw,
> the workaround is to open the file using c-style functions and then
> create a stream from the result of the c-style open.
>
> A gcc specific extension exists for that (stdio_filebuf) but it is
> obviously non-portable. fdstream does the same thing but appeared to
> be portable.
>
> So to get unicode filename enabled streams, we need to replace code like
>
> A)
> std::ifstream readstream(filename, std::ios::binary | std::ios::in)
>
> by code like
>
> B)
> int fd = _wopen(filename, _O_RDONLY);
> boost::fdistream readstream(fd);
> [...]
> close(fd)
>
> We might of course pepper the code with ifdefs each time a stream is
> used (as is already done to workaround a sgi bug in metaImage.cxx
> http://public.kitware.com/cgi-bin/viewcvs.cgi/Utilities/MetaIO/metaImage.cxx?root=Insight&view=markup
> ) but I wanted to avoid that by restricting these ifdefs to live in a
> specified file/module. Hence my plan to wrap only the c-style (f)open
> functions and use fdstreams everywhere.
>
> Note that since we need to close the file descriptor and because
> fd(i/o)streams do not inherit from (i/o)fstream but only from
> (i/o)stream, it is not obvious to have a function that uses either the
> A mode or B mode above.
>
> Sorry for this long email,
> Tom
>
> P.S.: some information is also available on the bug tracker:
> http://public.kitware.com/Bug/view.php?id=9623
>
> On Tue, Nov 10, 2009 at 21:11, Bill Lorensen <bill.lorensen at gmail.com> wrote:
>> My first try with VS6 is not encouraging. I suggest that we instrument
>> the code so that VS6 ITK cannot use Unicode.
>


More information about the Insight-developers mailing list