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