home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / ixemul-45.0-src.tgz / tar.out / contrib / ixemul / library / __close.c < prev    next >
C/C++ Source or Header  |  1996-10-01  |  3KB  |  83 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  $Id: __close.c,v 1.2 1994/06/19 15:18:48 rluebbert Exp $
  20.  *
  21.  *  $Log: __close.c,v $
  22.  *  Revision 1.2  1994/06/19  15:18:48  rluebbert
  23.  *  *** empty log message ***
  24.  *
  25.  */
  26.  
  27. #define _KERNEL
  28. #include "ixemul.h"
  29. #include "kprintf.h"
  30.  
  31. int
  32. __close(struct file *f)
  33. {
  34.   if (f->f_count == 1)
  35.     __wait_select_packet(&f->f_select_sp);
  36.  
  37.   ix_lock_base ();
  38.  
  39.   f->f_count--;
  40.  
  41.   KPRINTF (("__close: closing file $%lx, f_count now %ld.\n", f, f->f_count));
  42.   if (f->f_count > 0) goto unlock;
  43.  
  44.   if (!(f->f_flags & FEXTOPEN))
  45.     {
  46.       __Close (CTOBPTR (f->f_fh));
  47.       if (!memcmp(f->f_name, "/fifo/pty", 9))
  48.         {
  49.       int i = (f->f_name[9] - 'p') * 16 + f->f_name[10] - (f->f_name[10] >= 'a' ? 'a' - 10 : '0');
  50.             char mask = (f->f_name[17] == 'm' ? IX_PTY_MASTER : IX_PTY_SLAVE);
  51.       
  52.       ix.ix_ptys[i] &= ~(mask & IX_PTY_OPEN);
  53.       ix.ix_ptys[i] |= mask & IX_PTY_CLOSE;
  54.       if (!(ix.ix_ptys[i] & IX_PTY_OPEN))
  55.         ix.ix_ptys[i] = 0;  /* both slave and master are closed, so free this pty */
  56.         }
  57.     }
  58.  
  59.   /* if we have to set some modes, do it now */
  60.   if (f->f_stb_dirty)
  61.     {
  62.       syscall (SYS_chmod, f->f_name, f->f_stb.st_mode);
  63.       /* should later also set modification time */
  64.     }
  65.  
  66.   if (f->f_flags & FUNLINK) syscall (SYS_unlink, f->f_name);
  67.  
  68.   /* NOTE: the FEXTOPEN flag tells us two things: 1) we shouldn't
  69.    * perform a Close() on the filehandle, and 2) the name in the
  70.    * file structure wasn't allocated by malloc(), so we shouldn't 
  71.    * free() it either. */
  72.   if (!(f->f_flags & FEXTOPEN) && f->f_name) 
  73.     {
  74.       KPRINTF (("f->f_name(%s) ", f->f_name));
  75.       kfree (f->f_name);
  76.     }
  77.  
  78. unlock:
  79.   ix_unlock_base ();
  80.  
  81.   return 0;
  82. }
  83.