A Tuesday 12 February 2008 23:23:09, Danny Backx wrote:
> On Tue, 2008-02-12 at 12:03 +0900, Lance Fetters wrote:
> > Unfortunately I haven't been able to switch to mingw32ce so far for
> > various reasons, including that mingw32ce seems to be missing some win32
> > functionality, particularly _get_osfhandle() (declared but not defined),
> > which is being used for loadable module support. Is there an alternative
> > function that should be used?.
>
> According to MSDN (see e.g. http://support.microsoft.com/kb/99456) the
> _get_osfhandle is not supported in Win32. Also searching for the
> combination of _get_osfhandle and ce fails, which indicates that the
> call is not supported on Windows CE either.
>

Remember that a file descriptor in Windows CE is really a handle.  While
on desktop Windows, you need this, to get at the win32 file handle:

  FILE *f = fopen (...);
  HANDLE h = (HANDLE)_get_osfhandle (_fileno (f));

On Windows CE, you can do this directly:

  FILE *f = fopen (...);
  HANDLE h = (HANDLE) _fileno (f);

What you can do for WinCE, is something like:

#define _get_os_fhandle (FILDES) ((long) (FILDES))

(don't we have this in mingw32ce headers?)

And there you go, instant portability:

  FILE *f = fopen (...);
  HANDLE h = (HANDLE)_get_osfhandle (_fileno (f));

The file descriptor == HANDLE is also the reason why you should be
careful with code like:

  if (open (...) < 0)
  {
     /* error */
  }

A handle represented as an int can be negative, and that is not an error.
You should change that to:

  if (open (...) == -1)
  {
     /* error */
  }

That will work everywhere.  Posix, Wince and Windows CE.

Also, for the same reasons, you should not hardcode 0, 1 and 2 as stdin,
stdout and stderr file descriptors.  Use the STDIN_FILENO, STDOUT_FILENO,
and STDERR_FILENO macros.

We should put this stuff somewhere in the mingw32ce docs.

-- 
Pedro Alves

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Cegcc-devel mailing list
Cegcc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cegcc-devel

Reply via email to