1*09d4459fSDaniel Fojt /* Binary mode I/O. 2*09d4459fSDaniel Fojt Copyright 2017-2020 Free Software Foundation, Inc. 3*09d4459fSDaniel Fojt 4*09d4459fSDaniel Fojt This program is free software: you can redistribute it and/or modify 5*09d4459fSDaniel Fojt it under the terms of the GNU General Public License as published by 6*09d4459fSDaniel Fojt the Free Software Foundation; either version 3 of the License, or 7*09d4459fSDaniel Fojt (at your option) any later version. 8*09d4459fSDaniel Fojt 9*09d4459fSDaniel Fojt This program is distributed in the hope that it will be useful, 10*09d4459fSDaniel Fojt but WITHOUT ANY WARRANTY; without even the implied warranty of 11*09d4459fSDaniel Fojt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12*09d4459fSDaniel Fojt GNU General Public License for more details. 13*09d4459fSDaniel Fojt 14*09d4459fSDaniel Fojt You should have received a copy of the GNU General Public License 15*09d4459fSDaniel Fojt along with this program. If not, see <https://www.gnu.org/licenses/>. */ 16*09d4459fSDaniel Fojt 17680a9cb8SJohn Marino #include <config.h> 18*09d4459fSDaniel Fojt 19680a9cb8SJohn Marino #define BINARY_IO_INLINE _GL_EXTERN_INLINE 20680a9cb8SJohn Marino #include "binary-io.h" 21*09d4459fSDaniel Fojt 22*09d4459fSDaniel Fojt #if defined __DJGPP__ || defined __EMX__ 23*09d4459fSDaniel Fojt # include <unistd.h> 24*09d4459fSDaniel Fojt 25*09d4459fSDaniel Fojt int 26*09d4459fSDaniel Fojt set_binary_mode (int fd, int mode) 27*09d4459fSDaniel Fojt { 28*09d4459fSDaniel Fojt if (isatty (fd)) 29*09d4459fSDaniel Fojt /* If FD refers to a console (not a pipe, not a regular file), 30*09d4459fSDaniel Fojt O_TEXT is the only reasonable mode, both on input and on output. 31*09d4459fSDaniel Fojt Silently ignore the request. If we were to return -1 here, 32*09d4459fSDaniel Fojt all programs that use xset_binary_mode would fail when run 33*09d4459fSDaniel Fojt with console input or console output. */ 34*09d4459fSDaniel Fojt return O_TEXT; 35*09d4459fSDaniel Fojt else 36*09d4459fSDaniel Fojt return __gl_setmode (fd, mode); 37*09d4459fSDaniel Fojt } 38*09d4459fSDaniel Fojt 39*09d4459fSDaniel Fojt #endif 40