openat: don’t close (-1)
[gnulib.git] / lib / xbinary-io.h
blob52310e0de14279ecb338263788744b770506a32e
1 /* Binary mode I/O with checking
2 Copyright 2017-2024 Free Software Foundation, Inc.
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 3 of the
7 License, or (at your option) any later version.
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.
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/>. */
17 #ifndef _XBINARY_IO_H
18 #define _XBINARY_IO_H
20 /* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE, _Noreturn. */
21 #if !_GL_CONFIG_H_INCLUDED
22 #error "Please include config.h first."
23 #endif
25 #include "binary-io.h"
27 _GL_INLINE_HEADER_BEGIN
28 #ifndef XBINARY_IO_INLINE
29 # define XBINARY_IO_INLINE _GL_INLINE
30 #endif
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
37 #if O_BINARY
38 extern _Noreturn void xset_binary_mode_error (void);
39 #else
40 XBINARY_IO_INLINE void xset_binary_mode_error (void) {}
41 #endif
43 /* Set the mode of FD to MODE, which should be either O_TEXT or O_BINARY.
44 Report an error and exit if this fails. */
46 XBINARY_IO_INLINE void
47 xset_binary_mode (int fd, int mode)
49 if (set_binary_mode (fd, mode) < 0)
50 xset_binary_mode_error ();
54 #ifdef __cplusplus
56 #endif
58 _GL_INLINE_HEADER_END
60 #endif /* _XBINARY_IO_H */