binary-io.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* Binary mode I/O.
  2. Copyright (C) 2001-2022 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. #ifndef _BINARY_H
  14. #define _BINARY_H
  15. /* Include this header after <fcntl.h> and <stdio.h>, because
  16. systems that distinguish between text and binary I/O usually
  17. define O_BINARY in <fcntl.h>, and the MSVC7 <stdio.h> doesn't
  18. like to be included after '#define fileno ...'
  19. We don't include <fcntl.h> here because not all systems have
  20. that header. */
  21. #if !defined O_BINARY && defined _O_BINARY
  22. /* For MSC-compatible compilers. */
  23. # define O_BINARY _O_BINARY
  24. # define O_TEXT _O_TEXT
  25. #endif
  26. #ifdef __BEOS__
  27. /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */
  28. # undef O_BINARY
  29. # undef O_TEXT
  30. #endif
  31. #if O_BINARY
  32. # if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__
  33. # include <io.h> /* declares setmode() */
  34. # else
  35. # define setmode _setmode
  36. # undef fileno
  37. # define fileno _fileno
  38. # endif
  39. # ifdef __DJGPP__
  40. # include <unistd.h> /* declares isatty() */
  41. # /* Avoid putting stdin/stdout in binary mode if it is connected to the
  42. # console, because that would make it impossible for the user to
  43. # interrupt the program through Ctrl-C or Ctrl-Break. */
  44. # define SET_BINARY(fd) (!isatty (fd) ? (setmode (fd, O_BINARY), 0) : 0)
  45. # else
  46. # define SET_BINARY(fd) setmode (fd, O_BINARY)
  47. # endif
  48. #else
  49. /* On reasonable systems, binary I/O is the default. */
  50. # undef O_BINARY
  51. # define O_BINARY 0
  52. # define SET_BINARY(fd) /* nothing */
  53. #endif
  54. #endif /* _BINARY_H */