binary-io.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* Binary mode I/O.
  2. Copyright 2017-2020 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 <https://www.gnu.org/licenses/>. */
  13. #include <config.h>
  14. #define BINARY_IO_INLINE _GL_EXTERN_INLINE
  15. #include "binary-io.h"
  16. #if defined __DJGPP__ || defined __EMX__
  17. # include <unistd.h>
  18. int
  19. set_binary_mode (int fd, int mode)
  20. {
  21. if (isatty (fd))
  22. /* If FD refers to a console (not a pipe, not a regular file),
  23. O_TEXT is the only reasonable mode, both on input and on output.
  24. Silently ignore the request. If we were to return -1 here,
  25. all programs that use xset_binary_mode would fail when run
  26. with console input or console output. */
  27. return O_TEXT;
  28. else
  29. return __gl_setmode (fd, mode);
  30. }
  31. #endif