home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / AROS / dos / open.c < prev    next >
Encoding:
C/C++ Source or Header  |  1978-03-06  |  4.3 KB  |  163 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: open.c,v 1.9 1996/10/24 15:50:33 aros Exp $
  4.     $Log: open.c,v $
  5.     Revision 1.9  1996/10/24 15:50:33  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.8  1996/09/21 14:14:23  digulla
  9.     Hand DOSBase to DoName()
  10.  
  11.     Revision 1.7  1996/09/17 16:17:23  digulla
  12.     BADDR() instead of MKBADDR()
  13.  
  14.     Revision 1.6  1996/09/13 17:50:07  digulla
  15.     Use IPTR
  16.  
  17.     Revision 1.5  1996/09/11 13:02:22  digulla
  18.     Open() and Lock() are two different functions now (M. Fleischer)
  19.  
  20.     Revision 1.4  1996/08/13 13:52:49  digulla
  21.     Replaced <dos/dosextens.h> by "dos_intern.h" or added "dos_intern.h"
  22.     Replaced AROS_LA by AROS_LHA
  23.  
  24.     Revision 1.3  1996/08/12 14:20:38  digulla
  25.     Added aliases
  26.  
  27.     Revision 1.2  1996/08/01 17:40:55  digulla
  28.     Added standard header for all files
  29.  
  30.     Desc:
  31.     Lang: english
  32. */
  33. #include <exec/memory.h>
  34. #include <clib/exec_protos.h>
  35. #include <utility/tagitem.h>
  36. #include <dos/dosextens.h>
  37. #include <dos/filesystem.h>
  38. #include <clib/dos_protos.h>
  39. #include <clib/utility_protos.h>
  40. #include "dos_intern.h"
  41.  
  42. #define NEWLIST(l)                          \
  43. ((l)->lh_Head=(struct Node *)&(l)->lh_Tail, \
  44.  (l)->lh_Tail=NULL,                         \
  45.  (l)->lh_TailPred=(struct Node *)(l))
  46.  
  47. /*****************************************************************************
  48.  
  49.     NAME */
  50.     #include <clib/dos_protos.h>
  51.  
  52.     AROS_LH2(BPTR, Open,
  53.  
  54. /*  SYNOPSIS */
  55.     AROS_LHA(STRPTR, name,       D1),
  56.     AROS_LHA(LONG,   accessMode, D2),
  57.  
  58. /*  LOCATION */
  59.     struct DosLibrary *, DOSBase, 5, Dos)
  60.  
  61. /*  FUNCTION
  62.     Opens a file for read and/or write depending on the accessmode given.
  63.  
  64.     INPUTS
  65.     name       - NUL terminated name of the file.
  66.     accessMode - One of MODE_OLDFILE   - open existing file
  67.                 MODE_NEWFILE   - delete old, create new file
  68.                          exclusive lock
  69.                 MODE_READWRITE - open new one if it doesn't exist
  70.  
  71.     RESULT
  72.     Handle to the file or 0 if the file couldn't be opened.
  73.     IoErr() gives additional information in that case.
  74.  
  75.     NOTES
  76.  
  77.     EXAMPLE
  78.  
  79.     BUGS
  80.  
  81.     SEE ALSO
  82.  
  83.     INTERNALS
  84.  
  85.     HISTORY
  86.     29-10-95    digulla automatically created from
  87.                 dos_lib.fd and clib/dos_protos.h
  88.  
  89. *****************************************************************************/
  90. {
  91.     AROS_LIBFUNC_INIT
  92.     AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
  93.  
  94.     struct FileHandle *ret;
  95.     BPTR con, ast;
  96.  
  97.     /* Get pointer to process structure */
  98.     struct Process *me=(struct Process *)FindTask(NULL);
  99.  
  100.     /* Create filehandle */
  101.     ret=(struct FileHandle *)AllocDosObject(DOS_FILEHANDLE,NULL);
  102.     if(ret!=NULL)
  103.     {
  104.     /* Get pointer to I/O request. Use stackspace for now. */
  105.     struct IOFileSys io,*iofs=&io;
  106.  
  107.     /* Prepare I/O request. */
  108.     iofs->IOFS.io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  109.     iofs->IOFS.io_Message.mn_ReplyPort   =&me->pr_MsgPort;
  110.     iofs->IOFS.io_Message.mn_Length      =sizeof(struct IOFileSys);
  111.     iofs->IOFS.io_Flags=0;
  112.     iofs->IOFS.io_Command=FSA_OPEN_FILE;
  113.  
  114.     /* io_Args[0] is the name which is set by DoName(). */
  115.     switch(accessMode)
  116.     {
  117.         case MODE_OLDFILE:
  118.         iofs->io_Args[1]=FMF_WRITE|FMF_READ;
  119.         ast=con=me->pr_CIS;
  120.         break;
  121.         case MODE_NEWFILE:
  122.         iofs->io_Args[1]=FMF_LOCK|FMF_CREATE|FMF_CLEAR|FMF_WRITE|FMF_READ;
  123.         con=me->pr_COS;
  124.         ast=me->pr_CES?me->pr_CES:me->pr_COS;
  125.         break;
  126.         case MODE_READWRITE:
  127.         iofs->io_Args[1]=FMF_CREATE|FMF_WRITE|FMF_READ;
  128.         con=me->pr_COS;
  129.         ast=me->pr_CES?me->pr_CES:me->pr_COS;
  130.         break;
  131.         default:
  132.         iofs->io_Args[1]=accessMode;
  133.         ast=con=me->pr_CIS;
  134.         break;
  135.     }
  136.     iofs->io_Args[2]=FIBF_READ|FIBF_WRITE|FIBF_EXECUTE|FIBF_DELETE;
  137.     if(!Stricmp(name,"CONSOLE:"))
  138.     {
  139.         iofs->IOFS.io_Device=((struct FileHandle *)BADDR(con))->fh_Device;
  140.         iofs->IOFS.io_Unit    =((struct FileHandle *)BADDR(con))->fh_Unit;
  141.         iofs->io_Args[0]=(IPTR)"";
  142.         (void)DoIO(&iofs->IOFS);
  143.     }else if(!Stricmp(name,"*"))
  144.     {
  145.         iofs->IOFS.io_Device=((struct FileHandle *)BADDR(ast))->fh_Device;
  146.         iofs->IOFS.io_Unit    =((struct FileHandle *)BADDR(ast))->fh_Unit;
  147.         iofs->io_Args[0]=(IPTR)"";
  148.         (void)DoIO(&iofs->IOFS);
  149.     }else
  150.         (void)DoName(iofs,name,DOSBase);
  151.     if(!(me->pr_Result2=iofs->io_DosError))
  152.     {
  153.         ret->fh_Device=iofs->IOFS.io_Device;
  154.         ret->fh_Unit  =iofs->IOFS.io_Unit;
  155.         return MKBADDR(ret);
  156.     }
  157.     FreeDosObject(DOS_FILEHANDLE,ret);
  158.     }else
  159.     me->pr_Result2=ERROR_NO_FREE_STORE;
  160.     return 0;
  161.     AROS_LIBFUNC_EXIT
  162. } /* Open */
  163.