1 /* Retrieve information about a FILE stream.
2 Copyright (C) 2007-2025 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/>. */
24 # include <stdio_ext.h>
28 #include "stdio-impl.h"
33 /* Most systems provide FILE as a struct and the necessary bitmask in
34 <stdio.h>, because they need it for implementing getc() and putc() as
36 #if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1
37 /* GNU libc, BeOS, Haiku, Linux libc5 */
38 # if HAVE___FLBF /* glibc >= 2.2 */
42 if (fp
->_flags
& _IO_LINE_BUF
)
45 if (fp
->_flags
& _IO_UNBUFFERED
)
48 #elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
49 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
50 if (fp_
->_flags
& __SLBF
)
52 if (fp_
->_flags
& __SNBF
)
55 #elif defined __EMX__ /* emx+gcc */
56 return fp
->_flags
& (_IOLBF
| _IONBF
| _IOFBF
);
57 #elif defined __minix /* Minix */
58 return fp
->_flags
& (_IOLBF
| _IONBF
| _IOFBF
);
59 #elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, UnixWare, mingw, MSVC, NonStop Kernel, OpenVMS */
60 # if defined WINDOWS_OPAQUE_FILE
61 if (fp_
->_flag
& 0x100)
62 return _IOFBF
; /* Impossible to distinguish _IOFBF and _IOLBF. */
66 # if HAVE___FLBF /* Solaris >= 7 */
70 if (fp_
->_flag
& _IOLBF
)
73 if (fp_
->_flag
& _IONBF
)
77 #elif defined __UCLIBC__ /* uClibc */
78 if (fp
->__modeflags
& __FLAG_LBF
)
80 if (fp
->__modeflags
& __FLAG_NBF
)
83 #elif defined __QNX__ /* QNX */
84 if (fp
->_Mode
& 0x400 /* _MLBF */)
86 if (fp
->_Mode
& 0x800 /* _MNBF */)
89 #elif defined __MINT__ /* Atari FreeMiNT */
92 return (fp
->__bufsize
> 0 ? _IOFBF
: _IONBF
);
93 #elif HAVE___FLBF && HAVE___FBUFSIZE /* musl libc */
96 return (__fbufsize (fp
) > 0 ? _IOFBF
: _IONBF
);
97 #elif defined EPLAN9 /* Plan9 */
98 if (fp
->flags
& 2 /* LINEBUF */)
104 # error "Please port gnulib fbufmode.c to your platform! Look at the setvbuf implementation."