Annotation of embedaddon/libiconv/srclib/binary-io.h, revision 1.1.1.3
1.1 misho 1: /* Binary mode I/O.
1.1.1.3 ! misho 2: Copyright (C) 2001, 2003, 2005, 2008-2019 Free Software Foundation, Inc.
1.1 misho 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 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 General Public License for more details.
13:
14: You should have received a copy of the GNU General Public License
1.1.1.3 ! misho 15: along with this program. If not, see <https://www.gnu.org/licenses/>. */
1.1 misho 16:
17: #ifndef _BINARY_H
18: #define _BINARY_H
19:
20: /* For systems that distinguish between text and binary I/O.
1.1.1.2 misho 21: O_BINARY is guaranteed by the gnulib <fcntl.h>. */
1.1 misho 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:
1.1.1.3 ! misho 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
! 35:
1.1 misho 36: #if O_BINARY
37: # if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__
38: # include <io.h> /* declares setmode() */
1.1.1.3 ! misho 39: # define __gl_setmode setmode
1.1 misho 40: # else
1.1.1.3 ! misho 41: # define __gl_setmode _setmode
1.1 misho 42: # undef fileno
43: # define fileno _fileno
44: # endif
45: #else
1.1.1.3 ! misho 46: /* On reasonable systems, binary I/O is the only choice. */
! 47: /* Use a function rather than a macro, to avoid gcc warnings
! 48: "warning: statement with no effect". */
! 49: BINARY_IO_INLINE int
! 50: __gl_setmode (int fd _GL_UNUSED, int mode _GL_UNUSED)
! 51: {
! 52: return O_BINARY;
! 53: }
1.1 misho 54: #endif
55:
1.1.1.3 ! misho 56: #if defined __DJGPP__ || defined __EMX__
! 57: extern int __gl_setmode_check (int);
! 58: #else
! 59: BINARY_IO_INLINE int
! 60: __gl_setmode_check (int fd _GL_UNUSED) { return 0; }
! 61: #endif
! 62:
! 63: /* Set FD's mode to MODE, which should be either O_TEXT or O_BINARY.
! 64: Return the old mode if successful, -1 (setting errno) on failure.
! 65: Ordinarily this function would be called 'setmode', since that is
! 66: its name on MS-Windows, but it is called 'set_binary_mode' here
! 67: to avoid colliding with a BSD function of another name. */
! 68:
! 69: BINARY_IO_INLINE int
! 70: set_binary_mode (int fd, int mode)
! 71: {
! 72: int r = __gl_setmode_check (fd);
! 73: return r != 0 ? r : __gl_setmode (fd, mode);
! 74: }
! 75:
! 76: /* This macro is obsolescent. */
! 77: #define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY))
! 78:
! 79: _GL_INLINE_HEADER_END
! 80:
1.1 misho 81: #endif /* _BINARY_H */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>