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