diff -cr libstdc++-2.8.1.1/libio/fileops.c \emx\gnu\libstdc++-2.8.1.1/libio/fileops.c
*** libstdc++-2.8.1.1/libio/fileops.c	Tue Feb 24 15:08:44 1998
--- \emx\gnu\libstdc++-2.8.1.1/libio/fileops.c	Thu Oct 29 12:28:04 1998
***************
*** 1,3 ****
--- 1,4 ----
+ /* fileops.c -- changed for emx by Eberhard Mattes -- Oct 1998 */
  /* Copyright (C) 1993, 1995, 1997, 1998 Free Software Foundation, Inc.
     This file is part of the GNU IO Library.
     Written by Per Bothner <bothner@cygnus.com>.
***************
*** 194,199 ****
--- 195,204 ----
        omode = O_RDWR;
        read_write &= _IO_IS_APPENDING;
      }
+ #ifdef O_BINARY /* EMX */
+   if (mode[0] == 'b' || (mode[0] == '+' && mode[1] == 'b'))
+     oflags |= O_BINARY;
+ #endif /* O_BINARY */
    fdesc = open (filename, omode|oflags, oprot);
    if (fdesc < 0)
      return NULL;
diff -cr libstdc++-2.8.1.1/libio/gen-params \emx\gnu\libstdc++-2.8.1.1/libio/gen-params
*** libstdc++-2.8.1.1/libio/gen-params	Tue Feb 24 15:08:44 1998
--- \emx\gnu\libstdc++-2.8.1.1/libio/gen-params	Thu Oct 29 12:29:38 1998
***************
*** 1,4 ****
--- 1,5 ----
  #!/bin/sh
+ # gen-params -- changed for emx by Eberhard Mattes -- Oct 1998
  # Copyright (C) 1992, 1993, 1994, 1998 Free Software Foundation
  # 
  # This file is part of the GNU IO Library.  This library is free
***************
*** 48,63 ****
  rootdir=`pwd`/..
  gccdir=${gccdir-${rootdir}/gcc}
  binutilsdir=${binutilsdir-${rootdir}/binutils}
! CC=${CC-`if [ -f ${gccdir}/xgcc ] ; \
! 	then echo ${gccdir}/xgcc -B${gccdir}/ ; \
! 	else echo cc ; fi`}
! CXX=${CXX-`if [ -f ${gccdir}/xgcc ] ; \
! 	then echo ${gccdir}/xgcc -B${gccdir}/ ; \
! 	else echo gcc ; fi`}
  CPP=${CPP-`echo ${CC} -E`}
! CONFIG_NM=${CONFIG_NM-`if [ -f ${binutilsdir}/nm.new ] ; \
! 	then echo ${binutilsdir}/nm.new ; \
! 	else echo nm ; fi`}
  
  cat <<!EOF!
  /* AUTOMATICALLY GENERATED; DO NOT EDIT! */ 
--- 49,58 ----
  rootdir=`pwd`/..
  gccdir=${gccdir-${rootdir}/gcc}
  binutilsdir=${binutilsdir-${rootdir}/binutils}
! CC=gcc
! CXX='gcc -x c++'
  CPP=${CPP-`echo ${CC} -E`}
! CONFIG_NM=nm
  
  cat <<!EOF!
  /* AUTOMATICALLY GENERATED; DO NOT EDIT! */ 
diff -cr libstdc++-2.8.1.1/libio/iopopen.c \emx\gnu\libstdc++-2.8.1.1/libio/iopopen.c
*** libstdc++-2.8.1.1/libio/iopopen.c	Wed Sep 17 01:42:52 1997
--- \emx\gnu\libstdc++-2.8.1.1/libio/iopopen.c	Thu Oct 29 12:34:50 1998
***************
*** 1,3 ****
--- 1,4 ----
+ /* iopopen.c -- changed for emx by Eberhard Mattes -- Oct 1998 */
  /* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
     This file is part of the GNU IO Library.
     Written by Per Bothner <bothner@cygnus.com>.
***************
*** 24,29 ****
--- 25,36 ----
     other reasons why the executable file might be covered by the GNU
     General Public License.  */
  
+ #ifdef EMX
+ #include <stdlib.h>             /* before defining _POSIX_SOURCE */
+ #include <process.h>
+ #include <fcntl.h>
+ #endif /* EMX */
+ 
  #ifndef _POSIX_SOURCE
  # define _POSIX_SOURCE
  #endif
***************
*** 94,99 ****
--- 101,110 ----
    volatile int parent_end, child_end;
    int pipe_fds[2];
    _IO_pid_t child_pid;
+ #ifdef EMX
+   struct _IO_proc_file *pfc;
+   const char *sh, *base, *opt;
+ #endif /* EMX */
    if (_IO_file_is_open (fp))
      return NULL;
    if (_IO_pipe (pipe_fds) < 0)
***************
*** 110,115 ****
--- 121,161 ----
        child_end = pipe_fds[0];
        read_or_write = _IO_NO_READS;
      }
+ #ifdef EMX
+   child_pid = -1;
+   for (pfc = proc_file_chain; pfc != NULL; pfc = pfc->next)
+     {
+       /* TODO: Save previous state and restore after starting child. */
+       _fcntl (_IO_fileno ((_IO_FILE *)pfc), F_SETFD, 1);
+     }
+   _fcntl (parent_end, F_SETFD, 1);
+   sh = getenv ("EMXSHELL");
+   if (sh == NULL)
+     sh = getenv ("COMSPEC");
+   if (sh != NULL)
+     {
+       int child_std_end = mode[0] == 'r' ? 1 : 0;
+       int org = _dup (child_std_end);
+       if (org != -1)
+         {
+ 	  _IO_dup2 (child_end, child_std_end);
+ 	  _IO_close (child_end);
+           child_end = -1;
+           base = _getname (sh);
+           if (_stricmp (base, "cmd.exe") == 0
+               || _stricmp (base, "4os2.exe") == 0)
+             opt = "/c";
+           else
+             opt = "-c";
+           child_pid = _spawnlp (P_NOWAIT, sh, sh, opt, command, (char *)0);
+           _IO_dup2 (org, child_std_end);
+           _IO_close (org);
+         }
+     }
+   ((_IO_proc_file*) fp)->pid = child_pid;
+   if (child_end != -1)
+     _IO_close (child_end);
+ #else /* not EMX */
    ((_IO_proc_file *) fp)->pid = child_pid = _IO_fork ();
    if (child_pid == 0)
      {
***************
*** 133,138 ****
--- 179,185 ----
        _IO__exit (127);
      }
    _IO_close (child_end);
+ #endif /* not EMX */
    if (child_pid < 0)
      {
        _IO_close (parent_end);
