Blame lib/binary-io.h

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