home *** CD-ROM | disk | FTP | other *** search
- head 1.3;
- access;
- symbols
- version39-41:1.1;
- locks;
- comment @ * @;
-
-
- 1.3
- date 92.08.09.20.38.07; author amiga; state Exp;
- branches;
- next 1.2;
-
- 1.2
- date 92.07.28.02.51.41; author mwild; state Exp;
- branches;
- next 1.1;
-
- 1.1
- date 92.05.14.19.55.40; author mwild; state Exp;
- branches;
- next ;
-
-
- desc
- @Open() replacement
- @
-
-
- 1.3
- log
- @change to use 2.x header files by default
- @
- text
- @/*
- * This file is part of ixemul.library for the Amiga.
- * Copyright (C) 1991, 1992 Markus M. Wild
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id: __open.c,v 1.2 1992/07/28 02:51:41 mwild Exp $
- *
- * $Log: __open.c,v $
- * Revision 1.2 1992/07/28 02:51:41 mwild
- * call AllocDosObject instead of rolling my own when > 1.3
- *
- * Revision 1.1 1992/05/14 19:55:40 mwild
- * Initial revision
- *
- */
-
- #define KERNEL
- #include "ixemul.h"
-
- #include <utility/tagitem.h>
- #include <dos/dostags.h>
-
- extern int _dos20;
-
- #if __GNUC__ != 2
- #define alloca __builtin_alloca
- #endif
-
- struct open_vec {
- int action;
- struct FileHandle *fh;
- };
-
- static int
- __open_func (struct StandardPacket *sp, struct MsgPort *handler,
- BPTR parent_lock,
- BSTR name,
- struct open_vec *ov, int *no_error)
- {
- sp->sp_Pkt.dp_Type = ov->action;
- sp->sp_Pkt.dp_Arg1 = CTOBPTR (ov->fh);
- sp->sp_Pkt.dp_Arg2 = parent_lock;
- sp->sp_Pkt.dp_Arg3 = name;
-
- PutPacket (handler, sp);
- __wait_sync_packet (sp);
-
- *no_error = sp->sp_Pkt.dp_Res1 == -1;
-
- /* handler is supposed to supply this, but if it didn't... */
- if (*no_error && !ov->fh->fh_Type) ov->fh->fh_Type = handler;
-
- /* continue if we failed because of symlink - reference */
- return 1;
- }
-
- BPTR
- __open (char *name, int action)
- {
- unsigned long *fh;
- struct open_vec ov;
- BPTR res;
-
- if (! _dos20)
- {
- /* provide a new filehandle, allocated as DOS-like as possible
- * (don't know if that's needed)
- * kmalloc() gurantees long-aligned data */
- fh = (unsigned long *) kmalloc (sizeof (struct FileHandle) + 4);
- if (! fh)
- return 0;
- *fh = sizeof (struct FileHandle);
- ov.fh = (struct FileHandle *)(fh + 1);
- ov.action = action;
- bzero (ov.fh, sizeof (struct FileHandle));
- ov.fh->fh_Pos = ov.fh->fh_End = -1;
- }
- else
- {
- /* needed to get berserk ReadArgs() to behave sane, GRRR */
- fh = AllocDosObjectTags (DOS_FILEHANDLE, ADO_FH_Mode, action, TAG_DONE);
- if (! fh)
- return 0;
- ov.fh = fh;
- ov.action = action;
- }
-
- res = __plock (name, __open_func, &ov);
- /* check for opening of NIL:, in which case we just return
- a filehandle with a zero handle field */
- if (! res && IoErr() == 4242)
- res = -1;
-
- if (! res)
- {
- if (! _dos20)
- kfree (fh);
- else
- FreeDosObject (DOS_FILEHANDLE, fh);
- }
- return res ? CTOBPTR (ov.fh) : 0;
- }
- @
-
-
- 1.2
- log
- @call AllocDosObject instead of rolling my own when > 1.3
- @
- text
- @d19 1
- a19 1
- * $Id: __open.c,v 1.1 1992/05/14 19:55:40 mwild Exp $
- d22 3
- d33 2
- a34 37
- #include "gcc:include20/utility/tagitem.h"
- #include "gcc:include20/dos/dostags.h"
- #define BASE_EXT_DECL
- #define BASE_PAR_DECL
- #define BASE_PAR_DECL0
- #define BASE_NAME ix.ix_dos_base
- static __inline APTR
- AllocDosObject (BASE_PAR_DECL unsigned long type,struct TagItem *tags)
- {
- BASE_EXT_DECL
- register APTR _res __asm("d0");
- register struct DosLibrary *a6 __asm("a6") = BASE_NAME;
- register unsigned long d1 __asm("d1") = type;
- register struct TagItem *d2 __asm("d2") = tags;
- __asm __volatile ("jsr a6@@(-0xe4)"
- : "=r" (_res)
- : "r" (a6), "r" (d1), "r" (d2)
- : "a0","a1","d0","d1","d2", "memory");
- return _res;
- }
- static __inline void
- FreeDosObject (BASE_PAR_DECL unsigned long type,APTR ptr)
- {
- BASE_EXT_DECL
- register struct DosLibrary *a6 __asm("a6") = BASE_NAME;
- register unsigned long d1 __asm("d1") = type;
- register APTR d2 __asm("d2") = ptr;
- __asm __volatile ("jsr a6@@(-0xea)"
- : /* no output */
- : "r" (a6), "r" (d1), "r" (d2)
- : "a0","a1","d0","d1","d2", "memory");
- }
- #ifndef NO_INLINE_STDARG
- #define AllocDosObjectTags(a0, tags...) \
- ({ struct TagItem _tags[] = { tags }; AllocDosObject ((a0), _tags); })
- #endif /* not NO_INLINE_STDARG */
- #define DOS_FILEHANDLE 0
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d19 1
- a19 1
- * $Id$
- d21 4
- a24 1
- * $Log$
- d30 40
- d109 23
- a131 9
- /* provide a new filehandle, allocated as DOS-like as possible
- * (don't know if that's needed)
- * kmalloc() gurantees long-aligned data */
- fh = (unsigned long *) kmalloc (sizeof (struct FileHandle) + 4);
- *fh = sizeof (struct FileHandle);
- ov.fh = (struct FileHandle *)(fh + 1);
- ov.action = action;
- bzero (ov.fh, sizeof (struct FileHandle));
- ov.fh->fh_Pos = ov.fh->fh_End = -1;
- d139 7
- a145 1
- if (! res) kfree (fh);
- @
-