/* Specification. */
#include "freadptr.h"
+#include <stdlib.h>
+
const char *
freadptr (FILE *fp, size_t *sizep)
{
size_t size;
/* Keep this code in sync with freadahead! */
-#if defined _IO_ferror_unlocked /* GNU libc, BeOS */
+#if defined _IO_ferror_unlocked || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Linux libc5 */
if (fp->_IO_write_ptr > fp->_IO_write_base)
return NULL;
size = fp->_IO_read_end - fp->_IO_read_ptr;
return NULL;
*sizep = size;
return (const char *) fp->_p;
-#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, mingw */
+#elif defined __EMX__ /* emx+gcc */
+ if ((fp->_flags & _IOWRT) != 0)
+ return NULL;
+ /* Note: fp->_ungetc_count > 0 implies fp->_rcount <= 0,
+ fp->_ungetc_count = 0 implies fp->_rcount >= 0. */
+ if (fp->_rcount <= 0)
+ return NULL;
+ if (!(fp->_ungetc_count == 0))
+ abort ();
+ *sizep = fp->_rcount;
+ return fp->_ptr;
+#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw */
# if defined __sun && defined _LP64 /* Solaris/{SPARC,AMD64} 64-bit */
# define fp_ ((struct { unsigned char *_ptr; \
unsigned char *_base; \
*sizep = size;
return (const char *) fp_->_ptr;
# else
+# if defined _SCO_DS /* OpenServer */
+# define _flag __flag
+# define _ptr __ptr
+# define _cnt __cnt
+# endif
if ((fp->_flag & _IOWRT) != 0)
return NULL;
size = fp->_cnt;