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