1*09d4459fSDaniel Fojt /* Binary mode I/O with checking 2*09d4459fSDaniel Fojt Copyright 2017-2020 Free Software Foundation, Inc. 3*09d4459fSDaniel Fojt 4*09d4459fSDaniel Fojt This program is free software: you can redistribute it and/or modify 5*09d4459fSDaniel Fojt it under the terms of the GNU General Public License as published by 6*09d4459fSDaniel Fojt the Free Software Foundation; either version 3 of the License, or 7*09d4459fSDaniel Fojt (at your option) any later version. 8*09d4459fSDaniel Fojt 9*09d4459fSDaniel Fojt This program is distributed in the hope that it will be useful, 10*09d4459fSDaniel Fojt but WITHOUT ANY WARRANTY; without even the implied warranty of 11*09d4459fSDaniel Fojt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12*09d4459fSDaniel Fojt GNU General Public License for more details. 13*09d4459fSDaniel Fojt 14*09d4459fSDaniel Fojt You should have received a copy of the GNU General Public License 15*09d4459fSDaniel Fojt along with this program. If not, see <https://www.gnu.org/licenses/>. */ 16*09d4459fSDaniel Fojt 17*09d4459fSDaniel Fojt #ifndef _XBINARY_IO_H 18*09d4459fSDaniel Fojt #define _XBINARY_IO_H 19*09d4459fSDaniel Fojt 20*09d4459fSDaniel Fojt #include "binary-io.h" 21*09d4459fSDaniel Fojt 22*09d4459fSDaniel Fojt #ifndef _GL_INLINE_HEADER_BEGIN 23*09d4459fSDaniel Fojt #error "Please include config.h first." 24*09d4459fSDaniel Fojt #endif 25*09d4459fSDaniel Fojt _GL_INLINE_HEADER_BEGIN 26*09d4459fSDaniel Fojt #ifndef XBINARY_IO_INLINE 27*09d4459fSDaniel Fojt # define XBINARY_IO_INLINE _GL_INLINE 28*09d4459fSDaniel Fojt #endif 29*09d4459fSDaniel Fojt 30*09d4459fSDaniel Fojt #if O_BINARY 31*09d4459fSDaniel Fojt extern _Noreturn void xset_binary_mode_error (void); 32*09d4459fSDaniel Fojt #else 33*09d4459fSDaniel Fojt XBINARY_IO_INLINE void xset_binary_mode_error (void) {} 34*09d4459fSDaniel Fojt #endif 35*09d4459fSDaniel Fojt 36*09d4459fSDaniel Fojt /* Set the mode of FD to MODE, which should be either O_TEXT or O_BINARY. 37*09d4459fSDaniel Fojt Report an error and exit if this fails. */ 38*09d4459fSDaniel Fojt 39*09d4459fSDaniel Fojt XBINARY_IO_INLINE void xset_binary_mode(int fd,int mode)40*09d4459fSDaniel Fojtxset_binary_mode (int fd, int mode) 41*09d4459fSDaniel Fojt { 42*09d4459fSDaniel Fojt if (set_binary_mode (fd, mode) < 0) 43*09d4459fSDaniel Fojt xset_binary_mode_error (); 44*09d4459fSDaniel Fojt } 45*09d4459fSDaniel Fojt 46*09d4459fSDaniel Fojt _GL_INLINE_HEADER_END 47*09d4459fSDaniel Fojt 48*09d4459fSDaniel Fojt #endif /* _XBINARY_IO_H */ 49