home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / code / unixlib / !UnixLib / src / unix / c / close < prev    next >
Encoding:
Text File  |  1994-09-30  |  692 b   |  50 lines

  1. static char sccs_id[] = "@(#) close.c 1.3 " __DATE__ " HJR";
  2.  
  3. /* close.c (c) Copyright 1990 H.Rogers */
  4.  
  5. #include <errno.h>
  6.  
  7. #include "fcntl.h"
  8.  
  9. #include "sys/types.h"
  10. #include "sys/unix.h"
  11. #include "sys/dev.h"
  12. #include "sys/os.h"
  13.  
  14. int
  15. close (int fd)
  16. {
  17.   register struct file *f;
  18.  
  19.   if (BADF (fd))
  20.     {
  21.       errno = EBADF;
  22.       return (-1);
  23.     }
  24.  
  25.   f = __u->file + fd;
  26.  
  27.   if (f->dup != f)
  28.     {
  29.       register struct file *_f;
  30.  
  31.       _f = f->dup;
  32.       while (_f->dup != f)
  33.     {
  34.       _f = _f->dup;
  35.     }
  36.  
  37.       _f->dup = f->dup;
  38.     }
  39.   else
  40.     {
  41.       if (f->pid == __u->pid)
  42.     if ((*(__dev[major (f->dev)].close)) (minor (f->dev), f) < 0)
  43.       return (-1);
  44.     }
  45.  
  46.   f->dup = 0;
  47.  
  48.   return (0);
  49. }
  50.