home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / pdksh-4.9-src.tgz / tar.out / contrib / pdksh / std / posix / dup2.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  330b  |  24 lines

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