175fd0b74Schristos /* Binary mode I/O. 2*e992f068Schristos Copyright (C) 2001-2022 Free Software Foundation, Inc. 375fd0b74Schristos 475fd0b74Schristos This program is free software: you can redistribute it and/or modify 575fd0b74Schristos it under the terms of the GNU General Public License as published by 675fd0b74Schristos the Free Software Foundation; either version 3 of the License, or 775fd0b74Schristos (at your option) any later version. 875fd0b74Schristos 975fd0b74Schristos This program is distributed in the hope that it will be useful, 1075fd0b74Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 1175fd0b74Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1275fd0b74Schristos GNU General Public License for more details. 1375fd0b74Schristos 1475fd0b74Schristos You should have received a copy of the GNU General Public License 1575fd0b74Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 1675fd0b74Schristos 1775fd0b74Schristos #ifndef _BINARY_H 1875fd0b74Schristos #define _BINARY_H 1975fd0b74Schristos 2075fd0b74Schristos /* Include this header after <fcntl.h> and <stdio.h>, because 2175fd0b74Schristos systems that distinguish between text and binary I/O usually 2275fd0b74Schristos define O_BINARY in <fcntl.h>, and the MSVC7 <stdio.h> doesn't 2375fd0b74Schristos like to be included after '#define fileno ...' 2475fd0b74Schristos 2575fd0b74Schristos We don't include <fcntl.h> here because not all systems have 2675fd0b74Schristos that header. */ 2775fd0b74Schristos 2875fd0b74Schristos #if !defined O_BINARY && defined _O_BINARY 2975fd0b74Schristos /* For MSC-compatible compilers. */ 3075fd0b74Schristos # define O_BINARY _O_BINARY 3175fd0b74Schristos # define O_TEXT _O_TEXT 3275fd0b74Schristos #endif 3375fd0b74Schristos #ifdef __BEOS__ 3475fd0b74Schristos /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */ 3575fd0b74Schristos # undef O_BINARY 3675fd0b74Schristos # undef O_TEXT 3775fd0b74Schristos #endif 3875fd0b74Schristos #if O_BINARY 3975fd0b74Schristos # if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__ 4075fd0b74Schristos # include <io.h> /* declares setmode() */ 4175fd0b74Schristos # else 4275fd0b74Schristos # define setmode _setmode 4375fd0b74Schristos # undef fileno 4475fd0b74Schristos # define fileno _fileno 4575fd0b74Schristos # endif 4675fd0b74Schristos # ifdef __DJGPP__ 4775fd0b74Schristos # include <unistd.h> /* declares isatty() */ 4875fd0b74Schristos # /* Avoid putting stdin/stdout in binary mode if it is connected to the 4975fd0b74Schristos # console, because that would make it impossible for the user to 5075fd0b74Schristos # interrupt the program through Ctrl-C or Ctrl-Break. */ 5175fd0b74Schristos # define SET_BINARY(fd) (!isatty (fd) ? (setmode (fd, O_BINARY), 0) : 0) 5275fd0b74Schristos # else 5375fd0b74Schristos # define SET_BINARY(fd) setmode (fd, O_BINARY) 5475fd0b74Schristos # endif 5575fd0b74Schristos #else 5675fd0b74Schristos /* On reasonable systems, binary I/O is the default. */ 5775fd0b74Schristos # undef O_BINARY 5875fd0b74Schristos # define O_BINARY 0 5975fd0b74Schristos # define SET_BINARY(fd) /* nothing */ 6075fd0b74Schristos #endif 6175fd0b74Schristos 6275fd0b74Schristos #endif /* _BINARY_H */ 63