annotate lib/freadptr.c @ 12559:c2cbabec01dd

update nearly all FSF copyright year lists to include 2010 Use the same procedure as for 2009, outlined in http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/20081
author Jim Meyering <meyering@redhat.com>
date Fri, 01 Jan 2010 10:31:12 +0100
parents d4475bf2a2bf
children 6fa9f46e6153
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9727
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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: 11236
diff changeset
2 Copyright (C) 2007-2010 Free Software Foundation, Inc.
9727
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 #include <config.h>
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 /* Specification. */
9779
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
20 #include "freadptr.h"
9727
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
9881
e21211210418 Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents: 9876
diff changeset
22 #include <stdlib.h>
e21211210418 Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents: 9876
diff changeset
23
9980
2c1ba629f5d5 New private include file lib/stdio-impl.h.
Bruno Haible <bruno@clisp.org>
parents: 9928
diff changeset
24 #include "stdio-impl.h"
2c1ba629f5d5 New private include file lib/stdio-impl.h.
Bruno Haible <bruno@clisp.org>
parents: 9928
diff changeset
25
9727
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 const char *
9779
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
27 freadptr (FILE *fp, size_t *sizep)
9727
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 {
9779
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
29 size_t size;
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
30
9727
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 /* Keep this code in sync with freadahead! */
10780
5c7a68d31801 Add support for Haiku.
Bruno Haible <bruno@clisp.org>
parents: 10404
diff changeset
32 #if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
9779
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
33 if (fp->_IO_write_ptr > fp->_IO_write_base)
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
34 return NULL;
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
35 size = fp->_IO_read_end - fp->_IO_read_ptr;
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
36 if (size == 0)
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
37 return NULL;
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
38 *sizep = size;
9727
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 return (const char *) fp->_IO_read_ptr;
9981
e3d6988a9347 Add tentative support for DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents: 9980
diff changeset
40 #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
41 if ((fp_->_flags & __SWR) != 0 || fp_->_r < 0)
9779
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
42 return NULL;
9981
e3d6988a9347 Add tentative support for DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents: 9980
diff changeset
43 size = fp_->_r;
9779
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
44 if (size == 0)
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
45 return NULL;
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
46 *sizep = size;
9981
e3d6988a9347 Add tentative support for DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents: 9980
diff changeset
47 return (const char *) fp_->_p;
9881
e21211210418 Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents: 9876
diff changeset
48 #elif defined __EMX__ /* emx+gcc */
e21211210418 Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents: 9876
diff changeset
49 if ((fp->_flags & _IOWRT) != 0)
e21211210418 Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents: 9876
diff changeset
50 return NULL;
e21211210418 Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents: 9876
diff changeset
51 /* 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
52 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
53 if (fp->_rcount <= 0)
e21211210418 Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents: 9876
diff changeset
54 return NULL;
9899
1e9793d6008a Fix mistake in EMX port.
Bruno Haible <bruno@clisp.org>
parents: 9881
diff changeset
55 if (!(fp->_ungetc_count == 0))
9881
e21211210418 Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents: 9876
diff changeset
56 abort ();
e21211210418 Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents: 9876
diff changeset
57 *sizep = fp->_rcount;
e21211210418 Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents: 9876
diff changeset
58 return fp->_ptr;
9876
057a5220dfd5 Add tentative support for OpenServer.
Bruno Haible <bruno@clisp.org>
parents: 9779
diff changeset
59 #elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw */
9779
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
60 if ((fp_->_flag & _IOWRT) != 0)
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
61 return NULL;
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
62 size = fp_->_cnt;
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
63 if (size == 0)
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
64 return NULL;
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
65 *sizep = size;
9727
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 return (const char *) fp_->_ptr;
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 #elif defined __UCLIBC__ /* uClibc */
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 # ifdef __STDIO_BUFFERS
9779
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
69 if (fp->__modeflags & __FLAG_WRITING)
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
70 return NULL;
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
71 size = fp->__bufread - fp->__bufpos;
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
72 if (size == 0)
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
73 return NULL;
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
74 *sizep = size;
9727
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 return (const char *) fp->__bufpos;
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 # else
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 return NULL;
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 # endif
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 #elif defined __QNX__ /* QNX */
9779
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
80 if ((fp->_Mode & 0x2000 /* _MWRITE */) != 0)
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
81 return NULL;
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
82 /* fp->_Buf <= fp->_Next <= fp->_Rend */
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
83 size = fp->_Rend - fp->_Next;
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
84 if (size == 0)
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
85 return NULL;
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
86 *sizep = size;
9727
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 return (const char *) fp->_Next;
11236
d4475bf2a2bf Add tentative support for FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents: 10780
diff changeset
88 #elif defined __MINT__ /* Atari FreeMiNT */
d4475bf2a2bf Add tentative support for FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents: 10780
diff changeset
89 if (!fp->__mode.__read)
d4475bf2a2bf Add tentative support for FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents: 10780
diff changeset
90 return NULL;
d4475bf2a2bf Add tentative support for FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents: 10780
diff changeset
91 size = fp->__get_limit - fp->__bufp;
d4475bf2a2bf Add tentative support for FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents: 10780
diff changeset
92 if (size == 0)
d4475bf2a2bf Add tentative support for FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents: 10780
diff changeset
93 return NULL;
d4475bf2a2bf Add tentative support for FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents: 10780
diff changeset
94 *sizep = size;
d4475bf2a2bf Add tentative support for FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents: 10780
diff changeset
95 return fp->__bufp;
10404
4611578c5669 Add conditional code for SLOW_BUT_NO_HACKS.
Bruno Haible <bruno@clisp.org>
parents: 9981
diff changeset
96 #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: 9981
diff changeset
97 /* This implementation is correct on any ANSI C platform. It is just
4611578c5669 Add conditional code for SLOW_BUT_NO_HACKS.
Bruno Haible <bruno@clisp.org>
parents: 9981
diff changeset
98 awfully slow. */
4611578c5669 Add conditional code for SLOW_BUT_NO_HACKS.
Bruno Haible <bruno@clisp.org>
parents: 9981
diff changeset
99 return NULL;
9727
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 #else
9779
569a44f4dd4d Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents: 9727
diff changeset
101 #error "Please port gnulib freadptr.c to your platform! Look at the definition of fflush, fread, getc, getc_unlocked on your system, then report this to bug-gnulib."
9727
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 #endif
7c1260f0aac3 New module 'freadptr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 }