195b7b453SJohn Marino /* Binary mode I/O. 2*09d4459fSDaniel Fojt Copyright (C) 2001, 2003, 2005, 2008-2020 Free Software Foundation, Inc. 395b7b453SJohn Marino 495b7b453SJohn Marino This program is free software: you can redistribute it and/or modify 595b7b453SJohn Marino it under the terms of the GNU General Public License as published by 695b7b453SJohn Marino the Free Software Foundation; either version 3 of the License, or 795b7b453SJohn Marino (at your option) any later version. 895b7b453SJohn Marino 995b7b453SJohn Marino This program is distributed in the hope that it will be useful, 1095b7b453SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of 1195b7b453SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1295b7b453SJohn Marino GNU General Public License for more details. 1395b7b453SJohn Marino 1495b7b453SJohn Marino 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/>. */ 1695b7b453SJohn Marino 1795b7b453SJohn Marino #ifndef _BINARY_H 1895b7b453SJohn Marino #define _BINARY_H 1995b7b453SJohn Marino 2095b7b453SJohn Marino /* For systems that distinguish between text and binary I/O. 21200fbe8dSJohn Marino O_BINARY is guaranteed by the gnulib <fcntl.h>. */ 2295b7b453SJohn Marino #include <fcntl.h> 2395b7b453SJohn Marino 2495b7b453SJohn Marino /* The MSVC7 <stdio.h> doesn't like to be included after '#define fileno ...', 2595b7b453SJohn Marino so we include it here first. */ 2695b7b453SJohn Marino #include <stdio.h> 2795b7b453SJohn Marino 28680a9cb8SJohn Marino #ifndef _GL_INLINE_HEADER_BEGIN 29680a9cb8SJohn Marino #error "Please include config.h first." 30680a9cb8SJohn Marino #endif 31680a9cb8SJohn Marino _GL_INLINE_HEADER_BEGIN 32680a9cb8SJohn Marino #ifndef BINARY_IO_INLINE 33680a9cb8SJohn Marino # define BINARY_IO_INLINE _GL_INLINE 34680a9cb8SJohn Marino #endif 35680a9cb8SJohn Marino 3695b7b453SJohn Marino #if O_BINARY 3795b7b453SJohn Marino # if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__ 3895b7b453SJohn Marino # include <io.h> /* declares setmode() */ 39*09d4459fSDaniel Fojt # define __gl_setmode setmode 4095b7b453SJohn Marino # else 41*09d4459fSDaniel Fojt # define __gl_setmode _setmode 4295b7b453SJohn Marino # undef fileno 4395b7b453SJohn Marino # define fileno _fileno 4495b7b453SJohn Marino # endif 45a8597f6cSJohn Marino #else 46a8597f6cSJohn Marino /* On reasonable systems, binary I/O is the only choice. */ 47680a9cb8SJohn Marino /* Use a function rather than a macro, to avoid gcc warnings 48a8597f6cSJohn Marino "warning: statement with no effect". */ 49680a9cb8SJohn Marino BINARY_IO_INLINE int 50*09d4459fSDaniel Fojt __gl_setmode (int fd _GL_UNUSED, int mode _GL_UNUSED) 51a8597f6cSJohn Marino { 52a8597f6cSJohn Marino return O_BINARY; 53a8597f6cSJohn Marino } 54a8597f6cSJohn Marino #endif 55a8597f6cSJohn Marino 56*09d4459fSDaniel Fojt /* Set FD's mode to MODE, which should be either O_TEXT or O_BINARY. 57*09d4459fSDaniel Fojt Return the old mode if successful, -1 (setting errno) on failure. 58*09d4459fSDaniel Fojt Ordinarily this function would be called 'setmode', since that is 59*09d4459fSDaniel Fojt its name on MS-Windows, but it is called 'set_binary_mode' here 60*09d4459fSDaniel Fojt to avoid colliding with a BSD function of another name. */ 61*09d4459fSDaniel Fojt 62*09d4459fSDaniel Fojt #if defined __DJGPP__ || defined __EMX__ 63*09d4459fSDaniel Fojt extern int set_binary_mode (int fd, int mode); 6495b7b453SJohn Marino #else 65*09d4459fSDaniel Fojt BINARY_IO_INLINE int 66*09d4459fSDaniel Fojt set_binary_mode (int fd, int mode) 67*09d4459fSDaniel Fojt { 68*09d4459fSDaniel Fojt return __gl_setmode (fd, mode); 69*09d4459fSDaniel Fojt } 7095b7b453SJohn Marino #endif 7195b7b453SJohn Marino 72*09d4459fSDaniel Fojt /* This macro is obsolescent. */ 73*09d4459fSDaniel Fojt #define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY)) 74*09d4459fSDaniel Fojt 75680a9cb8SJohn Marino _GL_INLINE_HEADER_END 76680a9cb8SJohn Marino 7795b7b453SJohn Marino #endif /* _BINARY_H */ 78