dup2.c 380 B

1234567891011121314151617181920
  1. #include <unistd.h>
  2. #include <errno.h>
  3. #include <fcntl.h>
  4. #include "syscall.h"
  5. int dup2(int old, int new)
  6. {
  7. int r;
  8. #ifdef SYS_dup2
  9. while ((r=__syscall(SYS_dup2, old, new))==-EBUSY);
  10. #else
  11. if (old==new) {
  12. r = __syscall(SYS_fcntl, old, F_GETFD);
  13. if (r >= 0) return old;
  14. } else {
  15. while ((r=__syscall(SYS_dup3, old, new, 0))==-EBUSY);
  16. }
  17. #endif
  18. return __syscall_ret(r);
  19. }