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

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