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

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: read.c,v 1.1 1997/01/15 17:48:50 digulla Exp $
  4.  
  5.     Desc: ANSI C function read()
  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.     ssize_t read (
  22.  
  23. /*  SYNOPSIS */
  24.     int    fd,
  25.     void * buf,
  26.     size_t count)
  27.  
  28. /*  FUNCTION
  29.     Read an amount of bytes from a file descriptor.
  30.  
  31.     INPUTS
  32.     fd - The file descriptor to read from
  33.     buf - The buffer to read the bytes into
  34.     count - Read this many bytes.
  35.  
  36.     RESULT
  37.     The number of characters read (may range from 0 when the file
  38.     descriptor contains no more characters to count) or -1 on error.
  39.  
  40.     NOTES
  41.  
  42.     EXAMPLE
  43.  
  44.     BUGS
  45.  
  46.     SEE ALSO
  47.     open(), read(), fread()
  48.  
  49.     INTERNALS
  50.  
  51.     HISTORY
  52.     15.12.1996 digulla created
  53.  
  54. ******************************************************************************/
  55. {
  56.     ssize_t cnt;
  57.  
  58.     switch (fd)
  59.     {
  60.     case 0: /* Stdin */
  61.     cnt = Read (Input(), buf, count);
  62.     break;
  63.  
  64.     case 1: /* Stdout */
  65.     case 2: /* Stderr */
  66.     errno = EINVAL;
  67.     return EOF;
  68.  
  69.     default: {
  70.     FILENODE * fn;
  71.  
  72.     fn = GetFilenode4fd (fd);
  73.  
  74.     if (!fn)
  75.     {
  76.         errno = EBADF;
  77.         return EOF;
  78.     }
  79.  
  80.     cnt = Read ((BPTR)fn->File.fh, buf, count);
  81.  
  82.     break; }
  83.     }
  84.  
  85.     if (cnt == -1)
  86.     errno = IoErr2errno (IoErr ());
  87.  
  88.     return cnt;
  89. } /* read */
  90.  
  91.