Blame lib/binary-io.h

Packit Service c3aa71
/* Binary mode I/O.
Packit Service c3aa71
   Copyright (C) 2001, 2003, 2005, 2008-2015 Free Software Foundation, Inc.
Packit Service c3aa71
Packit Service c3aa71
   This program is free software: you can redistribute it and/or modify
Packit Service c3aa71
   it under the terms of the GNU General Public License as published by
Packit Service c3aa71
   the Free Software Foundation; either version 3 of the License, or
Packit Service c3aa71
   (at your option) any later version.
Packit Service c3aa71
Packit Service c3aa71
   This program is distributed in the hope that it will be useful,
Packit Service c3aa71
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service c3aa71
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service c3aa71
   GNU General Public License for more details.
Packit Service c3aa71
Packit Service c3aa71
   You should have received a copy of the GNU General Public License
Packit Service c3aa71
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit Service c3aa71
Packit Service c3aa71
#ifndef _BINARY_H
Packit Service c3aa71
#define _BINARY_H
Packit Service c3aa71
Packit Service c3aa71
/* For systems that distinguish between text and binary I/O.
Packit Service c3aa71
   O_BINARY is guaranteed by the gnulib <fcntl.h>. */
Packit Service c3aa71
#include <fcntl.h>
Packit Service c3aa71
Packit Service c3aa71
/* The MSVC7 <stdio.h> doesn't like to be included after '#define fileno ...',
Packit Service c3aa71
   so we include it here first.  */
Packit Service c3aa71
#include <stdio.h>
Packit Service c3aa71
Packit Service c3aa71
#ifndef _GL_INLINE_HEADER_BEGIN
Packit Service c3aa71
 #error "Please include config.h first."
Packit Service c3aa71
#endif
Packit Service c3aa71
_GL_INLINE_HEADER_BEGIN
Packit Service c3aa71
#ifndef BINARY_IO_INLINE
Packit Service c3aa71
# define BINARY_IO_INLINE _GL_INLINE
Packit Service c3aa71
#endif
Packit Service c3aa71
Packit Service c3aa71
/* set_binary_mode (fd, mode)
Packit Service c3aa71
   sets the binary/text I/O mode of file descriptor fd to the given mode
Packit Service c3aa71
   (must be O_BINARY or O_TEXT) and returns the previous mode.  */
Packit Service c3aa71
#if O_BINARY
Packit Service c3aa71
# if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__
Packit Service c3aa71
#  include <io.h> /* declares setmode() */
Packit Service c3aa71
#  define set_binary_mode setmode
Packit Service c3aa71
# else
Packit Service c3aa71
#  define set_binary_mode _setmode
Packit Service c3aa71
#  undef fileno
Packit Service c3aa71
#  define fileno _fileno
Packit Service c3aa71
# endif
Packit Service c3aa71
#else
Packit Service c3aa71
  /* On reasonable systems, binary I/O is the only choice.  */
Packit Service c3aa71
  /* Use a function rather than a macro, to avoid gcc warnings
Packit Service c3aa71
     "warning: statement with no effect".  */
Packit Service c3aa71
BINARY_IO_INLINE int
Packit Service c3aa71
set_binary_mode (int fd, int mode)
Packit Service c3aa71
{
Packit Service c3aa71
  (void) fd;
Packit Service c3aa71
  (void) mode;
Packit Service c3aa71
  return O_BINARY;
Packit Service c3aa71
}
Packit Service c3aa71
#endif
Packit Service c3aa71
Packit Service c3aa71
/* SET_BINARY (fd);
Packit Service c3aa71
   changes the file descriptor fd to perform binary I/O.  */
Packit Service c3aa71
#ifdef __DJGPP__
Packit Service c3aa71
# include <unistd.h> /* declares isatty() */
Packit Service c3aa71
  /* Avoid putting stdin/stdout in binary mode if it is connected to
Packit Service c3aa71
     the console, because that would make it impossible for the user
Packit Service c3aa71
     to interrupt the program through Ctrl-C or Ctrl-Break.  */
Packit Service c3aa71
# define SET_BINARY(fd) ((void) (!isatty (fd) ? (set_binary_mode (fd, O_BINARY), 0) : 0))
Packit Service c3aa71
#else
Packit Service c3aa71
# define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY))
Packit Service c3aa71
#endif
Packit Service c3aa71
Packit Service c3aa71
_GL_INLINE_HEADER_END
Packit Service c3aa71
Packit Service c3aa71
#endif /* _BINARY_H */