root/lib/binary-io.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. __gl_setmode
  2. set_binary_mode

     1 /* Binary mode I/O.
     2    Copyright (C) 2001, 2003, 2005, 2008-2023 Free Software Foundation,
     3    Inc.
     4 
     5    This file is free software: you can redistribute it and/or modify
     6    it under the terms of the GNU Lesser General Public License as
     7    published by the Free Software Foundation; either version 2.1 of the
     8    License, or (at your option) any later version.
     9 
    10    This file is distributed in the hope that it will be useful,
    11    but WITHOUT ANY WARRANTY; without even the implied warranty of
    12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13    GNU Lesser General Public License for more details.
    14 
    15    You should have received a copy of the GNU Lesser General Public License
    16    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
    17 
    18 #ifndef _BINARY_H
    19 #define _BINARY_H
    20 
    21 /* For systems that distinguish between text and binary I/O.
    22    O_BINARY is guaranteed by the gnulib <fcntl.h>. */
    23 #include <fcntl.h>
    24 
    25 /* The MSVC7 <stdio.h> doesn't like to be included after '#define fileno ...',
    26    so we include it here first.  */
    27 #include <stdio.h>
    28 
    29 #ifndef _GL_INLINE_HEADER_BEGIN
    30  #error "Please include config.h first."
    31 #endif
    32 _GL_INLINE_HEADER_BEGIN
    33 #ifndef BINARY_IO_INLINE
    34 # define BINARY_IO_INLINE _GL_INLINE
    35 #endif
    36 
    37 #if O_BINARY
    38 # if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__
    39 #  include <io.h> /* declares setmode() */
    40 #  define __gl_setmode setmode
    41 # else
    42 #  define __gl_setmode _setmode
    43 #  undef fileno
    44 #  define fileno _fileno
    45 # endif
    46 #else
    47   /* On reasonable systems, binary I/O is the only choice.  */
    48   /* Use a function rather than a macro, to avoid gcc warnings
    49      "warning: statement with no effect".  */
    50 BINARY_IO_INLINE int
    51 __gl_setmode (_GL_UNUSED int fd, _GL_UNUSED int mode)
    52 {
    53   return O_BINARY;
    54 }
    55 #endif
    56 
    57 /* Set FD's mode to MODE, which should be either O_TEXT or O_BINARY.
    58    Return the old mode if successful, -1 (setting errno) on failure.
    59    Ordinarily this function would be called 'setmode', since that is
    60    its old name on MS-Windows, but it is called 'set_binary_mode' here
    61    to avoid colliding with a BSD function of another name.  */
    62 
    63 #if defined __DJGPP__ || defined __EMX__
    64 extern int set_binary_mode (int fd, int mode);
    65 #else
    66 BINARY_IO_INLINE int
    67 set_binary_mode (int fd, int mode)
    68 {
    69   return __gl_setmode (fd, mode);
    70 }
    71 #endif
    72 
    73 /* This macro is obsolescent.  */
    74 #define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY))
    75 
    76 _GL_INLINE_HEADER_END
    77 
    78 #endif /* _BINARY_H */

/* [<][>][^][v][top][bottom][index][help] */