home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 May / W2KPRK.iso / apps / posix / source / SH / STD / POSIX / DUP2.C < prev    next >
C/C++ Source or Header  |  1999-11-17  |  278b  |  23 lines

  1. /*
  2.  * Cheap imitation of BSD dup2()
  3.  */
  4.  
  5. #include <fcntl.h>
  6.  
  7. #if _SYSV
  8. int
  9. dup2( oldd, newd )
  10. int    oldd, newd;
  11. {
  12.     int    fd;
  13.  
  14.     if (fcntl( oldd, F_GETFL, 0 ) < 0)
  15.         return( -1 );
  16.  
  17.     (void) close( newd );
  18.     fd = fcntl( oldd, F_DUPFD, newd );
  19.  
  20.     return( (fd > newd) ? -1 : fd );
  21. }
  22. #endif
  23.