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

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