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