home *** CD-ROM | disk | FTP | other *** search
- static char sccs_id[] = "@(#) close.c 1.3 " __DATE__ " HJR";
-
- /* close.c (c) Copyright 1990 H.Rogers */
-
- #include <errno.h>
-
- #include "fcntl.h"
-
- #include "sys/types.h"
- #include "sys/unix.h"
- #include "sys/dev.h"
- #include "sys/os.h"
-
- int
- close (int fd)
- {
- register struct file *f;
-
- if (BADF (fd))
- {
- errno = EBADF;
- return (-1);
- }
-
- f = __u->file + fd;
-
- if (f->dup != f)
- {
- register struct file *_f;
-
- _f = f->dup;
- while (_f->dup != f)
- {
- _f = _f->dup;
- }
-
- _f->dup = f->dup;
- }
- else
- {
- if (f->pid == __u->pid)
- if ((*(__dev[major (f->dev)].close)) (minor (f->dev), f) < 0)
- return (-1);
- }
-
- f->dup = 0;
-
- return (0);
- }
-