]> code.delx.au - gnu-emacs/blob - lib/binary-io.h
Update copyright year to 2015
[gnu-emacs] / lib / binary-io.h
1 /* Binary mode I/O.
2 Copyright (C) 2001, 2003, 2005, 2008-2015 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 guaranteed by the gnulib <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 #ifndef _GL_INLINE_HEADER_BEGIN
30 #error "Please include config.h first."
31 #endif
32 _GL_INLINE_HEADER_BEGIN
33 #ifndef BINARY_IO_INLINE
34 # define BINARY_IO_INLINE _GL_INLINE
35 #endif
36
37 /* set_binary_mode (fd, mode)
38 sets the binary/text I/O mode of file descriptor fd to the given mode
39 (must be O_BINARY or O_TEXT) and returns the previous mode. */
40 #if O_BINARY
41 # if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__
42 # include <io.h> /* declares setmode() */
43 # define set_binary_mode setmode
44 # else
45 # define set_binary_mode _setmode
46 # undef fileno
47 # define fileno _fileno
48 # endif
49 #else
50 /* On reasonable systems, binary I/O is the only choice. */
51 /* Use a function rather than a macro, to avoid gcc warnings
52 "warning: statement with no effect". */
53 BINARY_IO_INLINE int
54 set_binary_mode (int fd, int mode)
55 {
56 (void) fd;
57 (void) mode;
58 return O_BINARY;
59 }
60 #endif
61
62 /* SET_BINARY (fd);
63 changes the file descriptor fd to perform binary I/O. */
64 #ifdef __DJGPP__
65 # include <unistd.h> /* declares isatty() */
66 /* Avoid putting stdin/stdout in binary mode if it is connected to
67 the console, because that would make it impossible for the user
68 to interrupt the program through Ctrl-C or Ctrl-Break. */
69 # define SET_BINARY(fd) ((void) (!isatty (fd) ? (set_binary_mode (fd, O_BINARY), 0) : 0))
70 #else
71 # define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY))
72 #endif
73
74 _GL_INLINE_HEADER_END
75
76 #endif /* _BINARY_H */