1
0
mirror of https://https.git.savannah.gnu.org/git/gnulib.git synced 2026-09-01 02:34:55 +00:00

New private include file lib/stdio-impl.h.

This commit is contained in:
Bruno Haible
2008-04-26 18:12:05 +02:00
parent 0bdd1c6888
commit 569eba622c
25 changed files with 77 additions and 155 deletions
+40
View File
@@ -1,3 +1,43 @@
2008-04-26 Bruno Haible <bruno@clisp.org>
* lib/stdio-impl.h: New file.
* lib/fbufmode.c: Include stdio-impl.h.
(fbufmode): Use fp_, remove redundant #defines.
* lib/fflush.c: Include stdio-impl.h.
(clear_ungetc_buffer): Remove redundant #defines.
* lib/fpurge.c: Include stdio-impl.h.
(fpurge): Remove redundant #defines.
* lib/freadable.c: Include stdio-impl.h.
(freadable): Remove redundant #defines.
* lib/freadahead.c: Include stdio-impl.h.
(freadahead): Remove redundant #defines.
* lib/freading.c: Include stdio-impl.h.
(freading): Remove redundant #defines.
* lib/freadptr.c: Include stdio-impl.h.
(freadptr): Remove redundant #defines.
* lib/freadseek.c: Include stdio-impl.h.
(freadptrinc): Remove redundant #defines.
* lib/fseeko.c: Include stdio-impl.h.
(rpl_fseeko): Remove redundant #defines.
* lib/fseterr.c: Include stdio-impl.h.
(fseterr): Remove redundant #defines.
* lib/fwritable.c: Include stdio-impl.h.
(fwritable: Remove redundant #defines.
* lib/fwriting.c: Include stdio-impl.h.
(fwriting): Remove redundant #defines.
* modules/fbufmode (Files): Add lib/stdio-impl.h.
* modules/fflush (Files): Likewise.
* modules/fpurge (Files): Likewise.
* modules/freadable (Files): Likewise.
* modules/freadahead (Files): Likewise.
* modules/freading (Files): Likewise.
* modules/freadptr (Files): Likewise.
* modules/freadseek (Files): Likewise.
* modules/fseeko (Files): Likewise.
* modules/fseterr (Files): Likewise.
* modules/fwritable (Files): Likewise.
* modules/fwriting (Files): Likewise.
2008-04-26 Bruno Haible <bruno@clisp.org>
* lib/fflush.c (clear_ungetc_buffer, disable_seek_optimization,
+3 -15
View File
@@ -23,6 +23,8 @@
# include <stdio_ext.h>
#endif
#include "stdio-impl.h"
int
fbufmode (FILE *fp)
{
@@ -56,23 +58,9 @@ fbufmode (FILE *fp)
if (fp->_flag & _IOLBF)
return _IOLBF;
# endif
# if defined __sun && defined _LP64 /* Solaris/{SPARC,AMD64} 64-bit */
# define fp_ ((struct { unsigned char *_ptr; \
unsigned char *_base; \
unsigned char *_end; \
long _cnt; \
int _file; \
unsigned int _flag; \
} *) fp)
return fp_->_flag & (_IONBF | _IOFBF);
# else
# if defined _SCO_DS /* OpenServer */
# define _flag __flag
# endif
if (fp->_flag & _IONBF)
if (fp_->_flag & _IONBF)
return _IONBF;
return _IOFBF;
# endif
#elif defined __UCLIBC__ /* uClibc */
if (fp->__modeflags & __FLAG_LBF)
return _IOLBF;
+2 -10
View File
@@ -27,22 +27,14 @@
#include "freading.h"
#include "fpurge.h"
#include "stdio-impl.h"
#undef fflush
static inline void
clear_ungetc_buffer (FILE *fp)
{
#if defined __sferror /* FreeBSD, NetBSD, OpenBSD, MacOS X, Cygwin */
# if defined __NetBSD__ || defined __OpenBSD__
struct __sfileext
{
struct __sbuf _ub; /* ungetc buffer */
/* More fields, not relevant here. */
};
# define HASUB(fp) (((struct __sfileext *) (fp)->_ext._base)->_ub._base != NULL)
# else
# define HASUB(fp) ((fp)->_ub._base != NULL)
# endif
if (HASUB (fp))
{
fp->_p += stream->_r;
+2 -12
View File
@@ -24,6 +24,8 @@
#endif
#include <stdlib.h>
#include "stdio-impl.h"
int
fpurge (FILE *fp)
{
@@ -76,13 +78,6 @@ fpurge (FILE *fp)
? fp->_bf._size
: 0);
/* Avoid memory leak when there is an active ungetc buffer. */
# if defined __NetBSD__ || defined __OpenBSD__ /* NetBSD, OpenBSD */
/* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
and <http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> */
# define fp_ub ((struct { struct __sbuf _ub; } *) fp->_ext._base)->_ub
# else /* FreeBSD, MacOS X, Cygwin */
# define fp_ub fp->_ub
# endif
if (fp_ub._base != NULL)
{
if (fp_ub._base != fp->_ubuf)
@@ -97,11 +92,6 @@ fpurge (FILE *fp)
fp->_ungetc_count = 0;
return 0;
# elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw */
# if defined _SCO_DS /* OpenServer */
# define _base __base
# define _ptr __ptr
# define _cnt __cnt
# endif
fp->_ptr = fp->_base;
if (fp->_ptr != NULL)
fp->_cnt = 0;
+2 -3
View File
@@ -19,6 +19,8 @@
/* Specification. */
#include "freadable.h"
#include "stdio-impl.h"
bool
freadable (FILE *fp)
{
@@ -32,9 +34,6 @@ freadable (FILE *fp)
#elif defined __EMX__ /* emx+gcc */
return (fp->_flags & (_IORW | _IOREAD)) != 0;
#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw */
# if defined _SCO_DS /* OpenServer */
# define _flag __flag
# endif
return (fp->_flag & (_IORW | _IOREAD)) != 0;
#elif defined __QNX__ /* QNX */
return (fp->_Mode & 0x1 /* _MOPENR */) != 0;
+2 -27
View File
@@ -19,6 +19,8 @@
/* Specification. */
#include "freadahead.h"
#include "stdio-impl.h"
size_t
freadahead (FILE *fp)
{
@@ -29,16 +31,6 @@ freadahead (FILE *fp)
+ (fp->_flags & _IO_IN_BACKUP ? fp->_IO_save_end - fp->_IO_save_base :
0);
#elif defined __sferror /* FreeBSD, NetBSD, OpenBSD, MacOS X, Cygwin */
# if defined __NetBSD__ || defined __OpenBSD__
struct __sfileext
{
struct __sbuf _ub; /* ungetc buffer */
/* More fields, not relevant here. */
};
# define HASUB(fp) (((struct __sfileext *) (fp)->_ext._base)->_ub._base != NULL)
# else
# define HASUB(fp) ((fp)->_ub._base != NULL)
# endif
if ((fp->_flags & __SWR) != 0 || fp->_r < 0)
return 0;
return fp->_r
@@ -52,26 +44,9 @@ freadahead (FILE *fp)
(fp->_ungetc_count == 0 ? fp->_rcount : fp->_ungetc_count - fp->_rcount) */
return (fp->_rcount > 0 ? fp->_rcount : fp->_ungetc_count - fp->_rcount);
#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; \
unsigned char *_end; \
long _cnt; \
int _file; \
unsigned int _flag; \
} *) fp)
if ((fp_->_flag & _IOWRT) != 0)
return 0;
return fp_->_cnt;
# else
# if defined _SCO_DS /* OpenServer */
# define _flag __flag
# define _cnt __cnt
# endif
if ((fp->_flag & _IOWRT) != 0)
return 0;
return fp->_cnt;
# endif
#elif defined __UCLIBC__ /* uClibc */
# ifdef __STDIO_BUFFERS
if (fp->__modeflags & __FLAG_WRITING)
+2 -3
View File
@@ -19,6 +19,8 @@
/* Specification. */
#include "freading.h"
#include "stdio-impl.h"
/* Don't use glibc's __freading function in glibc < 2.7, see
<http://sourceware.org/bugzilla/show_bug.cgi?id=4359> */
#if !(HAVE___FREADING && (!defined __GLIBC__ || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)))
@@ -38,9 +40,6 @@ freading (FILE *fp)
#elif defined __EMX__ /* emx+gcc */
return (fp->_flags & _IOREAD) != 0;
#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw */
# if defined _SCO_DS /* OpenServer */
# define _flag __flag
# endif
return (fp->_flag & _IOREAD) != 0;
#elif defined __UCLIBC__ /* uClibc */
return (fp->__modeflags & (__FLAG_READONLY | __FLAG_READING)) != 0;
+2 -22
View File
@@ -21,6 +21,8 @@
#include <stdlib.h>
#include "stdio-impl.h"
const char *
freadptr (FILE *fp, size_t *sizep)
{
@@ -55,14 +57,6 @@ freadptr (FILE *fp, size_t *sizep)
*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; \
unsigned char *_end; \
long _cnt; \
int _file; \
unsigned int _flag; \
} *) fp)
if ((fp_->_flag & _IOWRT) != 0)
return NULL;
size = fp_->_cnt;
@@ -70,20 +64,6 @@ freadptr (FILE *fp, size_t *sizep)
return NULL;
*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;
if (size == 0)
return NULL;
*sizep = size;
return (const char *) fp->_ptr;
# endif
#elif defined __UCLIBC__ /* uClibc */
# ifdef __STDIO_BUFFERS
if (fp->__modeflags & __FLAG_WRITING)
+2 -16
View File
@@ -25,6 +25,8 @@
#include "freadahead.h"
#include "freadptr.h"
#include "stdio-impl.h"
/* Increment the in-memory pointer. INCREMENT must be at most the buffer size
returned by freadptr().
This is very cheap (no system calls). */
@@ -41,24 +43,8 @@ freadptrinc (FILE *fp, size_t increment)
fp->_ptr += increment;
fp->_rcount -= increment;
#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; \
unsigned char *_end; \
long _cnt; \
int _file; \
unsigned int _flag; \
} *) fp)
fp_->_ptr += increment;
fp_->_cnt -= increment;
# else
# if defined _SCO_DS /* OpenServer */
# define _ptr __ptr
# define _cnt __cnt
# endif
fp->_ptr += increment;
fp->_cnt -= increment;
# endif
#elif defined __UCLIBC__ /* uClibc */
# ifdef __STDIO_BUFFERS
fp->__bufpos += increment;
+2 -27
View File
@@ -23,6 +23,8 @@
/* Get off_t and lseek. */
#include <unistd.h>
#include "stdio-impl.h"
#undef fseeko
#if !HAVE_FSEEKO
# undef fseek
@@ -44,13 +46,6 @@ rpl_fseeko (FILE *fp, off_t offset, int whence)
&& fp->_IO_write_ptr == fp->_IO_write_base
&& fp->_IO_save_base == NULL)
#elif defined __sferror /* FreeBSD, NetBSD, OpenBSD, MacOS X, Cygwin */
# if defined __NetBSD__ || defined __OpenBSD__ /* NetBSD, OpenBSD */
/* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
and <http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> */
# define fp_ub ((struct { struct __sbuf _ub; } *) fp->_ext._base)->_ub
# else /* FreeBSD, MacOS X, Cygwin */
# define fp_ub fp->_ub
# endif
# if defined __SL64 && defined __SCLE /* Cygwin */
if ((fp->_flags & __SL64) == 0)
{
@@ -76,25 +71,8 @@ rpl_fseeko (FILE *fp, off_t offset, int whence)
&& fp->_wcount == 0
&& fp->_ungetc_count == 0)
#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; \
unsigned char *_end; \
long _cnt; \
int _file; \
unsigned int _flag; \
} *) fp)
if (fp_->_ptr == fp_->_base
&& (fp_->_ptr == NULL || fp_->_cnt == 0))
# else
# if defined _SCO_DS /* OpenServer */
# define _base __base
# define _ptr __ptr
# define _cnt __cnt
# endif
if (fp->_ptr == fp->_base
&& (fp->_ptr == NULL || fp->_cnt == 0))
# endif
#elif defined __UCLIBC__ /* uClibc */
if (((fp->__modeflags & __FLAG_WRITING) == 0
|| fp->__bufpos == fp->__bufstart)
@@ -125,9 +103,6 @@ rpl_fseeko (FILE *fp, off_t offset, int whence)
#elif defined __EMX__ /* emx+gcc */
fp->_flags &= ~_IOEOF;
#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw */
# if defined _SCO_DS /* OpenServer */
# define _flag __flag
# endif
fp->_flag &= ~_IOEOF;
#endif
return 0;
+2 -14
View File
@@ -21,6 +21,8 @@
#include <errno.h>
#include "stdio-impl.h"
void
fseterr (FILE *fp)
{
@@ -34,21 +36,7 @@ fseterr (FILE *fp)
#elif defined __EMX__ /* emx+gcc */
fp->_flags |= _IOERR;
#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; \
unsigned char *_end; \
long _cnt; \
int _file; \
unsigned int _flag; \
} *) fp)
fp_->_flag |= _IOERR;
# else
# if defined _SCO_DS /* OpenServer */
# define _flag __flag
# endif
fp->_flag |= _IOERR;
# endif
#elif defined __UCLIBC__ /* uClibc */
fp->__modeflags |= __FLAG_ERROR;
#elif defined __QNX__ /* QNX */
+2 -3
View File
@@ -19,6 +19,8 @@
/* Specification. */
#include "fwritable.h"
#include "stdio-impl.h"
bool
fwritable (FILE *fp)
{
@@ -32,9 +34,6 @@ fwritable (FILE *fp)
#elif defined __EMX__ /* emx+gcc */
return (fp->_flags & (_IORW | _IOWRT)) != 0;
#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw */
# if defined _SCO_DS /* OpenServer */
# define _flag __flag
# endif
return (fp->_flag & (_IORW | _IOWRT)) != 0;
#elif defined __QNX__ /* QNX */
return (fp->_Mode & 0x2 /* _MOPENW */) != 0;
+2 -3
View File
@@ -19,6 +19,8 @@
/* Specification. */
#include "fwriting.h"
#include "stdio-impl.h"
bool
fwriting (FILE *fp)
{
@@ -32,9 +34,6 @@ fwriting (FILE *fp)
#elif defined __EMX__ /* emx+gcc */
return (fp->_flags & _IOWRT) != 0;
#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw */
# if defined _SCO_DS /* OpenServer */
# define _flag __flag
# endif
return (fp->_flag & _IOWRT) != 0;
#elif defined __UCLIBC__ /* uClibc */
return (fp->__modeflags & __FLAG_WRITING) != 0;
+1
View File
@@ -4,6 +4,7 @@ fbufmode() function: Determine the buffering mode of a FILE stream.
Files:
lib/fbufmode.h
lib/fbufmode.c
lib/stdio-impl.h
m4/fbufmode.m4
Depends-on:
+1
View File
@@ -3,6 +3,7 @@ Discard pending data on both input and output streams.
Files:
lib/fflush.c
lib/stdio-impl.h
m4/fflush.m4
Depends-on:
+1
View File
@@ -4,6 +4,7 @@ fpurge() function: Flush buffers.
Files:
lib/fpurge.h
lib/fpurge.c
lib/stdio-impl.h
m4/fpurge.m4
Depends-on:
+1
View File
@@ -4,6 +4,7 @@ freadable() function: Determine whether a FILE stream supports reading.
Files:
lib/freadable.h
lib/freadable.c
lib/stdio-impl.h
m4/freadable.m4
Depends-on:
+1
View File
@@ -5,6 +5,7 @@ buffer of a stream.
Files:
lib/freadahead.h
lib/freadahead.c
lib/stdio-impl.h
Depends-on:
+1
View File
@@ -4,6 +4,7 @@ freading() function: Determine whether a FILE stream is currently doing reading.
Files:
lib/freading.h
lib/freading.c
lib/stdio-impl.h
m4/freading.m4
Depends-on:
+1
View File
@@ -4,6 +4,7 @@ freadptr() function: Pointer to the input buffer of a stream.
Files:
lib/freadptr.h
lib/freadptr.c
lib/stdio-impl.h
Depends-on:
+1
View File
@@ -4,6 +4,7 @@ freadseek() function: Read and discard input from a stream.
Files:
lib/freadseek.h
lib/freadseek.c
lib/stdio-impl.h
Depends-on:
freadahead
+1
View File
@@ -3,6 +3,7 @@ fseeko() function: Reposition a FILE stream.
Files:
lib/fseeko.c
lib/stdio-impl.h
m4/fseeko.m4
Depends-on:
+1
View File
@@ -4,6 +4,7 @@ Set the error indicator of a stream.
Files:
lib/fseterr.h
lib/fseterr.c
lib/stdio-impl.h
Depends-on:
+1
View File
@@ -4,6 +4,7 @@ fwritable() function: Determine whether a FILE stream supports writing.
Files:
lib/fwritable.h
lib/fwritable.c
lib/stdio-impl.h
m4/fwritable.m4
Depends-on:
+1
View File
@@ -4,6 +4,7 @@ fwriting() function: Determine whether a FILE stream is currently doing writing.
Files:
lib/fwriting.h
lib/fwriting.c
lib/stdio-impl.h
m4/fwriting.m4
Depends-on: