home *** CD-ROM | disk | FTP | other *** search
- static char sccs_id[] = "@(#) dup2.c 1.2 " __DATE__ " HJR";
-
- /* dup2.c (c) Copyright 1990 H.Rogers */
-
- #include <string.h>
- #include <errno.h>
-
- #include "sys/types.h"
- #include "sys/unix.h"
- #include "sys/os.h"
-
- int
- dup2 (int fd1, int fd2)
- {
- register struct file *f1, *f2;
-
- if (BADF (fd1) || (fd2 >= MAXFD) || (fd2 < 0))
- {
- errno = EBADF;
- return (-1);
- }
-
- if (fd1 == fd2)
- return (0);
-
- f1 = __u->file + fd1;
- f2 = __u->file + fd2;
-
- if (f2->dup)
- close (fd2);
-
- memcpy (f2, f1, sizeof (struct file));
-
- f2->dup = f1;
-
- while (f1->dup != f2->dup)
- f1 = f1->dup;
-
- f1->dup = f2;
-
- return (0);
- }
-