summaryrefslogtreecommitdiffstats
path: root/dup2.c
blob: bdf33250d67e0b45a26fe378256a6f1a72bf370d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
 * dup2.c
 *
 * Ersatz dup2() for really ancient systems
 */

#include "config.h"

int dup2(int oldfd, int newfd)
{
  int rv, nfd;

  close(newfd);

  nfd = rv = dup(oldfd);

  if (rv >= 0 && rv != newfd) {
    rv = dup2(oldfd, newfd);
    close(nfd);
  }

  return rv;
}