fcloseall.c 906 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
  2. *
  3. * GNU Library General Public License (LGPL) version 2 or later.
  4. *
  5. * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
  6. */
  7. #include <features.h>
  8. #ifdef __USE_GNU
  9. #include "_stdio.h"
  10. libc_hidden_proto(fclose)
  11. /* NOTE: GLIBC difference!!! -- fcloseall
  12. * According to the info pages, glibc actually fclose()s all open files.
  13. * Apparently, glibc's new version only fflush()s and unbuffers all
  14. * writing streams to cope with unordered destruction of c++ static
  15. * objects.
  16. */
  17. int fcloseall (void)
  18. {
  19. #ifdef __STDIO_HAS_OPENLIST
  20. int retval = 0;
  21. __STDIO_THREADLOCK_OPENLIST;
  22. while (_stdio_openlist) {
  23. if (fclose(_stdio_openlist)) {
  24. retval = EOF;
  25. }
  26. }
  27. __STDIO_THREADUNLOCK_OPENLIST;
  28. return retval;
  29. #else
  30. #warning Always fails in this configuration because no open file list.
  31. return EOF;
  32. #endif
  33. }
  34. #endif