Blame lib/binary-io.h

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