[comp.os.os9] OS9Lib Patch #01

ocker@lan.informatik.tu-muenchen.dbp.de (Wolfgang Ocker) (10/14/88)

The dup2() function was buggy, buggy, buggy ...

Here the first official patch for the OS9Lib.

/// Wolfgang Ocker

---- cut here ---- cut here ---- cut here ---- cut here ----
*** pipe.c.old	Thu Oct 13 15:48:00 1988
--- pipe.c	Thu Oct 13 18:38:00 1988
***************
*** 28,35 ****
   |
   * ----------------------------------------------------------------- */
  
! #define PATCHLEVEL 1
  
  #include <modes.h>
  
  /*
--- 28,36 ----
   |
   * ----------------------------------------------------------------- */
  
! #define PATCHLEVEL 2
  
+ #include <stdio.h>
  #include <modes.h>
  
  /*
***************
*** 62,85 ****
    register int src, dest;
  {
    register int i, newfd;
!   int          p[32];
  
    close(dest);
  
!   for(i = 0; i < 32; p[i++] = 0);
  
    do {
!     i = dup(src);
!     p[i] = 1;
!   } while(i != dest && i < 32);
  
!   p[i]  = 0;
!   newfd = dup(src);
  
!   for(i = 0; i < 32; i++)
      if (p[i])
        close(i);
  
!   return(dest == newfd ? 0 : -1);
  }
  
--- 63,91 ----
    register int src, dest;
  {
    register int i, newfd;
!   int          p[_NFILE];
  
+   if (src == dest)
+     return(dest);
+ 
    close(dest);
  
!   for (i = 0; i < _NFILE; p[i++] = 0);
  
    do {
!     if ((i = dup(src)) >= 0)
!       p[i] = 1;
!   } while(i != dest && i >= 0);
  
!   if (i >= 0)
!     p[i] = 0;
  
!   newfd = i;
! 
!   for (i = 0; i < _NFILE; i++)
      if (p[i])
        close(i);
  
!   return(dest == newfd ? newfd : -1);
  }
 ---- cut here --- cut here --- cut here ---- cut here ----

-- 
  |  Wolfgang Ocker          |  ocker@lan.informatik.tu-muenchen.dbp.de  |
  |  Lochhauserstr. 35a      |      pyramid!tmpmbx!recco!weo (home)      |
  |  D-8039 Puchheim         |     Technische Universitaet Muenchen      |
  |  Voice: +49 89 80 77 02  |          Huh, What? Where am I?           |