freading.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* Retrieve information about a FILE stream.
  2. Copyright (C) 2007-2013 Free Software Foundation, Inc.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #include <stdbool.h>
  14. #include <stdio.h>
  15. /* Return true if the stream STREAM is opened read-only, or if the
  16. last operation on the stream was a read operation. Return false if
  17. the stream is opened write-only or append-only, or if it supports
  18. writing and there is no current read operation (such as fgetc).
  19. freading and fwriting will never both be true. If STREAM supports
  20. both reads and writes, then:
  21. - both freading and fwriting might be false when the stream is first
  22. opened, after read encounters EOF, or after fflush,
  23. - freading might be false or true and fwriting might be false
  24. after repositioning (such as fseek, fsetpos, or rewind),
  25. depending on the underlying implementation.
  26. STREAM must not be wide-character oriented. */
  27. #if HAVE___FREADING && (!defined __GLIBC__ || defined __UCLIBC__ || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7))
  28. /* Solaris >= 7, not glibc >= 2.2, but glibc >= 2.7, or musl libc */
  29. # include <stdio_ext.h>
  30. # define freading(stream) (__freading (stream) != 0)
  31. #else
  32. # ifdef __cplusplus
  33. extern "C" {
  34. # endif
  35. extern bool freading (FILE *stream);
  36. # ifdef __cplusplus
  37. }
  38. # endif
  39. #endif