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 / __unlock.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  2KB  |  74 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.  
  20. #define _KERNEL
  21. #include "ixemul.h"
  22.  
  23. int __unlock (BPTR lock)
  24. {
  25.   struct StandardPacket *sp;
  26.   
  27.   if (lock == NULL)
  28.     return 0;
  29.   sp = alloca(sizeof(*sp)+2);
  30.   sp = LONG_ALIGN (sp);
  31.   __init_std_packet(sp);
  32.  
  33.   sp->sp_Pkt.dp_Port = u.u_sync_mp;
  34.   sp->sp_Pkt.dp_Type = ACTION_FREE_LOCK;
  35.   sp->sp_Pkt.dp_Arg1 = lock;
  36.  
  37.   PutPacket (((struct FileLock *)BTOCPTR (lock))->fl_Task, sp);
  38.   __wait_sync_packet (sp);
  39.   
  40.   /* set up Result2 so that the IoErr() works */
  41.   ((struct Process *)FindTask (0))->pr_Result2 = sp->sp_Pkt.dp_Res2;
  42.  
  43.   return sp->sp_Pkt.dp_Res1;
  44. }
  45.  
  46. /* ATTENTION: name-clash between sysio-__close and DOS-__Close !! */
  47. void __Close (BPTR fh)
  48. {
  49.   struct StandardPacket *sp;
  50.   struct FileHandle *fhp = BTOCPTR (fh);
  51.   
  52.   /* only do this is not closing a dummy NIL: filehandle */
  53.   if (fhp->fh_Type)
  54.     {
  55.       sp = alloca(sizeof(*sp)+2);
  56.       sp = LONG_ALIGN (sp);
  57.       __init_std_packet(sp);
  58.  
  59.       sp->sp_Pkt.dp_Port = u.u_sync_mp;
  60.       sp->sp_Pkt.dp_Type = ACTION_END;
  61.       sp->sp_Pkt.dp_Arg1 = fhp->fh_Arg1;
  62.  
  63.       PutPacket (fhp->fh_Type, sp);
  64.       __wait_sync_packet (sp);
  65.  
  66.       /* set up Result2 so that the IoErr() works */
  67.       ((struct Process *)FindTask (0))->pr_Result2 = sp->sp_Pkt.dp_Res2;
  68.     }
  69.   else
  70.     ((struct Process *)FindTask (0))->pr_Result2 = 0;
  71.   
  72.   FreeDosObject (DOS_FILEHANDLE, fhp);
  73. }
  74.