home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / LIBSRC.ZOO / libsrc / local / dup2.c < prev    next >
Text File  |  1992-02-16  |  556b  |  32 lines

  1. #define INCL_DOSFILEMGR
  2. #define INCL_DOSERRORS
  3. #include <os2.h>
  4. #include <errno.h>
  5.  
  6. ULONG Dos32DupHandle() asm ("Dos32DupHandle");
  7. ULONG Dos32Close() asm ("Dos32Close");
  8.  
  9. int dup2 (int oldd, int newd)
  10. {
  11.    int newdesc = newd;
  12.    ULONG rc;
  13.  
  14.    rc = Dos32DupHandle (oldd, (PHFILE)&newd);
  15.  
  16.    if (rc)
  17.       if (rc == ERROR_TOO_MANY_OPEN_FILES)
  18.       {
  19.          errno = EMFILE;
  20.          return (-1);
  21.       }
  22.       else
  23.       {
  24.          errno = EBADF;
  25.          return (-1);
  26.       }
  27.  
  28.    Dos32Close (oldd);
  29.    return (newdesc);
  30. }
  31.  
  32.