Mercurial > hg > octave-lojdl > gnulib-hg
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 |
rev | line source |
---|---|
8691 | 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 | 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 | 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 | 8 |
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. | |
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 | 16 |
17 #include <config.h> | |
18 | |
19 /* Specification. */ | |
20 #include "fbufmode.h" | |
21 | |
22 #if HAVE___FLBF | |
23 # include <stdio_ext.h> | |
24 #endif | |
25 | |
26 int | |
27 fbufmode (FILE *fp) | |
28 { | |
29 /* Most systems provide FILE as a struct and the necessary bitmask in | |
30 <stdio.h>, because they need it for implementing getc() and putc() as | |
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 | 33 # if HAVE___FLBF /* glibc >= 2.2 */ |
34 if (__flbf (fp)) | |
35 return _IOLBF; | |
36 # else | |
37 if (fp->_flags & _IO_LINE_BUF) | |
38 return _IOLBF; | |
39 # endif | |
40 if (fp->_flags & _IO_UNBUFFERED) | |
41 return _IONBF; | |
42 return _IOFBF; | |
43 #elif defined __sferror /* FreeBSD, NetBSD, OpenBSD, MacOS X, Cygwin */ | |
44 if (fp->_flags & __SLBF) | |
45 return _IOLBF; | |
46 if (fp->_flags & __SNBF) | |
47 return _IONBF; | |
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 | 52 # if HAVE___FLBF /* Solaris >= 7 */ |
53 if (__flbf (fp)) | |
54 return _IOLBF; | |
55 # else | |
56 if (fp->_flag & _IOLBF) | |
57 return _IOLBF; | |
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 | 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 | 72 if (fp->_flag & _IONBF) |
73 return _IONBF; | |
74 return _IOFBF; | |
8703 | 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 | 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 | 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 | 88 #else |
89 #error "Please port gnulib fbufmode.c to your platform! Look at the setvbuf implementation." | |
90 #endif | |
91 } |