af_alg: Improve comments.
[gnulib.git] / lib / fbufmode.c
blob73c64f3487a1e0e207664354492a116d45281a50
1 /* Retrieve information about a FILE stream.
2 Copyright (C) 2007-2018 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program 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 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 #include <config.h>
19 /* Specification. */
20 #include "fbufmode.h"
22 #if HAVE___FLBF
23 # include <stdio_ext.h>
24 #endif
26 #include "stdio-impl.h"
28 int
29 fbufmode (FILE *fp)
31 /* Most systems provide FILE as a struct and the necessary bitmask in
32 <stdio.h>, because they need it for implementing getc() and putc() as
33 fast macros. */
34 #if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1
35 /* GNU libc, BeOS, Haiku, Linux libc5 */
36 # if HAVE___FLBF /* glibc >= 2.2 */
37 if (__flbf (fp))
38 return _IOLBF;
39 # else
40 if (fp->_flags & _IO_LINE_BUF)
41 return _IOLBF;
42 # endif
43 if (fp->_flags & _IO_UNBUFFERED)
44 return _IONBF;
45 return _IOFBF;
46 #elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
47 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
48 if (fp_->_flags & __SLBF)
49 return _IOLBF;
50 if (fp_->_flags & __SNBF)
51 return _IONBF;
52 return _IOFBF;
53 #elif defined __EMX__ /* emx+gcc */
54 return fp->_flags & (_IOLBF | _IONBF | _IOFBF);
55 #elif defined __minix /* Minix */
56 return fp->_flags & (_IOLBF | _IONBF | _IOFBF);
57 #elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, MSVC, NonStop Kernel, OpenVMS */
58 # if defined WINDOWS_OPAQUE_FILE
59 if (fp_->_flag & 0x100)
60 return _IOFBF; /* Impossible to distinguish _IOFBF and _IOLBF. */
61 else
62 return _IONBF;
63 # else
64 # if HAVE___FLBF /* Solaris >= 7 */
65 if (__flbf (fp))
66 return _IOLBF;
67 # else
68 if (fp_->_flag & _IOLBF)
69 return _IOLBF;
70 # endif
71 if (fp_->_flag & _IONBF)
72 return _IONBF;
73 return _IOFBF;
74 # endif
75 #elif defined __UCLIBC__ /* uClibc */
76 if (fp->__modeflags & __FLAG_LBF)
77 return _IOLBF;
78 if (fp->__modeflags & __FLAG_NBF)
79 return _IONBF;
80 return _IOFBF;
81 #elif defined __QNX__ /* QNX */
82 if (fp->_Mode & 0x400 /* _MLBF */)
83 return _IOLBF;
84 if (fp->_Mode & 0x800 /* _MNBF */)
85 return _IONBF;
86 return _IOFBF;
87 #elif defined __MINT__ /* Atari FreeMiNT */
88 if (fp->__linebuf)
89 return _IOLBF;
90 return (fp->__bufsize > 0 ? _IOFBF : _IONBF);
91 #elif HAVE___FLBF && HAVE___FBUFSIZE /* musl libc */
92 if (__flbf (fp))
93 return _IOLBF;
94 return (__fbufsize (fp) > 0 ? _IOFBF : _IONBF);
95 #elif defined EPLAN9 /* Plan9 */
96 if (fp->flags & 2 /* LINEBUF */)
97 return _IOLBF;
98 if (fp->bufl)
99 return _IOFBF;
100 return _IONBF;
101 #else
102 # error "Please port gnulib fbufmode.c to your platform! Look at the setvbuf implementation."
103 #endif