Blame gnulib/tests/binary-io.h

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