home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / __close.c,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  2.3 KB  |  108 lines

  1. head    1.1;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.1
  10. date    92.05.14.19.55.40;    author mwild;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @lowlevel close function for plain files
  17. @
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/*
  26.  *  This file is part of ixemul.library for the Amiga.
  27.  *  Copyright (C) 1991, 1992  Markus M. Wild
  28.  *
  29.  *  This library is free software; you can redistribute it and/or
  30.  *  modify it under the terms of the GNU Library General Public
  31.  *  License as published by the Free Software Foundation; either
  32.  *  version 2 of the License, or (at your option) any later version.
  33.  *
  34.  *  This library is distributed in the hope that it will be useful,
  35.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  36.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  37.  *  Library General Public License for more details.
  38.  *
  39.  *  You should have received a copy of the GNU Library General Public
  40.  *  License along with this library; if not, write to the Free
  41.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  42.  *
  43.  *  $Id$
  44.  *
  45.  *  $Log$
  46.  */
  47.  
  48. #define KERNEL
  49. #include "ixemul.h"
  50.  
  51. #undef DEBUG
  52.  
  53. #ifdef DEBUG
  54. #define DP(a) kprintf a
  55. #else
  56. #define DP(a)
  57. #endif
  58.  
  59. int
  60. __close(struct file *f)
  61. {
  62.   int omask;
  63.  
  64.   ix_lock_base ();
  65.  
  66.   f->f_count--;
  67.  
  68. /* DP(("__close: closing file $%lx, f_count now %ld.\n", f, f->f_count)); */
  69.   if (f->f_count > 0) goto unlock;
  70.   /* don't need file locking here... if the counter is down to 0, nobody
  71.      else CAN have this file locked */
  72.   __wait_packet(&f->f_sp);
  73.  
  74.   if (!(f->f_flags & FEXTOPEN))
  75.     __Close (CTOBPTR (f->f_fh));   
  76.  
  77.   /* if we have to set some modes, do it now */
  78.   if (f->f_stb_dirty)
  79.     {
  80.       syscall (SYS_chmod, f->f_name, f->f_stb.st_mode);
  81.       /* should later also set modification time */
  82.     }
  83.  
  84.   if (f->f_flags & FUNLINK) syscall (SYS_unlink, f->f_name);
  85.  
  86.   /* NOTE: the FEXTOPEN flag tells us two things: 1) we shouldn't
  87.    * perform a Close() on the filehandle, and 2) the name in the
  88.    * file structure wasn't allocated by malloc(), so we shouldn't 
  89.    * free() it either. */
  90.   if (!(f->f_flags & FEXTOPEN) && f->f_name) 
  91.     {
  92. /*      DP(("f->f_name(%s) ", f->f_name));*/
  93.       kfree (f->f_name);
  94.     }
  95.  
  96.   if (f->f_async_len) 
  97.     {
  98. /*      DP(("f->f_async_len "));*/
  99.       kfree (f->f_async_buf);
  100.     }
  101.  
  102. unlock:
  103.   ix_unlock_base ();
  104.  
  105.   return 0;
  106. }
  107. @
  108.