wxWindows: it's official!

Francois Gouget fgouget at free.fr
Wed Jan 8 19:12:10 CST 2003

On Wed, 8 Jan 2003, Dimitrie O. Paun wrote:

> On January 8, 2003 02:08 pm, Francois Gouget wrote:
> > I can see how get_osfhandle() can be useful for interoperability in
> > Cygwin. setmode() seems of a more dubious value though (especially since
> > it means they must have implemented the awful CR/LF conversion across
> > their C library API (unless setmode() is nothing but a stub)).
> get_osfhandle() seems useful in Wine as well, no?

Actually I got things reversed:
 * get_osfhandle() takes a C library file descriptor (fd) and returns a
Win32 file handle (HANDLE).
 * open_osfhandle() is the one that takes the Win32 file handle (HANDLE)
and returns a C library file descriptor (fd).
I always get those two confused.

Both are implemented in Wine's msvcrt library which is where they belong
since the C library file handle is specific to msvcrt, i.e. if you get
an fd from msvcrt and give it to open from the glibc bad things will
happen (error in the best case, reading/writing to the wrong file in the
worst case).

There is similar functionality in Wine for Unix file descriptors which
is provided by: wine_server_fd_to_handle and wine_server_handle_to_fd.
But these work differently from the msvcrt ones.

> As for semode(), it can
> work both ways. A simple
> #define setmode() do {} while(0)
> seems to be a good first order approximation...

Sure it's a hack that will let you compile the application. It will even
run as long as it doesn't rely on that feature.

> Do we do the awful CR/LF conversion in msvcrt?

Nope, it's a stub in msvcrt for now. However it will print a trace if
called with a parameter it does not support, and unlike header hacks it
can actually be made to work.

The better question is whether cygwin really implements setmode()...
If no then the above hack is sufficient. Otherwise you will eventually
need to:
 * implement a cygwin compatible C library and link cygwin applications
with it
 * or link cygwin applications with the msvcrt (after improving it).
This is quite likely to work
 * or modify the application during the port so that it does not rely on
this functionality

Francois Gouget         fgouget at free.fr        http://fgouget.free.fr/
                         "Utilisateur" (nom commun) :
        Mot utilisé par les informaticiens en lieu et place d'"idiot".

More information about the wine-devel mailing list