xref: /netbsd-src/external/gpl3/binutils/dist/include/binary-io.h (revision cb63e24e8d6aae7ddac1859a9015f48b1d8bd90e)
12a6b7db3Sskrll /* Binary mode I/O.
2*cb63e24eSchristos    Copyright (C) 2001-2024 Free Software Foundation, Inc.
32a6b7db3Sskrll 
42a6b7db3Sskrll    This program is free software: you can redistribute it and/or modify
52a6b7db3Sskrll    it under the terms of the GNU General Public License as published by
62a6b7db3Sskrll    the Free Software Foundation; either version 3 of the License, or
72a6b7db3Sskrll    (at your option) any later version.
82a6b7db3Sskrll 
92a6b7db3Sskrll    This program is distributed in the hope that it will be useful,
102a6b7db3Sskrll    but WITHOUT ANY WARRANTY; without even the implied warranty of
112a6b7db3Sskrll    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
122a6b7db3Sskrll    GNU General Public License for more details.
132a6b7db3Sskrll 
142a6b7db3Sskrll    You should have received a copy of the GNU General Public License
152a6b7db3Sskrll    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
162a6b7db3Sskrll 
172a6b7db3Sskrll #ifndef _BINARY_H
182a6b7db3Sskrll #define _BINARY_H
192a6b7db3Sskrll 
202a6b7db3Sskrll /* Include this header after <fcntl.h> and <stdio.h>, because
212a6b7db3Sskrll    systems that distinguish between text and binary I/O usually
222a6b7db3Sskrll    define O_BINARY in <fcntl.h>, and the MSVC7 <stdio.h> doesn't
232a6b7db3Sskrll    like to be included after '#define fileno ...'
242a6b7db3Sskrll 
252a6b7db3Sskrll    We don't include <fcntl.h> here because not all systems have
262a6b7db3Sskrll    that header.  */
272a6b7db3Sskrll 
282a6b7db3Sskrll #if !defined O_BINARY && defined _O_BINARY
292a6b7db3Sskrll   /* For MSC-compatible compilers.  */
302a6b7db3Sskrll # define O_BINARY _O_BINARY
312a6b7db3Sskrll # define O_TEXT _O_TEXT
322a6b7db3Sskrll #endif
332a6b7db3Sskrll #ifdef __BEOS__
342a6b7db3Sskrll   /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect.  */
352a6b7db3Sskrll # undef O_BINARY
362a6b7db3Sskrll # undef O_TEXT
372a6b7db3Sskrll #endif
382a6b7db3Sskrll #if O_BINARY
392a6b7db3Sskrll # if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__
402a6b7db3Sskrll #  include <io.h> /* declares setmode() */
412a6b7db3Sskrll # else
422a6b7db3Sskrll #  define setmode _setmode
432a6b7db3Sskrll #  undef fileno
442a6b7db3Sskrll #  define fileno _fileno
452a6b7db3Sskrll # endif
462a6b7db3Sskrll # ifdef __DJGPP__
472a6b7db3Sskrll #  include <unistd.h> /* declares isatty() */
482a6b7db3Sskrll #  /* Avoid putting stdin/stdout in binary mode if it is connected to the
492a6b7db3Sskrll #     console, because that would make it impossible for the user to
502a6b7db3Sskrll #     interrupt the program through Ctrl-C or Ctrl-Break.  */
512a6b7db3Sskrll #  define SET_BINARY(fd) (!isatty (fd) ? (setmode (fd, O_BINARY), 0) : 0)
522a6b7db3Sskrll # else
532a6b7db3Sskrll #  define SET_BINARY(fd) setmode (fd, O_BINARY)
542a6b7db3Sskrll # endif
552a6b7db3Sskrll #else
562a6b7db3Sskrll   /* On reasonable systems, binary I/O is the default.  */
572a6b7db3Sskrll # undef O_BINARY
582a6b7db3Sskrll # define O_BINARY 0
592a6b7db3Sskrll # define SET_BINARY(fd) /* nothing */
602a6b7db3Sskrll #endif
612a6b7db3Sskrll 
622a6b7db3Sskrll #endif /* _BINARY_H */
63