198b9484cSchristos /* Binary mode I/O. 2*e663ba6eSchristos Copyright (C) 2001-2024 Free Software Foundation, Inc. 398b9484cSchristos 498b9484cSchristos This program is free software: you can redistribute it and/or modify 598b9484cSchristos it under the terms of the GNU General Public License as published by 698b9484cSchristos the Free Software Foundation; either version 3 of the License, or 798b9484cSchristos (at your option) any later version. 898b9484cSchristos 998b9484cSchristos This program is distributed in the hope that it will be useful, 1098b9484cSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of 1198b9484cSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1298b9484cSchristos GNU General Public License for more details. 1398b9484cSchristos 1498b9484cSchristos You should have received a copy of the GNU General Public License 1598b9484cSchristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 1698b9484cSchristos 1798b9484cSchristos #ifndef _BINARY_H 1898b9484cSchristos #define _BINARY_H 1998b9484cSchristos 2098b9484cSchristos /* Include this header after <fcntl.h> and <stdio.h>, because 2198b9484cSchristos systems that distinguish between text and binary I/O usually 2298b9484cSchristos define O_BINARY in <fcntl.h>, and the MSVC7 <stdio.h> doesn't 2398b9484cSchristos like to be included after '#define fileno ...' 2498b9484cSchristos 2598b9484cSchristos We don't include <fcntl.h> here because not all systems have 2698b9484cSchristos that header. */ 2798b9484cSchristos 2898b9484cSchristos #if !defined O_BINARY && defined _O_BINARY 2998b9484cSchristos /* For MSC-compatible compilers. */ 3098b9484cSchristos # define O_BINARY _O_BINARY 3198b9484cSchristos # define O_TEXT _O_TEXT 3298b9484cSchristos #endif 3398b9484cSchristos #ifdef __BEOS__ 3498b9484cSchristos /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */ 3598b9484cSchristos # undef O_BINARY 3698b9484cSchristos # undef O_TEXT 3798b9484cSchristos #endif 3898b9484cSchristos #if O_BINARY 3998b9484cSchristos # if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__ 4098b9484cSchristos # include <io.h> /* declares setmode() */ 4198b9484cSchristos # else 4298b9484cSchristos # define setmode _setmode 4398b9484cSchristos # undef fileno 4498b9484cSchristos # define fileno _fileno 4598b9484cSchristos # endif 4698b9484cSchristos # ifdef __DJGPP__ 4798b9484cSchristos # include <unistd.h> /* declares isatty() */ 4898b9484cSchristos # /* Avoid putting stdin/stdout in binary mode if it is connected to the 4998b9484cSchristos # console, because that would make it impossible for the user to 5098b9484cSchristos # interrupt the program through Ctrl-C or Ctrl-Break. */ 5198b9484cSchristos # define SET_BINARY(fd) (!isatty (fd) ? (setmode (fd, O_BINARY), 0) : 0) 5298b9484cSchristos # else 5398b9484cSchristos # define SET_BINARY(fd) setmode (fd, O_BINARY) 5498b9484cSchristos # endif 5598b9484cSchristos #else 5698b9484cSchristos /* On reasonable systems, binary I/O is the default. */ 5798b9484cSchristos # undef O_BINARY 5898b9484cSchristos # define O_BINARY 0 5998b9484cSchristos # define SET_BINARY(fd) /* nothing */ 6098b9484cSchristos #endif 6198b9484cSchristos 6298b9484cSchristos #endif /* _BINARY_H */ 63