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

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: read.c,v 1.7 1997/01/27 00:36:28 ldp Exp $
  4.     $Log: read.c,v $
  5.     Revision 1.7  1997/01/27 00:36:28  ldp
  6.     Polish
  7.  
  8.     Revision 1.6  1996/12/09 13:53:38  aros
  9.     Added empty templates for all missing functions
  10.  
  11.     Moved #include's into first column
  12.  
  13.     Revision 1.5  1996/10/24 15:50:35  aros
  14.     Use the official AROS macros over the __AROS versions.
  15.  
  16.     Revision 1.4  1996/09/13 17:50:08  digulla
  17.     Use IPTR
  18.  
  19.     Revision 1.3  1996/08/13 13:52:50  digulla
  20.     Replaced <dos/dosextens.h> by "dos_intern.h" or added "dos_intern.h"
  21.     Replaced AROS_LA by AROS_LHA
  22.  
  23.     Revision 1.2  1996/08/01 17:40:56  digulla
  24.     Added standard header for all files
  25.  
  26.     Desc:
  27.     Lang: english
  28. */
  29. #include <proto/exec.h>
  30. #include <dos/dosextens.h>
  31. #include <dos/filesystem.h>
  32. #include "dos_intern.h"
  33.  
  34. /*****************************************************************************
  35.  
  36.     NAME */
  37. #include <proto/dos.h>
  38.  
  39.     AROS_LH3(LONG, Read,
  40.  
  41. /*  SYNOPSIS */
  42.     AROS_LHA(BPTR, file,   D1),
  43.     AROS_LHA(APTR, buffer, D2),
  44.     AROS_LHA(LONG, length, D3),
  45.  
  46. /*  LOCATION */
  47.     struct DosLibrary *, DOSBase, 7, Dos)
  48.  
  49. /*  FUNCTION
  50.     Read some data from a given file. The request is directly
  51.     given to the filesystem - no buffering is involved. For
  52.     small amounts of data it's probably better to use the
  53.     buffered I/O routines.
  54.  
  55.     INPUTS
  56.     file   - filehandle
  57.     buffer - pointer to buffer for the data
  58.     length - number of bytes to read. The filesystem is
  59.          advised to try to fulfill the request as good
  60.          as possible.
  61.  
  62.     RESULT
  63.     The number of bytes actually read, 0 if the end of the
  64.     file was reached, -1 if an error happened. IoErr() will
  65.     give additional information in that case.
  66.  
  67.     NOTES
  68.  
  69.     EXAMPLE
  70.  
  71.     BUGS
  72.  
  73.     SEE ALSO
  74.  
  75.     INTERNALS
  76.  
  77.     HISTORY
  78.     29-10-95    digulla automatically created from
  79.                 dos_lib.fd and clib/dos_protos.h
  80.  
  81. *****************************************************************************/
  82. {
  83.     AROS_LIBFUNC_INIT
  84.     AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
  85.  
  86.     /* Get pointer to filehandle */
  87.     struct FileHandle *fh=(struct FileHandle *)BADDR(file);
  88.  
  89.     /* Get pointer to process structure */
  90.     struct Process *me=(struct Process *)FindTask(NULL);
  91.  
  92.     /* Get pointer to I/O request. Use stackspace for now. */
  93.     struct IOFileSys io,*iofs=&io;
  94.  
  95.     /* Prepare I/O request. */
  96.     iofs->IOFS.io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  97.     iofs->IOFS.io_Message.mn_ReplyPort     =&me->pr_MsgPort;
  98.     iofs->IOFS.io_Message.mn_Length     =sizeof(struct IOFileSys);
  99.     iofs->IOFS.io_Device =fh->fh_Device;
  100.     iofs->IOFS.io_Unit     =fh->fh_Unit;
  101.     iofs->IOFS.io_Command=FSA_READ;
  102.     iofs->IOFS.io_Flags  =0;
  103.     iofs->io_Args[0]=(IPTR)buffer;
  104.     iofs->io_Args[1]=length;
  105.  
  106.     /* Send the request. */
  107.     DoIO(&iofs->IOFS);
  108.  
  109.     /* Set error code and return */
  110.     if((me->pr_Result2=iofs->io_DosError))
  111.     return -1;
  112.     else
  113.     return iofs->io_Args[1];
  114.  
  115.     AROS_LIBFUNC_EXIT
  116. } /* Read */
  117.