Update to gnulib 0.0.7865-a828.
[bpt/guile.git] / lib / binary-io.h
CommitLineData
3d458a81 1/* Binary mode I/O.
af07e104 2 Copyright (C) 2001, 2003, 2005, 2008-2013 Free Software Foundation, Inc.
3d458a81
AW
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser 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.
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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17#ifndef _BINARY_H
18#define _BINARY_H
19
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>
23
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>
27
7ae4e75a
LC
28_GL_INLINE_HEADER_BEGIN
29#ifndef BINARY_IO_INLINE
30# define BINARY_IO_INLINE _GL_INLINE
31#endif
32
005de2e8
LC
33/* set_binary_mode (fd, mode)
34 sets the binary/text I/O mode of file descriptor fd to the given mode
35 (must be O_BINARY or O_TEXT) and returns the previous mode. */
3d458a81
AW
36#if O_BINARY
37# if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__
38# include <io.h> /* declares setmode() */
005de2e8 39# define set_binary_mode setmode
3d458a81 40# else
005de2e8 41# define set_binary_mode _setmode
3d458a81
AW
42# undef fileno
43# define fileno _fileno
44# endif
3d458a81 45#else
005de2e8 46 /* On reasonable systems, binary I/O is the only choice. */
7ae4e75a 47 /* Use a function rather than a macro, to avoid gcc warnings
005de2e8 48 "warning: statement with no effect". */
7ae4e75a 49BINARY_IO_INLINE int
005de2e8
LC
50set_binary_mode (int fd, int mode)
51{
52 (void) fd;
53 (void) mode;
54 return O_BINARY;
55}
56#endif
57
58/* SET_BINARY (fd);
59 changes the file descriptor fd to perform binary I/O. */
60#ifdef __DJGPP__
61# include <unistd.h> /* declares isatty() */
62 /* Avoid putting stdin/stdout in binary mode if it is connected to
63 the console, because that would make it impossible for the user
64 to interrupt the program through Ctrl-C or Ctrl-Break. */
65# define SET_BINARY(fd) ((void) (!isatty (fd) ? (set_binary_mode (fd, O_BINARY), 0) : 0))
66#else
67# define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY))
3d458a81
AW
68#endif
69
7ae4e75a
LC
70_GL_INLINE_HEADER_END
71
3d458a81 72#endif /* _BINARY_H */