|
Packit Service |
fdd496 |
/* Binary mode I/O.
|
|
Packit Service |
fdd496 |
Copyright (C) 2001, 2003, 2005, 2008-2017 Free Software Foundation, Inc.
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
This program is free software: you can redistribute it and/or modify
|
|
Packit Service |
fdd496 |
it under the terms of the GNU General Public License as published by
|
|
Packit Service |
fdd496 |
the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
fdd496 |
(at your option) any later version.
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
This program is distributed in the hope that it will be useful,
|
|
Packit Service |
fdd496 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
fdd496 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
fdd496 |
GNU General Public License for more details.
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
You should have received a copy of the GNU General Public License
|
|
Packit Service |
fdd496 |
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
#ifndef _BINARY_H
|
|
Packit Service |
fdd496 |
#define _BINARY_H
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
/* For systems that distinguish between text and binary I/O.
|
|
Packit Service |
fdd496 |
O_BINARY is guaranteed by the gnulib <fcntl.h>. */
|
|
Packit Service |
fdd496 |
#include <fcntl.h>
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
/* The MSVC7 <stdio.h> doesn't like to be included after '#define fileno ...',
|
|
Packit Service |
fdd496 |
so we include it here first. */
|
|
Packit Service |
fdd496 |
#include <stdio.h>
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
#ifndef _GL_INLINE_HEADER_BEGIN
|
|
Packit Service |
fdd496 |
#error "Please include config.h first."
|
|
Packit Service |
fdd496 |
#endif
|
|
Packit Service |
fdd496 |
_GL_INLINE_HEADER_BEGIN
|
|
Packit Service |
fdd496 |
#ifndef BINARY_IO_INLINE
|
|
Packit Service |
fdd496 |
# define BINARY_IO_INLINE _GL_INLINE
|
|
Packit Service |
fdd496 |
#endif
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
#if O_BINARY
|
|
Packit Service |
fdd496 |
# if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__
|
|
Packit Service |
fdd496 |
# include <io.h> /* declares setmode() */
|
|
Packit Service |
fdd496 |
# define __gl_setmode setmode
|
|
Packit Service |
fdd496 |
# else
|
|
Packit Service |
fdd496 |
# define __gl_setmode _setmode
|
|
Packit Service |
fdd496 |
# undef fileno
|
|
Packit Service |
fdd496 |
# define fileno _fileno
|
|
Packit Service |
fdd496 |
# endif
|
|
Packit Service |
fdd496 |
#else
|
|
Packit Service |
fdd496 |
/* On reasonable systems, binary I/O is the only choice. */
|
|
Packit Service |
fdd496 |
/* Use a function rather than a macro, to avoid gcc warnings
|
|
Packit Service |
fdd496 |
"warning: statement with no effect". */
|
|
Packit Service |
fdd496 |
BINARY_IO_INLINE int
|
|
Packit Service |
fdd496 |
__gl_setmode (int fd, int mode)
|
|
Packit Service |
fdd496 |
{
|
|
Packit Service |
fdd496 |
(void) fd;
|
|
Packit Service |
fdd496 |
(void) mode;
|
|
Packit Service |
fdd496 |
return O_BINARY;
|
|
Packit Service |
fdd496 |
}
|
|
Packit Service |
fdd496 |
#endif
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
#if defined __DJGPP__ || defined __EMX__
|
|
Packit Service |
fdd496 |
extern int __gl_setmode_check (int);
|
|
Packit Service |
fdd496 |
#else
|
|
Packit Service |
fdd496 |
BINARY_IO_INLINE int
|
|
Packit Service |
fdd496 |
__gl_setmode_check (int fd) { return 0; }
|
|
Packit Service |
fdd496 |
#endif
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
/* Set FD's mode to MODE, which should be either O_TEXT or O_BINARY.
|
|
Packit Service |
fdd496 |
Return the old mode if successful, -1 (setting errno) on failure.
|
|
Packit Service |
fdd496 |
Ordinarily this function would be called 'setmode', since that is
|
|
Packit Service |
fdd496 |
its name on MS-Windows, but it is called 'set_binary_mode' here
|
|
Packit Service |
fdd496 |
to avoid colliding with a BSD function of another name. */
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
BINARY_IO_INLINE int
|
|
Packit Service |
fdd496 |
set_binary_mode (int fd, int mode)
|
|
Packit Service |
fdd496 |
{
|
|
Packit Service |
fdd496 |
int r = __gl_setmode_check (fd);
|
|
Packit Service |
fdd496 |
return r != 0 ? r : __gl_setmode (fd, mode);
|
|
Packit Service |
fdd496 |
}
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
/* This macro is obsolescent. */
|
|
Packit Service |
fdd496 |
#define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY))
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
_GL_INLINE_HEADER_END
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
#endif /* _BINARY_H */
|