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

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