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