home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / libsrc87 / dup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-30  |  861 b   |  44 lines

  1. /* from Dale Schumacher's dLibs library */
  2.  
  3. /* these will have to be adjusted at some time ++jrb */
  4. /* use these with caution, TOS 1.4 still has double re-direction bug! */
  5.  
  6. #include <stddef.h>
  7. #include <unistd.h>
  8. #include <fcntl.h>
  9. #include <osbind.h>
  10. #include <errno.h>
  11.  
  12. int dup(handle)
  13.     int handle;
  14. {
  15.     register int rv;
  16.  
  17.     rv = Fdup(handle);
  18.     if(( rv < (__SMALLEST_VALID_HANDLE)) ||
  19.        (__OPEN_INDEX(rv) >= __NHANDLES) ) {
  20.         errno = -rv; rv = -1;
  21.     } else {
  22.         __open_stat[__OPEN_INDEX(rv)] =
  23.         __open_stat[__OPEN_INDEX(handle)];
  24.     }
  25.  
  26.     return(rv);
  27. }
  28.  
  29. int dup2(handle1, handle2)
  30.     int handle1, handle2;
  31. {
  32.     int rv;
  33.  
  34.     close(handle2);
  35.     rv = Fforce(handle2, handle1);
  36.     if ((rv < 0) ||
  37.         (__OPEN_INDEX(handle2) >= __NHANDLES))
  38.         errno = -rv;
  39.     else
  40.         __open_stat[__OPEN_INDEX(handle2)] =
  41.         __open_stat[__OPEN_INDEX(handle1)];
  42.     return (rv < 0) ? -1 : handle2;
  43. }
  44.