| 624 | } |
| 625 | |
| 626 | int TFileHandle::Duplicate2Posix(int dstHandle) const noexcept { |
| 627 | if (!IsOpen()) { |
| 628 | return -1; |
| 629 | } |
| 630 | #if defined(_win_) |
| 631 | FHANDLE dupHandle = Duplicate(); |
| 632 | if (dupHandle == INVALID_FHANDLE) { |
| 633 | _set_errno(EMFILE); |
| 634 | return -1; |
| 635 | } |
| 636 | int posixHandle = _open_osfhandle((intptr_t)dupHandle, 0); |
| 637 | if (posixHandle == -1) { |
| 638 | CloseHandle(dupHandle); |
| 639 | return -1; |
| 640 | } |
| 641 | if (dup2(posixHandle, dstHandle) == -1) { |
| 642 | dstHandle = -1; |
| 643 | } |
| 644 | _close(posixHandle); |
| 645 | return dstHandle; |
| 646 | #elif defined(_unix_) |
| 647 | while (dup2(Fd_, dstHandle) == -1) { |
| 648 | if (errno != EINTR) { |
| 649 | return -1; |
| 650 | } |
| 651 | } |
| 652 | return dstHandle; |
| 653 | #else |
| 654 | #error unsupported platform |
| 655 | #endif |
| 656 | } |
| 657 | |
| 658 | bool TFileHandle::LinkTo(const TFileHandle& fh) const noexcept { |
| 659 | #if defined(_unix_) |
no test coverage detected