Mercurial > hg > octave-jordi > gnulib-hg
annotate lib/freadahead.c @ 13997:6fa9f46e6153
Port extended stdio modules to HP NonStop Kernel.
* lib/stdio-impl.h (_IOERR, _IOREAD, _IOWRT, _IORW) [__TANDEM]: New
macros.
* lib/fbufmode.c: Update comments.
* lib/fflush.c: Likewise.
* lib/fpurge.c: Likewise.
* lib/freadable.c: Likewise.
* lib/freadahead.c: Likewise.
* lib/freading.c: Likewise.
* lib/freadptr.c: Likewise.
* lib/freadseek.c: Likewise.
* lib/fseeko.c: Likewise.
* lib/fseterr.c: Likewise.
* lib/fwritable.c: Likewise.
* lib/fwriting.c: Likewise.
Reported by Joachim Schmitz <jojo@schmitz-digital.de>.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Wed, 22 Dec 2010 17:37:34 +0100 |
parents | c2cbabec01dd |
children | 97fc9a21a8fb |
rev | line source |
---|---|
9158 | 1 /* Retrieve information about a FILE stream. |
12559
c2cbabec01dd
update nearly all FSF copyright year lists to include 2010
Jim Meyering <meyering@redhat.com>
parents:
12421
diff
changeset
|
2 Copyright (C) 2007-2010 Free Software Foundation, Inc. |
9158 | 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 |
9158 | 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. |
9158 | 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/>. */ |
9158 | 16 |
17 #include <config.h> | |
18 | |
19 /* Specification. */ | |
20 #include "freadahead.h" | |
21 | |
10404
4611578c5669
Add conditional code for SLOW_BUT_NO_HACKS.
Bruno Haible <bruno@clisp.org>
parents:
10140
diff
changeset
|
22 #include <stdlib.h> |
9980
2c1ba629f5d5
New private include file lib/stdio-impl.h.
Bruno Haible <bruno@clisp.org>
parents:
9978
diff
changeset
|
23 #include "stdio-impl.h" |
2c1ba629f5d5
New private include file lib/stdio-impl.h.
Bruno Haible <bruno@clisp.org>
parents:
9978
diff
changeset
|
24 |
9158 | 25 size_t |
26 freadahead (FILE *fp) | |
27 { | |
10780 | 28 #if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ |
9158 | 29 if (fp->_IO_write_ptr > fp->_IO_write_base) |
30 return 0; | |
9780
cf325a112b9d
Take into account the number of pushed-back bytes (ungetc).
Bruno Haible <bruno@clisp.org>
parents:
9456
diff
changeset
|
31 return (fp->_IO_read_end - fp->_IO_read_ptr) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11236
diff
changeset
|
32 + (fp->_flags & _IO_IN_BACKUP ? fp->_IO_save_end - fp->_IO_save_base : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11236
diff
changeset
|
33 0); |
9981
e3d6988a9347
Add tentative support for DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9980
diff
changeset
|
34 #elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */ |
e3d6988a9347
Add tentative support for DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9980
diff
changeset
|
35 if ((fp_->_flags & __SWR) != 0 || fp_->_r < 0) |
9158 | 36 return 0; |
10140
879d77289ca0
Use special-purpose function in DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9981
diff
changeset
|
37 # if defined __DragonFly__ |
879d77289ca0
Use special-purpose function in DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9981
diff
changeset
|
38 return __sreadahead (fp); |
879d77289ca0
Use special-purpose function in DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9981
diff
changeset
|
39 # else |
9981
e3d6988a9347
Add tentative support for DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9980
diff
changeset
|
40 return fp_->_r |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11236
diff
changeset
|
41 + (HASUB (fp) ? fp_->_ur : 0); |
10140
879d77289ca0
Use special-purpose function in DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9981
diff
changeset
|
42 # endif |
9881
e21211210418
Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents:
9876
diff
changeset
|
43 #elif defined __EMX__ /* emx+gcc */ |
e21211210418
Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents:
9876
diff
changeset
|
44 if ((fp->_flags & _IOWRT) != 0) |
e21211210418
Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents:
9876
diff
changeset
|
45 return 0; |
e21211210418
Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents:
9876
diff
changeset
|
46 /* Note: fp->_ungetc_count > 0 implies fp->_rcount <= 0, |
e21211210418
Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents:
9876
diff
changeset
|
47 fp->_ungetc_count = 0 implies fp->_rcount >= 0. */ |
e21211210418
Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents:
9876
diff
changeset
|
48 /* equivalent to |
e21211210418
Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents:
9876
diff
changeset
|
49 (fp->_ungetc_count == 0 ? fp->_rcount : fp->_ungetc_count - fp->_rcount) */ |
e21211210418
Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents:
9876
diff
changeset
|
50 return (fp->_rcount > 0 ? fp->_rcount : fp->_ungetc_count - fp->_rcount); |
13997
6fa9f46e6153
Port extended stdio modules to HP NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
51 #elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */ |
9158 | 52 if ((fp_->_flag & _IOWRT) != 0) |
53 return 0; | |
54 return fp_->_cnt; | |
55 #elif defined __UCLIBC__ /* uClibc */ | |
56 # ifdef __STDIO_BUFFERS | |
57 if (fp->__modeflags & __FLAG_WRITING) | |
58 return 0; | |
9780
cf325a112b9d
Take into account the number of pushed-back bytes (ungetc).
Bruno Haible <bruno@clisp.org>
parents:
9456
diff
changeset
|
59 return (fp->__bufread - fp->__bufpos) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11236
diff
changeset
|
60 + (fp->__modeflags & __FLAG_UNGOT ? 1 : 0); |
9158 | 61 # else |
62 return 0; | |
63 # endif | |
9280
a1f6fe4c68c1
Add support for QNX (untested).
Bruno Haible <bruno@clisp.org>
parents:
9158
diff
changeset
|
64 #elif defined __QNX__ /* QNX */ |
9456 | 65 if ((fp->_Mode & 0x2000 /* _MWRITE */) != 0) |
9280
a1f6fe4c68c1
Add support for QNX (untested).
Bruno Haible <bruno@clisp.org>
parents:
9158
diff
changeset
|
66 return 0; |
9780
cf325a112b9d
Take into account the number of pushed-back bytes (ungetc).
Bruno Haible <bruno@clisp.org>
parents:
9456
diff
changeset
|
67 /* fp->_Buf <= fp->_Next <= fp->_Rend, |
cf325a112b9d
Take into account the number of pushed-back bytes (ungetc).
Bruno Haible <bruno@clisp.org>
parents:
9456
diff
changeset
|
68 and fp->_Rend may be overridden by fp->_Rsave. */ |
cf325a112b9d
Take into account the number of pushed-back bytes (ungetc).
Bruno Haible <bruno@clisp.org>
parents:
9456
diff
changeset
|
69 return ((fp->_Rsave ? fp->_Rsave : fp->_Rend) - fp->_Next) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11236
diff
changeset
|
70 + (fp->_Mode & 0x4000 /* _MBYTE */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11236
diff
changeset
|
71 ? (fp->_Back + sizeof (fp->_Back)) - fp->_Rback |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11236
diff
changeset
|
72 : 0); |
11236
d4475bf2a2bf
Add tentative support for FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents:
10780
diff
changeset
|
73 #elif defined __MINT__ /* Atari FreeMiNT */ |
d4475bf2a2bf
Add tentative support for FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents:
10780
diff
changeset
|
74 if (!fp->__mode.__read) |
d4475bf2a2bf
Add tentative support for FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents:
10780
diff
changeset
|
75 return 0; |
d4475bf2a2bf
Add tentative support for FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents:
10780
diff
changeset
|
76 return (fp->__pushed_back |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11236
diff
changeset
|
77 ? fp->__get_limit - fp->__pushback_bufp + 1 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11236
diff
changeset
|
78 : fp->__get_limit - fp->__bufp); |
10404
4611578c5669
Add conditional code for SLOW_BUT_NO_HACKS.
Bruno Haible <bruno@clisp.org>
parents:
10140
diff
changeset
|
79 #elif defined SLOW_BUT_NO_HACKS /* users can define this */ |
4611578c5669
Add conditional code for SLOW_BUT_NO_HACKS.
Bruno Haible <bruno@clisp.org>
parents:
10140
diff
changeset
|
80 abort (); |
4611578c5669
Add conditional code for SLOW_BUT_NO_HACKS.
Bruno Haible <bruno@clisp.org>
parents:
10140
diff
changeset
|
81 return 0; |
9158 | 82 #else |
9780
cf325a112b9d
Take into account the number of pushed-back bytes (ungetc).
Bruno Haible <bruno@clisp.org>
parents:
9456
diff
changeset
|
83 #error "Please port gnulib freadahead.c to your platform! Look at the definition of fflush, fread, ungetc on your system, then report this to bug-gnulib." |
9158 | 84 #endif |
85 } |