annotate lib/fbufmode.c @ 9928:9a02133ad731

Add tentative support for Linux libc5.
author Bruno Haible <bruno@clisp.org>
date Thu, 17 Apr 2008 02:01:23 +0200
parents e21211210418
children 2c1ba629f5d5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8691
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Retrieve information about a FILE stream.
9876
057a5220dfd5 Add tentative support for OpenServer.
Bruno Haible <bruno@clisp.org>
parents: 9456
diff changeset
2 Copyright (C) 2007-2008 Free Software Foundation, Inc.
8691
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9280
diff changeset
4 This program is free software: you can redistribute it and/or modify
8691
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9280
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9280
diff changeset
7 (at your option) any later version.
8691
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9280
diff changeset
14 You should have received a copy of the GNU General Public License
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9280
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8691
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 #include <config.h>
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 /* Specification. */
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #include "fbufmode.h"
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #if HAVE___FLBF
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 # include <stdio_ext.h>
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #endif
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 int
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 fbufmode (FILE *fp)
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 {
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 /* Most systems provide FILE as a struct and the necessary bitmask in
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 <stdio.h>, because they need it for implementing getc() and putc() as
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 fast macros. */
9928
9a02133ad731 Add tentative support for Linux libc5.
Bruno Haible <bruno@clisp.org>
parents: 9881
diff changeset
32 #if defined _IO_ferror_unlocked || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Linux libc5 */
8691
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 # if HAVE___FLBF /* glibc >= 2.2 */
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 if (__flbf (fp))
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 return _IOLBF;
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 # else
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 if (fp->_flags & _IO_LINE_BUF)
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 return _IOLBF;
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 # endif
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 if (fp->_flags & _IO_UNBUFFERED)
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 return _IONBF;
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 return _IOFBF;
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 #elif defined __sferror /* FreeBSD, NetBSD, OpenBSD, MacOS X, Cygwin */
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 if (fp->_flags & __SLBF)
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 return _IOLBF;
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 if (fp->_flags & __SNBF)
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 return _IONBF;
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 return _IOFBF;
9881
e21211210418 Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents: 9876
diff changeset
49 #elif defined __EMX__ /* emx+gcc */
e21211210418 Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents: 9876
diff changeset
50 return fp->_flags & (_IOLBF | _IONBF | _IOFBF);
9876
057a5220dfd5 Add tentative support for OpenServer.
Bruno Haible <bruno@clisp.org>
parents: 9456
diff changeset
51 #elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw */
8691
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 # if HAVE___FLBF /* Solaris >= 7 */
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 if (__flbf (fp))
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 return _IOLBF;
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 # else
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 if (fp->_flag & _IOLBF)
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 return _IOLBF;
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 # endif
9155
37e28ffbab9e Add tentative support for Solaris/AMD64.
Bruno Haible <bruno@clisp.org>
parents: 8926
diff changeset
59 # if defined __sun && defined _LP64 /* Solaris/{SPARC,AMD64} 64-bit */
37e28ffbab9e Add tentative support for Solaris/AMD64.
Bruno Haible <bruno@clisp.org>
parents: 8926
diff changeset
60 # define fp_ ((struct { unsigned char *_ptr; \
37e28ffbab9e Add tentative support for Solaris/AMD64.
Bruno Haible <bruno@clisp.org>
parents: 8926
diff changeset
61 unsigned char *_base; \
37e28ffbab9e Add tentative support for Solaris/AMD64.
Bruno Haible <bruno@clisp.org>
parents: 8926
diff changeset
62 unsigned char *_end; \
37e28ffbab9e Add tentative support for Solaris/AMD64.
Bruno Haible <bruno@clisp.org>
parents: 8926
diff changeset
63 long _cnt; \
37e28ffbab9e Add tentative support for Solaris/AMD64.
Bruno Haible <bruno@clisp.org>
parents: 8926
diff changeset
64 int _file; \
37e28ffbab9e Add tentative support for Solaris/AMD64.
Bruno Haible <bruno@clisp.org>
parents: 8926
diff changeset
65 unsigned int _flag; \
37e28ffbab9e Add tentative support for Solaris/AMD64.
Bruno Haible <bruno@clisp.org>
parents: 8926
diff changeset
66 } *) fp)
37e28ffbab9e Add tentative support for Solaris/AMD64.
Bruno Haible <bruno@clisp.org>
parents: 8926
diff changeset
67 return fp_->_flag & (_IONBF | _IOFBF);
8703
0f394f9a6ffe Port to Solaris/SPARC64.
Bruno Haible <bruno@clisp.org>
parents: 8691
diff changeset
68 # else
9876
057a5220dfd5 Add tentative support for OpenServer.
Bruno Haible <bruno@clisp.org>
parents: 9456
diff changeset
69 # if defined _SCO_DS /* OpenServer */
057a5220dfd5 Add tentative support for OpenServer.
Bruno Haible <bruno@clisp.org>
parents: 9456
diff changeset
70 # define _flag __flag
057a5220dfd5 Add tentative support for OpenServer.
Bruno Haible <bruno@clisp.org>
parents: 9456
diff changeset
71 # endif
8691
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 if (fp->_flag & _IONBF)
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 return _IONBF;
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 return _IOFBF;
8703
0f394f9a6ffe Port to Solaris/SPARC64.
Bruno Haible <bruno@clisp.org>
parents: 8691
diff changeset
75 # endif
8926
1d4c80b053f0 Add support for uClibc 0.9.29.
Bruno Haible <bruno@clisp.org>
parents: 8703
diff changeset
76 #elif defined __UCLIBC__ /* uClibc */
1d4c80b053f0 Add support for uClibc 0.9.29.
Bruno Haible <bruno@clisp.org>
parents: 8703
diff changeset
77 if (fp->__modeflags & __FLAG_LBF)
1d4c80b053f0 Add support for uClibc 0.9.29.
Bruno Haible <bruno@clisp.org>
parents: 8703
diff changeset
78 return _IOLBF;
1d4c80b053f0 Add support for uClibc 0.9.29.
Bruno Haible <bruno@clisp.org>
parents: 8703
diff changeset
79 if (fp->__modeflags & __FLAG_NBF)
1d4c80b053f0 Add support for uClibc 0.9.29.
Bruno Haible <bruno@clisp.org>
parents: 8703
diff changeset
80 return _IONBF;
1d4c80b053f0 Add support for uClibc 0.9.29.
Bruno Haible <bruno@clisp.org>
parents: 8703
diff changeset
81 return _IOFBF;
9280
a1f6fe4c68c1 Add support for QNX (untested).
Bruno Haible <bruno@clisp.org>
parents: 9155
diff changeset
82 #elif defined __QNX__ /* QNX */
9456
b3c8ee11ddfa Fix port to QNX.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
83 if (fp->_Mode & 0x400 /* _MLBF */)
9280
a1f6fe4c68c1 Add support for QNX (untested).
Bruno Haible <bruno@clisp.org>
parents: 9155
diff changeset
84 return _IOLBF;
9456
b3c8ee11ddfa Fix port to QNX.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
85 if (fp->_Mode & 0x800 /* _MNBF */)
9280
a1f6fe4c68c1 Add support for QNX (untested).
Bruno Haible <bruno@clisp.org>
parents: 9155
diff changeset
86 return _IONBF;
a1f6fe4c68c1 Add support for QNX (untested).
Bruno Haible <bruno@clisp.org>
parents: 9155
diff changeset
87 return _IOFBF;
8691
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 #else
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 #error "Please port gnulib fbufmode.c to your platform! Look at the setvbuf implementation."
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 #endif
fe35a667f2c8 New module 'fbufmode'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 }