home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / compiler / clib / fwrite.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-17  |  1.6 KB  |  95 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: fwrite.c,v 1.1 1997/01/17 16:23:06 digulla Exp $
  4.  
  5.     Desc: ANSI C function fwrite()
  6.     Lang: english
  7. */
  8. #include <errno.h>
  9. #include <dos/dos.h>
  10. #include <dos/dosextens.h>
  11. #include <proto/exec.h>
  12. #include <proto/dos.h>
  13. #include "__errno.h"
  14. #include "__stdio.h"
  15.  
  16. /*****************************************************************************
  17.  
  18.     NAME */
  19. #include <unistd.h>
  20.  
  21.     size_t fwrite (
  22.  
  23. /*  SYNOPSIS */
  24.     void * buf,
  25.     size_t size,
  26.     size_t nblocks,
  27.     FILE * stream)
  28.  
  29. /*  FUNCTION
  30.     Read an amount of bytes from a stream.
  31.  
  32.     INPUTS
  33.     buf - The buffer to write to the stream
  34.     size - Size of one block to write
  35.     nblocks - The number of blocks to write
  36.     stream - Write to this stream
  37.  
  38.     RESULT
  39.     The number of blocks written. If no error occurred, this is
  40.     nblocks. Otherwise examine errno for the reason of the error.
  41.  
  42.     NOTES
  43.  
  44.     EXAMPLE
  45.  
  46.     BUGS
  47.  
  48.     SEE ALSO
  49.     fopen(), fwrite()
  50.  
  51.     INTERNALS
  52.  
  53.     HISTORY
  54.     15.12.1996 digulla created
  55.  
  56. ******************************************************************************/
  57. {
  58.     size_t cnt;
  59.     BPTR   fh;
  60.  
  61.     switch ((IPTR)stream)
  62.     {
  63.     case 1: /* Stdin */
  64.     errno = EINVAL;
  65.     return 0;
  66.  
  67.     case 2: /* Stdout */
  68.     fh = Output ();
  69.     break;
  70.  
  71.     case 3: { /* Stderr */
  72.     struct Process * me = (struct Process *)FindTask (NULL);
  73.  
  74.     fh = me->pr_CES ? me->pr_CES : me->pr_COS;
  75.  
  76.     break; }
  77.  
  78.     default:
  79.     fh = (BPTR)(stream->fh);
  80.     break;
  81.     }
  82.  
  83.     cnt = FWrite (fh, buf, size, nblocks);
  84.  
  85.     if (cnt == -1)
  86.     {
  87.     errno = IoErr2errno (IoErr ());
  88.  
  89.     cnt = 0;
  90.     }
  91.  
  92.     return cnt;
  93. } /* fwrite */
  94.  
  95.