Blame gl/tests/binary-io.h

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