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

  1. head    1.3;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.3
  10. date    92.08.09.20.38.07;    author amiga;    state Exp;
  11. branches;
  12. next    1.2;
  13.  
  14. 1.2
  15. date    92.07.28.02.51.41;    author mwild;    state Exp;
  16. branches;
  17. next    1.1;
  18.  
  19. 1.1
  20. date    92.05.14.19.55.40;    author mwild;    state Exp;
  21. branches;
  22. next    ;
  23.  
  24.  
  25. desc
  26. @Open() replacement
  27. @
  28.  
  29.  
  30. 1.3
  31. log
  32. @change to use 2.x header files by default
  33. @
  34. text
  35. @/*
  36.  *  This file is part of ixemul.library for the Amiga.
  37.  *  Copyright (C) 1991, 1992  Markus M. Wild
  38.  *
  39.  *  This library is free software; you can redistribute it and/or
  40.  *  modify it under the terms of the GNU Library General Public
  41.  *  License as published by the Free Software Foundation; either
  42.  *  version 2 of the License, or (at your option) any later version.
  43.  *
  44.  *  This library is distributed in the hope that it will be useful,
  45.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  46.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  47.  *  Library General Public License for more details.
  48.  *
  49.  *  You should have received a copy of the GNU Library General Public
  50.  *  License along with this library; if not, write to the Free
  51.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  52.  *
  53.  *  $Id: __open.c,v 1.2 1992/07/28 02:51:41 mwild Exp $
  54.  *
  55.  *  $Log: __open.c,v $
  56.  *  Revision 1.2  1992/07/28  02:51:41  mwild
  57.  *  call AllocDosObject instead of rolling my own when > 1.3
  58.  *
  59.  *  Revision 1.1  1992/05/14  19:55:40  mwild
  60.  *  Initial revision
  61.  *
  62.  */
  63.  
  64. #define KERNEL
  65. #include "ixemul.h"
  66.  
  67. #include <utility/tagitem.h>
  68. #include <dos/dostags.h>
  69.  
  70. extern int _dos20;
  71.  
  72. #if __GNUC__ != 2
  73. #define alloca __builtin_alloca
  74. #endif
  75.  
  76. struct open_vec {
  77.   int action;
  78.   struct FileHandle *fh;
  79. };
  80.  
  81. static int
  82. __open_func (struct StandardPacket *sp, struct MsgPort *handler,
  83.              BPTR parent_lock,
  84.          BSTR name,
  85.          struct open_vec *ov, int *no_error)
  86. {
  87.   sp->sp_Pkt.dp_Type = ov->action;
  88.   sp->sp_Pkt.dp_Arg1 = CTOBPTR (ov->fh);
  89.   sp->sp_Pkt.dp_Arg2 = parent_lock;
  90.   sp->sp_Pkt.dp_Arg3 = name;
  91.  
  92.   PutPacket (handler, sp);
  93.   __wait_sync_packet (sp);
  94.  
  95.   *no_error = sp->sp_Pkt.dp_Res1 == -1;
  96.  
  97.   /* handler is supposed to supply this, but if it didn't... */
  98.   if (*no_error && !ov->fh->fh_Type) ov->fh->fh_Type = handler;
  99.  
  100.   /* continue if we failed because of symlink - reference */
  101.   return 1;
  102. }
  103.  
  104. BPTR
  105. __open (char *name, int action)
  106. {
  107.   unsigned long *fh;
  108.   struct open_vec ov;
  109.   BPTR res;
  110.  
  111.   if (! _dos20)
  112.     {
  113.       /* provide a new filehandle, allocated as DOS-like as possible
  114.        * (don't know if that's needed)
  115.        * kmalloc() gurantees long-aligned data */
  116.       fh = (unsigned long *) kmalloc (sizeof (struct FileHandle) + 4);
  117.       if (! fh)
  118.         return 0;
  119.       *fh = sizeof (struct FileHandle);
  120.       ov.fh = (struct FileHandle *)(fh + 1);
  121.       ov.action = action;
  122.       bzero (ov.fh, sizeof (struct FileHandle));
  123.       ov.fh->fh_Pos = ov.fh->fh_End = -1;
  124.     }
  125.   else
  126.     {
  127.       /* needed to get berserk ReadArgs() to behave sane, GRRR */
  128.       fh = AllocDosObjectTags (DOS_FILEHANDLE, ADO_FH_Mode, action, TAG_DONE);
  129.       if (! fh)
  130.         return 0;
  131.       ov.fh = fh;
  132.       ov.action = action;
  133.     }
  134.  
  135.   res = __plock (name, __open_func, &ov);
  136.   /* check for opening of NIL:, in which case we just return
  137.      a filehandle with a zero handle field */
  138.   if (! res && IoErr() == 4242)
  139.     res = -1;
  140.   
  141.   if (! res)
  142.     {
  143.       if (! _dos20)
  144.         kfree (fh);
  145.       else
  146.     FreeDosObject (DOS_FILEHANDLE, fh);
  147.     }
  148.   return res ? CTOBPTR (ov.fh) : 0;
  149. }
  150. @
  151.  
  152.  
  153. 1.2
  154. log
  155. @call AllocDosObject instead of rolling my own when > 1.3
  156. @
  157. text
  158. @d19 1
  159. a19 1
  160.  *  $Id: __open.c,v 1.1 1992/05/14 19:55:40 mwild Exp $
  161. d22 3
  162. d33 2
  163. a34 37
  164. #include "gcc:include20/utility/tagitem.h"
  165. #include "gcc:include20/dos/dostags.h"
  166. #define BASE_EXT_DECL
  167. #define BASE_PAR_DECL    
  168. #define BASE_PAR_DECL0    
  169. #define BASE_NAME    ix.ix_dos_base
  170. static __inline APTR 
  171. AllocDosObject (BASE_PAR_DECL unsigned long type,struct TagItem *tags)
  172. {
  173.   BASE_EXT_DECL
  174.   register APTR  _res  __asm("d0");
  175.   register struct DosLibrary *a6 __asm("a6") = BASE_NAME;
  176.   register unsigned long d1 __asm("d1") = type;
  177.   register struct TagItem *d2 __asm("d2") = tags;
  178.   __asm __volatile ("jsr a6@@(-0xe4)"
  179.   : "=r" (_res)
  180.   : "r" (a6), "r" (d1), "r" (d2)
  181.   : "a0","a1","d0","d1","d2", "memory");
  182.   return _res;
  183. }
  184. static __inline void 
  185. FreeDosObject (BASE_PAR_DECL unsigned long type,APTR ptr)
  186. {
  187.   BASE_EXT_DECL
  188.   register struct DosLibrary *a6 __asm("a6") = BASE_NAME;
  189.   register unsigned long d1 __asm("d1") = type;
  190.   register APTR d2 __asm("d2") = ptr;
  191.   __asm __volatile ("jsr a6@@(-0xea)"
  192.   : /* no output */
  193.   : "r" (a6), "r" (d1), "r" (d2)
  194.   : "a0","a1","d0","d1","d2", "memory");
  195. }
  196. #ifndef NO_INLINE_STDARG
  197. #define AllocDosObjectTags(a0, tags...) \
  198.   ({ struct TagItem _tags[] = { tags }; AllocDosObject ((a0), _tags); })
  199. #endif /* not NO_INLINE_STDARG */
  200. #define DOS_FILEHANDLE    0
  201. @
  202.  
  203.  
  204. 1.1
  205. log
  206. @Initial revision
  207. @
  208. text
  209. @d19 1
  210. a19 1
  211.  *  $Id$
  212. d21 4
  213. a24 1
  214.  *  $Log$
  215. d30 40
  216. d109 23
  217. a131 9
  218.   /* provide a new filehandle, allocated as DOS-like as possible
  219.    * (don't know if that's needed)
  220.    * kmalloc() gurantees long-aligned data */
  221.   fh = (unsigned long *) kmalloc (sizeof (struct FileHandle) + 4);
  222.   *fh = sizeof (struct FileHandle);
  223.   ov.fh = (struct FileHandle *)(fh + 1);
  224.   ov.action = action;
  225.   bzero (ov.fh, sizeof (struct FileHandle));
  226.   ov.fh->fh_Pos = ov.fh->fh_End = -1;
  227. d139 7
  228. a145 1
  229.   if (! res) kfree (fh);
  230. @
  231.