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

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: fflush.c,v 1.3 1997/01/01 03:41:09 ldp Exp $
  4.  
  5.     Desc: ANSI C function fflush()
  6.     Lang: english
  7. */
  8. #include <errno.h>
  9. #include <exec/types.h>
  10. #include <dos/dosextens.h>
  11. #include <proto/exec.h>
  12. #include <proto/dos.h>
  13.  
  14. /*****************************************************************************
  15.  
  16.     NAME */
  17. #include <stdio.h>
  18.  
  19.     int fflush (
  20.  
  21. /*  SYNOPSIS */
  22.     FILE * stream)
  23.  
  24. /*  FUNCTION
  25.     Flush a stream. If the stream is an input stream, then the stream
  26.     is synchronised for unbuffered I/O. If the stream is an output
  27.     stream, then any buffered data is written.
  28.  
  29.     INPUTS
  30.     stream - Flush this stream. May be NULL. In this case, all
  31.         output streams are flushed.
  32.  
  33.     RESULT
  34.     0 on success or EOF on error.
  35.  
  36.     NOTES
  37.  
  38.     EXAMPLE
  39.  
  40.     BUGS
  41.  
  42.     SEE ALSO
  43.  
  44.     INTERNALS
  45.  
  46.     HISTORY
  47.     10.12.1996 digulla created
  48.  
  49. ******************************************************************************/
  50. {
  51.     BPTR fh;
  52.  
  53.     switch ((IPTR)stream)
  54.     {
  55.     case 1:
  56.     fh = Input ();
  57.  
  58.     break;
  59.  
  60.     case 0: /* TODO flush all output streams */
  61.     case 2:
  62.     fh = Output ();
  63.  
  64.     break;
  65.  
  66.     case 3: {
  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.     fh = stream->fh;
  75.     break;
  76.     }
  77.  
  78.     if (fh && Flush (fh))
  79.     return 0;
  80.  
  81.     if (!fh)
  82.     errno = EINVAL;
  83.     else
  84.     {
  85.     switch (IoErr())
  86.     {
  87.     case ERROR_OBJECT_WRONG_TYPE:
  88.         errno = EINVAL;
  89.         break;
  90.  
  91.     case ERROR_NO_FREE_STORE:
  92.         errno = ENOMEM;
  93.         break;
  94.  
  95.     case ERROR_OBJECT_NOT_FOUND:
  96.         errno = ENOENT;
  97.         break;
  98.  
  99.     default:
  100.         errno = ENOSYS;
  101.         break;
  102.     }
  103.     }
  104.  
  105.     return EOF;
  106. } /* fflush */
  107.  
  108.