#include "stdioprivate.h"
#include <errno.h>

extern "C" int fflush (register FILE *fp)
{
  if (fp == NULL) {
      int bad = 0;
      streambuf *stream;
      for (stream = __stream_list; stream != NULL; stream = stream->_chain)
	  if (__checkfp(stream))
	      bad |= __overflow((FILE*)stream, EOF) == EOF;
      return bad ? EOF : 0;
  }

  if (!__validfp(fp))
    {
      errno = EINVAL;
      return EOF;
    }

  return __overflow(fp, EOF);
}
