[RFC] io.h & friends

Dimitrie O. Paun dpaun at rogers.com
Thu Jan 9 01:10:45 CST 2003


Folks,

Just as I thought 'fine, I'll add the #ifdef, and get it over with', this
thing comes back to haunt me. For the record, I've delete the previous
thread, _and_ the io.h patch from my tree, thinking the issue was put to
rest.

As you can probably guess, I have the io.h problems in wxWindows, simply
because this is what I work on right now. Let me state the problem again:
  -- When you compile with winegcc, you get these macros:
	__WINE__, __WIN32__, __UNIX__
  -- You want your source to compile with the native libc and/or msvcrt
  -- You want it portable between Wine/MinGW/Cygwin.

So, let's say I do:
#ifndef __UNIX__
#include <io.h>
#endif

Well, this will not work if I want to compile with msvcrt, because
__UNIX__ will be defined anyway. So what do I have to test for? 
I have to define a new symbol (USE_MSVCRT) and test for it

#if !defined(__UNIX__) || defined(USE_MSVCRT)
#include <io.h>
#endif

But this is not all! For example, wxWindows includes stuff like this:
#include <sys/unistd.h>
#include <sys/stat.h>
Since they are available in mingw, and cygwin, and in UNIX, but if
I want to use msvcrt they conflit with stuff from there!

It's a mess. As you can see, the defines alone can make a grown man
cry, and this is for a simple include. And I don't even know I've
covered all the basis! Problem is that there are already 5 platforms:
UNIX, Wine, Cygwin, MinGW, MS. And complexity grows exponentially
with the number of platforms and combinations you have to test for.

This way lays madness. It is now clear to me why the Cygwin people
included io.h. It's so that you can compile with or without the
-mno-cygwin switch, and have everything work. The only way for that
to happen without ungodly defines and tests, is to have a flat space
of include files: a union of MS & Unix files. Even if they are
empty! This way you can simply do:

#include <unistd.h>
#include <io.h>

and you make sure you get the access() definition regardless if you
use the msvcrt of the libc.

I'm not sure what to do. I was hoping to get a include/cygwin
and/or a include/mingw directory so we can deal with these problems.
I didn't know mingw had Unix headers as well, this complicates matters.

Any fresh ideas in this matter are highly appreciated.

-- 
Dimi.




More information about the wine-devel mailing list