1*fae548d3Szrj /* Binary mode I/O. 2*fae548d3Szrj Copyright (C) 2001-2020 Free Software Foundation, Inc. 3*fae548d3Szrj 4*fae548d3Szrj This program is free software: you can redistribute it and/or modify 5*fae548d3Szrj it under the terms of the GNU General Public License as published by 6*fae548d3Szrj the Free Software Foundation; either version 3 of the License, or 7*fae548d3Szrj (at your option) any later version. 8*fae548d3Szrj 9*fae548d3Szrj This program is distributed in the hope that it will be useful, 10*fae548d3Szrj but WITHOUT ANY WARRANTY; without even the implied warranty of 11*fae548d3Szrj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12*fae548d3Szrj GNU General Public License for more details. 13*fae548d3Szrj 14*fae548d3Szrj You should have received a copy of the GNU General Public License 15*fae548d3Szrj along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16*fae548d3Szrj 17*fae548d3Szrj #ifndef _BINARY_H 18*fae548d3Szrj #define _BINARY_H 19*fae548d3Szrj 20*fae548d3Szrj /* Include this header after <fcntl.h> and <stdio.h>, because 21*fae548d3Szrj systems that distinguish between text and binary I/O usually 22*fae548d3Szrj define O_BINARY in <fcntl.h>, and the MSVC7 <stdio.h> doesn't 23*fae548d3Szrj like to be included after '#define fileno ...' 24*fae548d3Szrj 25*fae548d3Szrj We don't include <fcntl.h> here because not all systems have 26*fae548d3Szrj that header. */ 27*fae548d3Szrj 28*fae548d3Szrj #if !defined O_BINARY && defined _O_BINARY 29*fae548d3Szrj /* For MSC-compatible compilers. */ 30*fae548d3Szrj # define O_BINARY _O_BINARY 31*fae548d3Szrj # define O_TEXT _O_TEXT 32*fae548d3Szrj #endif 33*fae548d3Szrj #ifdef __BEOS__ 34*fae548d3Szrj /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */ 35*fae548d3Szrj # undef O_BINARY 36*fae548d3Szrj # undef O_TEXT 37*fae548d3Szrj #endif 38*fae548d3Szrj #if O_BINARY 39*fae548d3Szrj # if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__ 40*fae548d3Szrj # include <io.h> /* declares setmode() */ 41*fae548d3Szrj # else 42*fae548d3Szrj # define setmode _setmode 43*fae548d3Szrj # undef fileno 44*fae548d3Szrj # define fileno _fileno 45*fae548d3Szrj # endif 46*fae548d3Szrj # ifdef __DJGPP__ 47*fae548d3Szrj # include <unistd.h> /* declares isatty() */ 48*fae548d3Szrj # /* Avoid putting stdin/stdout in binary mode if it is connected to the 49*fae548d3Szrj # console, because that would make it impossible for the user to 50*fae548d3Szrj # interrupt the program through Ctrl-C or Ctrl-Break. */ 51*fae548d3Szrj # define SET_BINARY(fd) (!isatty (fd) ? (setmode (fd, O_BINARY), 0) : 0) 52*fae548d3Szrj # else 53*fae548d3Szrj # define SET_BINARY(fd) setmode (fd, O_BINARY) 54*fae548d3Szrj # endif 55*fae548d3Szrj #else 56*fae548d3Szrj /* On reasonable systems, binary I/O is the default. */ 57*fae548d3Szrj # undef O_BINARY 58*fae548d3Szrj # define O_BINARY 0 59*fae548d3Szrj # define SET_BINARY(fd) /* nothing */ 60*fae548d3Szrj #endif 61*fae548d3Szrj 62*fae548d3Szrj #endif /* _BINARY_H */ 63