summaryrefslogtreecommitdiffstats
path: root/dup2.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2007-07-06 15:42:57 -0700
committerH. Peter Anvin <hpa@zytor.com>2007-07-06 15:42:57 -0700
commitcaba1e82891eb4b419b1ac9fef6e774104acafe2 (patch)
tree0cafc2965f5571e2a289da89ed1ec75798568d05 /dup2.c
downloadlib-caba1e82891eb4b419b1ac9fef6e774104acafe2.tar.gz
lib-caba1e82891eb4b419b1ac9fef6e774104acafe2.tar.xz
lib-caba1e82891eb4b419b1ac9fef6e774104acafe2.zip
Initial commit: collection of useful functions
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;
+}
+
+