New module 'freadptr'.
[gnulib.git] / lib / freadptr.c
1 /* Retrieve information about a FILE stream.
2    Copyright (C) 2007-2008 Free Software Foundation, Inc.
3
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.
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
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
16
17 #include <config.h>
18
19 /* Specification.  */
20 #include "freadahead.h"
21
22 const char *
23 freadptr (FILE *fp)
24 {
25   /* Keep this code in sync with freadahead!  */
26 #if defined _IO_ferror_unlocked     /* GNU libc, BeOS */
27   return (const char *) fp->_IO_read_ptr;
28 #elif defined __sferror             /* FreeBSD, NetBSD, OpenBSD, MacOS X, Cygwin */
29   return (const char *) fp->_p;
30 #elif defined _IOERR                /* AIX, HP-UX, IRIX, OSF/1, Solaris, mingw */
31 # if defined __sun && defined _LP64 /* Solaris/{SPARC,AMD64} 64-bit */
32 #  define fp_ ((struct { unsigned char *_ptr; \
33                          unsigned char *_base; \
34                          unsigned char *_end; \
35                          long _cnt; \
36                          int _file; \
37                          unsigned int _flag; \
38                        } *) fp)
39   return (const char *) fp_->_ptr;
40 # else
41   return (const char *) fp->_ptr;
42 # endif
43 #elif defined __UCLIBC__            /* uClibc */
44 # ifdef __STDIO_BUFFERS
45   return (const char *) fp->__bufpos;
46 # else
47   return NULL;
48 # endif
49 #elif defined __QNX__               /* QNX */
50   return (const char *) fp->_Next;
51 #else
52  #error "Please port gnulib freadptr.c to your platform! Look at the definition of getc, getc_unlocked on your system, then report this to bug-gnulib."
53 #endif
54 }