home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / posix / unistd / dup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-26  |  446 b   |  24 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <libc/stubs.h>
  3. #include <unistd.h>
  4. #include <dpmi.h>
  5. #include <errno.h>
  6. #include <io.h>
  7. #include <libc/dosio.h>
  8.  
  9. int
  10. dup(int fd)
  11. {
  12.   __dpmi_regs r;
  13.   r.h.ah = 0x45;
  14.   r.x.bx = fd;
  15.   __dpmi_int(0x21, &r);
  16.   if (r.x.flags & 1)
  17.   {
  18.     errno = __doserr_to_errno(r.x.ax);
  19.     return -1;
  20.   }
  21.   setmode(r.x.ax, __file_handle_modes[fd]);
  22.   return r.x.ax;
  23. }
  24.