home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / dos / open.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  4.7 KB  |  177 lines

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