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

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: fread.c,v 1.1 1997/01/17 16:23:06 digulla Exp $
  4.  
  5.     Desc: ANSI C function fread()
  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 fread (
  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 read the bytes into
  34.     size - Size of one block to read
  35.     nblocks - The number of blocks to read
  36.     stream - Read from this stream
  37.  
  38.     RESULT
  39.     The number of blocks read. This may range from 0 when the stream
  40.     contains no more blocks up to nblocks. In case of an error, 0 is
  41.     returned.
  42.  
  43.     NOTES
  44.  
  45.     EXAMPLE
  46.  
  47.     BUGS
  48.  
  49.     SEE ALSO
  50.     fopen(), fwrite()
  51.  
  52.     INTERNALS
  53.  
  54.     HISTORY
  55.     15.12.1996 digulla created
  56.  
  57. ******************************************************************************/
  58. {
  59.     size_t cnt;
  60.     BPTR   fh;
  61.  
  62.     switch ((IPTR)stream)
  63.     {
  64.     case 1: /* Stdin */
  65.     fh = Input ();
  66.     break;
  67.  
  68.     case 2: /* Stdout */
  69.     case 3: /* Stderr */
  70.     errno = EINVAL;
  71.     return 0;
  72.  
  73.     default:
  74.     fh = stream->fh;
  75.  
  76.     break;
  77.     }
  78.  
  79.     cnt = FRead (fh, buf, size, nblocks);
  80.  
  81.     if (cnt == -1)
  82.     {
  83.     errno = IoErr2errno (IoErr ());
  84.     stream->flags |= _STDIO_FILEFLAG_ERROR;
  85.  
  86.     cnt = 0;
  87.     }
  88.     else if (cnt == 0)
  89.     {
  90.     stream->flags |= _STDIO_FILEFLAG_EOF;
  91.     }
  92.  
  93.     return cnt;
  94. } /* fread */
  95.  
  96.