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

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: write.c,v 1.1 1997/01/15 17:48:50 digulla Exp $
  4.  
  5.     Desc: ANSI C function write()
  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 "__stdio.h"
  14. #include "__errno.h"
  15.  
  16. /*****************************************************************************
  17.  
  18.     NAME */
  19. #include <unistd.h>
  20.  
  21.     ssize_t write (
  22.  
  23. /*  SYNOPSIS */
  24.     int         fd,
  25.     const void * buf,
  26.     size_t         count)
  27.  
  28. /*  FUNCTION
  29.     Write an amount of characters to the specified file descriptor.
  30.  
  31.     INPUTS
  32.     fd - The file descriptor to write to
  33.     buf - Write these bytes into the file descriptor
  34.     count - Write that many bytes
  35.  
  36.     RESULT
  37.     The number of characters written or -1 on error.
  38.  
  39.     NOTES
  40.  
  41.     EXAMPLE
  42.  
  43.     BUGS
  44.  
  45.     SEE ALSO
  46.  
  47.     INTERNALS
  48.  
  49.     HISTORY
  50.     06.12.1996 digulla created
  51.  
  52. ******************************************************************************/
  53. {
  54.     BPTR    fh;
  55.     ssize_t cnt;
  56.  
  57.     switch (fd)
  58.     {
  59.     case 0: /* Stdin */
  60.     errno = EINVAL;
  61.     return EOF;
  62.  
  63.     case 1: /* Stdout */
  64.     fh = Output();
  65.  
  66.     case 2: { /* Stderr */
  67.     struct Process * me = (struct Process *)FindTask (NULL);
  68.  
  69.     fh = me->pr_CES ? me->pr_CES : me->pr_COS;
  70.  
  71.     break; }
  72.  
  73.     default: {
  74.     FILENODE * fn;
  75.  
  76.     fn = GetFilenode4fd (fd);
  77.  
  78.     if (!fn)
  79.     {
  80.         errno = EINVAL;
  81.         return EOF;
  82.     }
  83.  
  84.     fh = fn->File.fh;
  85.  
  86.     break; }
  87.     }
  88.  
  89.     cnt = Write (fh, (void *)buf, count);
  90.  
  91.     if (cnt == EOF)
  92.     errno = IoErr2errno (IoErr ());
  93.  
  94.     return cnt;
  95. } /* write */
  96.  
  97.