exp2l: Work around a NetBSD 10.0/i386 bug.
[gnulib.git] / lib / binary-io.h
blob0cc5c11748ca665df77ecdf3422cca5e4d1600f1
1 /* Binary mode I/O.
2 Copyright (C) 2001, 2003, 2005, 2008-2024 Free Software Foundation, Inc.
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
9 This file 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.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 #ifndef _BINARY_H
18 #define _BINARY_H
20 /* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE, _GL_UNUSED. */
21 #if !_GL_CONFIG_H_INCLUDED
22 #error "Please include config.h first."
23 #endif
25 /* For systems that distinguish between text and binary I/O.
26 O_BINARY is guaranteed by the gnulib <fcntl.h>. */
27 #include <fcntl.h>
29 /* The MSVC7 <stdio.h> doesn't like to be included after '#define fileno ...',
30 so we include it here first. */
31 #include <stdio.h>
33 _GL_INLINE_HEADER_BEGIN
34 #ifndef BINARY_IO_INLINE
35 # define BINARY_IO_INLINE _GL_INLINE
36 #endif
38 #if O_BINARY
39 # if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__
40 # include <io.h> /* declares setmode() */
41 # define __gl_setmode setmode
42 # else
43 # define __gl_setmode _setmode
44 # undef fileno
45 # define fileno _fileno
46 # endif
47 #else
48 /* On reasonable systems, binary I/O is the only choice. */
49 /* Use a function rather than a macro, to avoid gcc warnings
50 "warning: statement with no effect". */
51 BINARY_IO_INLINE int
52 __gl_setmode (_GL_UNUSED int fd, _GL_UNUSED int mode)
54 return O_BINARY;
56 #endif
58 /* Set FD's mode to MODE, which should be either O_TEXT or O_BINARY.
59 Return the old mode if successful, -1 (setting errno) on failure.
60 Ordinarily this function would be called 'setmode', since that is
61 its old name on MS-Windows, but it is called 'set_binary_mode' here
62 to avoid colliding with a BSD function of another name. */
64 #if defined __DJGPP__ || defined __EMX__
65 extern int set_binary_mode (int fd, int mode);
66 #else
67 BINARY_IO_INLINE int
68 set_binary_mode (int fd, int mode)
70 return __gl_setmode (fd, mode);
72 #endif
74 /* This macro is obsolescent. */
75 #define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY))
77 _GL_INLINE_HEADER_END
79 #endif /* _BINARY_H */