dup2() implementation