Neutralize language specific to a repository type.
[emacs.git] / lib / binary-io.h
blob7928f8c10ccd62257ee448c8e928ba764c509cf1
1 /* Binary mode I/O.
2 Copyright (C) 2001, 2003, 2005, 2008-2014 Free Software Foundation, Inc.
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 3 of the License, or
7 (at your option) any later version.
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.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 #ifndef _BINARY_H
18 #define _BINARY_H
20 /* For systems that distinguish between text and binary I/O.
21 O_BINARY is guaranteed by the gnulib <fcntl.h>. */
22 #include <fcntl.h>
24 /* The MSVC7 <stdio.h> doesn't like to be included after '#define fileno ...',
25 so we include it here first. */
26 #include <stdio.h>
28 #ifndef _GL_INLINE_HEADER_BEGIN
29 #error "Please include config.h first."
30 #endif
31 _GL_INLINE_HEADER_BEGIN
32 #ifndef BINARY_IO_INLINE
33 # define BINARY_IO_INLINE _GL_INLINE
34 #endif
36 /* set_binary_mode (fd, mode)
37 sets the binary/text I/O mode of file descriptor fd to the given mode
38 (must be O_BINARY or O_TEXT) and returns the previous mode. */
39 #if O_BINARY
40 # if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__
41 # include <io.h> /* declares setmode() */
42 # define set_binary_mode setmode
43 # else
44 # define set_binary_mode _setmode
45 # undef fileno
46 # define fileno _fileno
47 # endif
48 #else
49 /* On reasonable systems, binary I/O is the only choice. */
50 /* Use a function rather than a macro, to avoid gcc warnings
51 "warning: statement with no effect". */
52 BINARY_IO_INLINE int
53 set_binary_mode (int fd, int mode)
55 (void) fd;
56 (void) mode;
57 return O_BINARY;
59 #endif
61 /* SET_BINARY (fd);
62 changes the file descriptor fd to perform binary I/O. */
63 #ifdef __DJGPP__
64 # include <unistd.h> /* declares isatty() */
65 /* Avoid putting stdin/stdout in binary mode if it is connected to
66 the console, because that would make it impossible for the user
67 to interrupt the program through Ctrl-C or Ctrl-Break. */
68 # define SET_BINARY(fd) ((void) (!isatty (fd) ? (set_binary_mode (fd, O_BINARY), 0) : 0))
69 #else
70 # define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY))
71 #endif
73 _GL_INLINE_HEADER_END
75 #endif /* _BINARY_H */