home *** CD-ROM | disk | FTP | other *** search
- static char sccs_id[] = "@(#) dup.c 1.2 " __DATE__ " HJR";
-
- /* dup.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
- dup (int fd)
- {
- register struct file *f1, *f2;
- register int i;
-
- if (BADF (fd))
- {
- errno = EBADF;
- return (-1);
- }
-
- if ((i = __fdalloc ()) < 0)
- return (-1);
-
- f1 = __u->file + i;
- f2 = __u->file + fd;
-
- memcpy (f1, f2, sizeof (struct file));
-
- f1->dup = f2;
-
- while (f2->dup != f1->dup)
- f2 = f2->dup;
-
- f2->dup = f1;
-
- return (i);
- }
-