summaryrefslogtreecommitdiffstats
path: root/dup2.c
diff options
context:
space:
mode:
Diffstat (limited to 'dup2.c')
-rw-r--r--dup2.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/dup2.c b/dup2.c
new file mode 100644
index 0000000..bdf3325
--- /dev/null
+++ b/dup2.c
@@ -0,0 +1,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;
+}
+
+