home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / dup.c < prev    next >
C/C++ Source or Header  |  1993-02-28  |  975b  |  48 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 <fcntl.h>
  8. #include <osbind.h>
  9. #include <errno.h>
  10. #include <mintbind.h>
  11. #include <unistd.h>
  12. #include "lib.h"
  13.  
  14. extern int __mint;
  15.  
  16. int dup(handle)
  17.     int handle;
  18. {
  19.     register int rv;
  20.  
  21.     if (__mint)
  22.         rv = (int)Fcntl(handle, (long)0, F_DUPFD);
  23.     else
  24.         rv = (int)Fdup(handle);
  25.  
  26.     if(rv < (__SMALLEST_VALID_HANDLE)) {
  27.         errno = -rv; rv = -1;
  28.     } else if (__OPEN_INDEX(rv) < __NHANDLES) {
  29.         __open_stat[__OPEN_INDEX(rv)] =
  30.         __open_stat[__OPEN_INDEX(handle)];
  31.     }
  32.     return(rv);
  33. }
  34.  
  35. int dup2(handle1, handle2)
  36.     int handle1, handle2;
  37. {
  38.     int rv;
  39.  
  40.     close(handle2);
  41.     if ((rv = (int)Fforce(handle2, handle1)) < 0)
  42.         errno = -rv;
  43.     else if (__OPEN_INDEX(handle2) < __NHANDLES)
  44.         __open_stat[__OPEN_INDEX(handle2)] =
  45.         __open_stat[__OPEN_INDEX(handle1)];
  46.     return (rv < 0) ? -1 : handle2;
  47. }
  48.