mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-04-05 08:40:27 +08:00
Sync libio to glibc-2.2 current CVS.
2000-07-01 Benjamin Kosnik <bkoz@purist.soma.redhat.com> Ulrich Drepper <drepper@purist.soma.redhat.com> Sync libio to glibc-2.2 current CVS. * libio/_G_config.h: New file. * libio/wfileops.c: New file. * libio/wfiledoalloc.c: New file. * libio/wgenops.c: New file. * libio/iofwide.c: New file. * libio/Makefile.am: Tweaks. * libio/Makefile.in: Regenerate. * libio/gen-params: Remove. Generic replacement for this yet undone. * libio/[filedoalloc.c, fileops.c, genops.c, iolibio.h, libio.h, libioP.h, stdfiles.c]: Update. * config/c_io_libio.cc: Tweaks. * acinclude.m4: Complete hacks to test wide io. * aclocal.m4: Regenerate. * configure: Regenerate. * src/Makefile.am: Update. * src/Makefile.in: Regenerate. * math/cargl.c: Remove underscores. * bits/locale_facets.h: Tweaks. Start adding iconv details and notes. * bits/locale_facets.tcc: Tweaks. * bits/std_cwchar.h: Tweaks. Co-Authored-By: Ulrich Drepper <drepper@purist.soma.redhat.com> From-SVN: r34822
This commit is contained in:
parent
dee4095a02
commit
20427c6b9b
@ -1,3 +1,31 @@
|
||||
2000-07-01 Benjamin Kosnik <bkoz@purist.soma.redhat.com>
|
||||
Ulrich Drepper <drepper@purist.soma.redhat.com>
|
||||
|
||||
Sync libio to glibc-2.2 current CVS.
|
||||
* libio/_G_config.h: New file.
|
||||
* libio/wfileops.c: New file.
|
||||
* libio/wfiledoalloc.c: New file.
|
||||
* libio/wgenops.c: New file.
|
||||
* libio/iofwide.c: New file.
|
||||
* libio/Makefile.am: Tweaks.
|
||||
* libio/Makefile.in: Regenerate.
|
||||
* libio/gen-params: Remove. Generic replacement for this yet undone.
|
||||
* libio/[filedoalloc.c, fileops.c, genops.c, iolibio.h, libio.h,
|
||||
libioP.h, stdfiles.c]: Update.
|
||||
* config/c_io_libio.cc: Tweaks.
|
||||
* acinclude.m4: Complete hacks to test wide io.
|
||||
* aclocal.m4: Regenerate.
|
||||
* configure: Regenerate.
|
||||
* src/Makefile.am: Update.
|
||||
* src/Makefile.in: Regenerate.
|
||||
|
||||
* math/cargl.c: Remove underscores.
|
||||
|
||||
* bits/locale_facets.h: Tweaks. Start adding iconv details
|
||||
and notes.
|
||||
* bits/locale_facets.tcc: Tweaks.
|
||||
* bits/std_cwchar.h: Tweaks.
|
||||
|
||||
2000-06-29 scott snyder <snyder@fnal.gov>
|
||||
|
||||
* bits/concept_checks.h
|
||||
@ -18,7 +46,7 @@
|
||||
function, uglify to __eos. Return char_type().
|
||||
* bits/std_ostream.h: Change.
|
||||
|
||||
* testsuite/27_io/ostream_seeks.cc (test01): New file.
|
||||
* testsuite/27_io/ostream_seeks.cc: New file.
|
||||
* testsuite/27_io/ostream_seeks-1.tst: New file.
|
||||
* testsuite/27_io/istream_unformatted.cc (main): Move test04 and
|
||||
test05 to...
|
||||
|
@ -1173,6 +1173,10 @@ AC_DEFUN(GLIBCPP_ENABLE_CSTDIO, [
|
||||
|
||||
# see if we are on a system with libio native (ie, linux)
|
||||
AC_CHECK_HEADER(libio.h, has_libio=yes, has_libio=no)
|
||||
|
||||
# bkoz XXX hack hack need version checks, this is temporary
|
||||
has_libio=no
|
||||
|
||||
if test $has_libio = "yes"; then
|
||||
BUILD_LIBIO_INCLUDE=
|
||||
need_libio=no
|
||||
@ -1186,6 +1190,11 @@ AC_DEFUN(GLIBCPP_ENABLE_CSTDIO, [
|
||||
# NB: This replaces the _G_CONFIG_H machinery in libio-v2
|
||||
AC_CHECK_HEADER(_G_config.h, has_gconf_h=yes, has_gconf_h=no)
|
||||
AM_CONDITIONAL(GLIBCPP_NEED_LIBIO_CONFIG_H, test "$has_gconf_h" = no)
|
||||
# bkoz XXX hack need to add support for non-glibc systems here
|
||||
has_gconf=no
|
||||
|
||||
# bkoz XXX need to add checks for this
|
||||
need_wlibio=yes
|
||||
;;
|
||||
xwince)
|
||||
CSTDIO_H=c_io_wince.h
|
||||
@ -1204,6 +1213,7 @@ AC_DEFUN(GLIBCPP_ENABLE_CSTDIO, [
|
||||
AC_SUBST(CSTDIO_H)
|
||||
AC_SUBST(CSTDIO_CC)
|
||||
AM_CONDITIONAL(GLIBCPP_NEED_LIBIO, test "$need_libio" = yes)
|
||||
AM_CONDITIONAL(GLIBCPP_NEED_WLIBIO, test "$need_wlibio" = yes)
|
||||
])
|
||||
|
||||
|
||||
|
10
libstdc++-v3/aclocal.m4
vendored
10
libstdc++-v3/aclocal.m4
vendored
@ -1185,6 +1185,10 @@ AC_DEFUN(GLIBCPP_ENABLE_CSTDIO, [
|
||||
|
||||
# see if we are on a system with libio native (ie, linux)
|
||||
AC_CHECK_HEADER(libio.h, has_libio=yes, has_libio=no)
|
||||
|
||||
# bkoz XXX hack hack need version checks, this is temporary
|
||||
has_libio=no
|
||||
|
||||
if test $has_libio = "yes"; then
|
||||
BUILD_LIBIO_INCLUDE=
|
||||
need_libio=no
|
||||
@ -1198,6 +1202,11 @@ AC_DEFUN(GLIBCPP_ENABLE_CSTDIO, [
|
||||
# NB: This replaces the _G_CONFIG_H machinery in libio-v2
|
||||
AC_CHECK_HEADER(_G_config.h, has_gconf_h=yes, has_gconf_h=no)
|
||||
AM_CONDITIONAL(GLIBCPP_NEED_LIBIO_CONFIG_H, test "$has_gconf_h" = no)
|
||||
# bkoz XXX hack need to add support for non-glibc systems here
|
||||
has_gconf=no
|
||||
|
||||
# bkoz XXX need to add checks for this
|
||||
need_wlibio=yes
|
||||
;;
|
||||
xwince)
|
||||
CSTDIO_H=c_io_wince.h
|
||||
@ -1216,6 +1225,7 @@ AC_DEFUN(GLIBCPP_ENABLE_CSTDIO, [
|
||||
AC_SUBST(CSTDIO_H)
|
||||
AC_SUBST(CSTDIO_CC)
|
||||
AM_CONDITIONAL(GLIBCPP_NEED_LIBIO, test "$need_libio" = yes)
|
||||
AM_CONDITIONAL(GLIBCPP_NEED_WLIBIO, test "$need_wlibio" = yes)
|
||||
])
|
||||
|
||||
|
||||
|
@ -39,6 +39,10 @@
|
||||
#include <bits/std_ctime.h> // For struct tm
|
||||
#include <bits/std_typeinfo.h> // For bad_cast, which shouldn't be here.
|
||||
#include <bits/std_ios.h> // For ios_base
|
||||
#ifdef _GLIBCPP_USE_WCHAR_T
|
||||
// XXX should break this out??
|
||||
#include <iconv.h> // For iconv, iconv_t
|
||||
#endif
|
||||
|
||||
namespace std
|
||||
{
|
||||
@ -76,6 +80,60 @@ namespace std
|
||||
_Use_facet_failure_handler(const locale&)
|
||||
{ throw _Bad_use_facet(); }
|
||||
|
||||
|
||||
#ifdef _GLIBCPP_USE_WCHAR_T
|
||||
// Extensions to use icov for dealing with character encodings,
|
||||
// including conversions and comparisons between various character
|
||||
// sets. This object encapsulates data that codecvt and possibly
|
||||
// ctype will use.
|
||||
template<typename _IntT, typename _ExtT>
|
||||
class __enc_traits
|
||||
{
|
||||
public:
|
||||
// Types:
|
||||
typedef iconv_t __conv_type;
|
||||
typedef _IntT __intc_type;
|
||||
typedef _ExtT __extc_type;
|
||||
|
||||
// max size of charset encoding name
|
||||
static const int __max_size = 32;
|
||||
// name of internal character set encoding.
|
||||
char __intc_enc[__max_size];
|
||||
// name of external character set encoding.
|
||||
char __extc_enc[__max_size];
|
||||
|
||||
const char*
|
||||
_M_get_intc_enc(void)
|
||||
{ return __intc_enc; }
|
||||
|
||||
void
|
||||
_M_set_intc_enc(const char* __c)
|
||||
{ strcpy(__intc_enc, __c); }
|
||||
|
||||
const char*
|
||||
_M_get_extc_enc(void)
|
||||
{ return __extc_enc; }
|
||||
|
||||
void
|
||||
_M_set_extc_enc(const char* __c)
|
||||
{ strcpy(__extc_enc, __c); }
|
||||
|
||||
__enc_traits(const char* __int, const char* __ext)
|
||||
{
|
||||
// __intc_end = whatever we are using internally, which is
|
||||
// almost alwyas UCS4 (linux) or UCS2 (microsoft, aix,
|
||||
// whatever...)
|
||||
// __extc_end = nl_langinfo(CODESET)
|
||||
strcpy(__intc_enc, __int);
|
||||
strcpy(__extc_enc, __ext);
|
||||
}
|
||||
|
||||
protected:
|
||||
__enc_traits();
|
||||
__enc_traits(const __enc_traits&);
|
||||
};
|
||||
#endif //_GLIBCPP_USE_WCHAR_T
|
||||
|
||||
// 22.2.1 The ctype category
|
||||
// Include host-specific ctype enums for ctype_base.
|
||||
#include <bits/ctype_base.h>
|
||||
@ -86,10 +144,10 @@ namespace std
|
||||
template<typename _CharT>
|
||||
class _Ctype_nois : public locale::facet, public ctype_base
|
||||
{
|
||||
public:
|
||||
// Types:
|
||||
typedef _CharT char_type;
|
||||
|
||||
public:
|
||||
char_type
|
||||
toupper(char_type __c) const
|
||||
{ return this->do_toupper(__c); }
|
||||
@ -162,7 +220,6 @@ namespace std
|
||||
class _Ctype : public _Ctype_nois<_CharT>
|
||||
{
|
||||
public:
|
||||
|
||||
// Types:
|
||||
typedef _CharT char_type;
|
||||
typedef typename _Ctype_nois<_CharT>::mask mask;
|
||||
@ -644,8 +701,8 @@ namespace std
|
||||
|
||||
#ifdef _GLIBCPP_USE_WCHAR_T
|
||||
template<>
|
||||
class codecvt<wchar_t,char,mbstate_t>
|
||||
: public _Codecvt<wchar_t,char,mbstate_t>
|
||||
class codecvt<wchar_t, char, mbstate_t>
|
||||
: public _Codecvt<wchar_t, char, mbstate_t>
|
||||
{
|
||||
public:
|
||||
// Types:
|
||||
@ -687,7 +744,7 @@ namespace std
|
||||
|
||||
// 22.2.1.6 Template class codecvt_byname
|
||||
template<typename _InternT, typename _ExternT, typename _StateT>
|
||||
class codecvt_byname : public codecvt<_InternT,_ExternT,_StateT>
|
||||
class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT>
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
@ -699,8 +756,8 @@ namespace std
|
||||
};
|
||||
|
||||
template<>
|
||||
class codecvt_byname<char,char,mbstate_t>
|
||||
: public codecvt<char,char,mbstate_t>
|
||||
class codecvt_byname<char, char, mbstate_t>
|
||||
: public codecvt<char, char, mbstate_t>
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
@ -713,8 +770,8 @@ namespace std
|
||||
|
||||
#ifdef _GLIBCPP_USE_WCHAR_T
|
||||
template<>
|
||||
class codecvt_byname<wchar_t,char,mbstate_t>
|
||||
: public codecvt<wchar_t,char,mbstate_t>
|
||||
class codecvt_byname<wchar_t, char, mbstate_t>
|
||||
: public codecvt<wchar_t, char, mbstate_t>
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
|
@ -606,7 +606,7 @@ namespace std
|
||||
// Stage 1: extract and determine the conversion specifier.
|
||||
// Assuming leading zeros eliminated, thus the size of 32 for
|
||||
// integral types.
|
||||
char __xtrc[32]= {'\0'};
|
||||
char __xtrc[32] = {'\0'};
|
||||
int __base;
|
||||
_M_extract(__beg, __end, __io, __err, __xtrc, __base, false);
|
||||
|
||||
|
@ -42,15 +42,17 @@
|
||||
# pragma system_header
|
||||
# include_next <wchar.h>
|
||||
#else
|
||||
# ifdef _GLIBCPP_NEED_MBSTATE_T
|
||||
# ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
typedef struct
|
||||
{
|
||||
int __fill[6];
|
||||
} mbstate_t;
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
#endif //_GLIBCPP_USE_WCHAR_T
|
||||
|
||||
#endif // _CPP_CWCHAR
|
||||
|
@ -41,7 +41,7 @@ namespace std {
|
||||
{
|
||||
_lock = __lock;
|
||||
_IO_init(this, 0);
|
||||
_IO_file_init(this);
|
||||
_IO_file_init((_IO_FILE_plus*) this);
|
||||
_IO_file_attach(this, -1);
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ namespace std {
|
||||
{
|
||||
_IO_do_flush(this);
|
||||
if (!(_flags & _IO_DELETE_DONT_CLOSE))
|
||||
_IO_SYSCLOSE(this);
|
||||
_IO_SYSCLOSE((_IO_FILE*)this);
|
||||
}
|
||||
_IO_default_finish(this, 0);
|
||||
}
|
||||
@ -92,7 +92,7 @@ namespace std {
|
||||
_fileno = __fd;
|
||||
int __mask = _IO_NO_READS + _IO_NO_WRITES + _IO_IS_APPENDING;
|
||||
_flags = (_flags & ~__mask) | (__rw_mode & __mask);
|
||||
_IO_link_in(this);
|
||||
_IO_link_in((_IO_FILE_plus*) this);
|
||||
__retval = this;
|
||||
}
|
||||
return __retval;
|
||||
|
1862
libstdc++-v3/configure
vendored
1862
libstdc++-v3/configure
vendored
File diff suppressed because it is too large
Load Diff
@ -23,11 +23,27 @@
|
||||
|
||||
AUTOMAKE_OPTIONS = 1.3 cygnus
|
||||
|
||||
# Passed down for cross compilers, canadian crosses.
|
||||
TOPLEVEL_INCLUDES = -I$(includedir)
|
||||
|
||||
LIBIO_INCLUDES = @BUILD_LIBIO_INCLUDE@ -I$(top_srcdir)/libio
|
||||
|
||||
CSHADOW_INCLUDES = @CSHADOWFLAGS@ @CSHADOW_INCLUDES@
|
||||
|
||||
CONFIG_INCLUDES = \
|
||||
-I$(top_srcdir)/@cpu_include_dir@ \
|
||||
-I$(top_srcdir)/@ctype_include_dir@
|
||||
|
||||
INCLUDES = \
|
||||
-D_GNU_SOURCE -nostdinc++ -I$(top_srcdir) \
|
||||
$(LIBIO_INCLUDES) $(CONFIG_INCLUDES) $(CSHADOW_INCLUDES) \
|
||||
$(TOPLEVEL_INCLUDES)
|
||||
|
||||
noinst_LTLIBRARIES = libio.la
|
||||
|
||||
LINK = $(LIBTOOL) --mode=link "$(CCLD)" $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
includes =
|
||||
#includes =
|
||||
|
||||
libio_headers = \
|
||||
libio.h libioP.h iolibio.h
|
||||
@ -39,35 +55,17 @@ else
|
||||
LIBIO_SRCS =
|
||||
endif
|
||||
|
||||
EXTRA_DIST = iostreamP.h
|
||||
|
||||
libio_la_LIBADD = $(LIBIO_SRCS)
|
||||
libio_la_DEPENDENCIES = $(libio_la_LIBADD)
|
||||
libio_la_SOURCES = $(LIBIO_SRCS)
|
||||
|
||||
if GLIBCPP_NEED_LIBIO_CONFIG_H
|
||||
LIBIO_CONFIG_H = _G_config.h
|
||||
if GLIBCPP_NEED_WLIBIO
|
||||
LIBIO_WSRCS = \
|
||||
iofwide.c wfiledoalloc.c wfileops.c wgenops.c
|
||||
else
|
||||
LIBIO_CONFIG_H =
|
||||
LIBIO_WSRCS =
|
||||
endif
|
||||
|
||||
# Specify that *.o depend on this one header
|
||||
$(libio_la_OBJECTS): $(LIBIO_CONFIG_H)
|
||||
|
||||
# Generate this file.
|
||||
_G_config.h: $(srcdir)/gen-params
|
||||
rootme=`pwd`/ ; export rootme; \
|
||||
CC="$(CC) $(CINCLUDES)"; export CC; \
|
||||
CXX="$(CXX) $(CXXINCLUDES) $(NOSTDINC) $(CXXFLAGS)"; export CXX; \
|
||||
CONFIG_NM="$(NM)"; export CONFIG_NM; \
|
||||
$(SHELL) $(srcdir)/gen-params LIB_VERSION=$(VERSION) $(G_CONFIG_ARGS) >tmp-params.h
|
||||
mv tmp-params.h _G_config.h
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
EXTRA_DIST = iostreamP.h
|
||||
|
||||
libio_la_LIBADD = $(LIBIO_SRCS) $(LIBIO_WSRCS)
|
||||
libio_la_DEPENDENCIES = $(libio_la_LIBADD)
|
||||
libio_la_SOURCES = $(LIBIO_SRCS) $(LIBIO_WSRCS)
|
||||
|
||||
|
@ -70,7 +70,6 @@ CC = @CC@
|
||||
CPP = @CPP@
|
||||
CPU_FLAGS = @CPU_FLAGS@
|
||||
CSHADOWFLAGS = @CSHADOWFLAGS@
|
||||
CSHADOW_INCLUDES = @CSHADOW_INCLUDES@
|
||||
CSTDIO_CC = @CSTDIO_CC@
|
||||
CSTDIO_H = @CSTDIO_H@
|
||||
CXX = @CXX@
|
||||
@ -109,11 +108,29 @@ libinst_wstring_la = @libinst_wstring_la@
|
||||
|
||||
AUTOMAKE_OPTIONS = 1.3 cygnus
|
||||
|
||||
# Passed down for cross compilers, canadian crosses.
|
||||
TOPLEVEL_INCLUDES = -I$(includedir)
|
||||
|
||||
LIBIO_INCLUDES = @BUILD_LIBIO_INCLUDE@ -I$(top_srcdir)/libio
|
||||
|
||||
CSHADOW_INCLUDES = @CSHADOWFLAGS@ @CSHADOW_INCLUDES@
|
||||
|
||||
CONFIG_INCLUDES = \
|
||||
-I$(top_srcdir)/@cpu_include_dir@ \
|
||||
-I$(top_srcdir)/@ctype_include_dir@
|
||||
|
||||
|
||||
INCLUDES = \
|
||||
-D_GNU_SOURCE -nostdinc++ -I$(top_srcdir) \
|
||||
$(LIBIO_INCLUDES) $(CONFIG_INCLUDES) $(CSHADOW_INCLUDES) \
|
||||
$(TOPLEVEL_INCLUDES)
|
||||
|
||||
|
||||
noinst_LTLIBRARIES = libio.la
|
||||
|
||||
LINK = $(LIBTOOL) --mode=link "$(CCLD)" $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
includes =
|
||||
#includes =
|
||||
|
||||
libio_headers = \
|
||||
libio.h libioP.h iolibio.h
|
||||
@ -121,14 +138,15 @@ libio_headers = \
|
||||
@GLIBCPP_NEED_LIBIO_TRUE@LIBIO_SRCS = @GLIBCPP_NEED_LIBIO_TRUE@\
|
||||
@GLIBCPP_NEED_LIBIO_TRUE@ filedoalloc.c genops.c fileops.c stdfiles.c cleanup.c
|
||||
@GLIBCPP_NEED_LIBIO_FALSE@LIBIO_SRCS =
|
||||
@GLIBCPP_NEED_WLIBIO_TRUE@LIBIO_WSRCS = @GLIBCPP_NEED_WLIBIO_TRUE@\
|
||||
@GLIBCPP_NEED_WLIBIO_TRUE@ iofwide.c wfiledoalloc.c wfileops.c wgenops.c
|
||||
@GLIBCPP_NEED_WLIBIO_FALSE@LIBIO_WSRCS =
|
||||
|
||||
EXTRA_DIST = iostreamP.h
|
||||
|
||||
libio_la_LIBADD = $(LIBIO_SRCS)
|
||||
libio_la_LIBADD = $(LIBIO_SRCS) $(LIBIO_WSRCS)
|
||||
libio_la_DEPENDENCIES = $(libio_la_LIBADD)
|
||||
libio_la_SOURCES = $(LIBIO_SRCS)
|
||||
@GLIBCPP_NEED_LIBIO_CONFIG_H_TRUE@LIBIO_CONFIG_H = @GLIBCPP_NEED_LIBIO_CONFIG_H_TRUE@_G_config.h
|
||||
@GLIBCPP_NEED_LIBIO_CONFIG_H_FALSE@LIBIO_CONFIG_H =
|
||||
libio_la_SOURCES = $(LIBIO_SRCS) $(LIBIO_WSRCS)
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/../mkinstalldirs
|
||||
CONFIG_HEADER = ../config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
@ -140,9 +158,27 @@ CPPFLAGS = @CPPFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBS = @LIBS@
|
||||
libio_la_LDFLAGS =
|
||||
@GLIBCPP_NEED_LIBIO_TRUE@libio_la_OBJECTS = filedoalloc.lo genops.lo \
|
||||
@GLIBCPP_NEED_LIBIO_TRUE@fileops.lo stdfiles.lo cleanup.lo
|
||||
@GLIBCPP_NEED_LIBIO_FALSE@libio_la_OBJECTS =
|
||||
@GLIBCPP_NEED_WLIBIO_TRUE@@GLIBCPP_NEED_LIBIO_TRUE@libio_la_OBJECTS = \
|
||||
@GLIBCPP_NEED_WLIBIO_TRUE@@GLIBCPP_NEED_LIBIO_TRUE@filedoalloc.lo \
|
||||
@GLIBCPP_NEED_WLIBIO_TRUE@@GLIBCPP_NEED_LIBIO_TRUE@genops.lo fileops.lo \
|
||||
@GLIBCPP_NEED_WLIBIO_TRUE@@GLIBCPP_NEED_LIBIO_TRUE@stdfiles.lo \
|
||||
@GLIBCPP_NEED_WLIBIO_TRUE@@GLIBCPP_NEED_LIBIO_TRUE@cleanup.lo \
|
||||
@GLIBCPP_NEED_WLIBIO_TRUE@@GLIBCPP_NEED_LIBIO_TRUE@iofwide.lo \
|
||||
@GLIBCPP_NEED_WLIBIO_TRUE@@GLIBCPP_NEED_LIBIO_TRUE@wfiledoalloc.lo \
|
||||
@GLIBCPP_NEED_WLIBIO_TRUE@@GLIBCPP_NEED_LIBIO_TRUE@wfileops.lo \
|
||||
@GLIBCPP_NEED_WLIBIO_TRUE@@GLIBCPP_NEED_LIBIO_TRUE@wgenops.lo
|
||||
@GLIBCPP_NEED_WLIBIO_TRUE@@GLIBCPP_NEED_LIBIO_FALSE@libio_la_OBJECTS = \
|
||||
@GLIBCPP_NEED_WLIBIO_TRUE@@GLIBCPP_NEED_LIBIO_FALSE@iofwide.lo \
|
||||
@GLIBCPP_NEED_WLIBIO_TRUE@@GLIBCPP_NEED_LIBIO_FALSE@wfiledoalloc.lo \
|
||||
@GLIBCPP_NEED_WLIBIO_TRUE@@GLIBCPP_NEED_LIBIO_FALSE@wfileops.lo \
|
||||
@GLIBCPP_NEED_WLIBIO_TRUE@@GLIBCPP_NEED_LIBIO_FALSE@wgenops.lo
|
||||
@GLIBCPP_NEED_WLIBIO_FALSE@@GLIBCPP_NEED_LIBIO_TRUE@libio_la_OBJECTS = \
|
||||
@GLIBCPP_NEED_WLIBIO_FALSE@@GLIBCPP_NEED_LIBIO_TRUE@filedoalloc.lo \
|
||||
@GLIBCPP_NEED_WLIBIO_FALSE@@GLIBCPP_NEED_LIBIO_TRUE@genops.lo \
|
||||
@GLIBCPP_NEED_WLIBIO_FALSE@@GLIBCPP_NEED_LIBIO_TRUE@fileops.lo \
|
||||
@GLIBCPP_NEED_WLIBIO_FALSE@@GLIBCPP_NEED_LIBIO_TRUE@stdfiles.lo \
|
||||
@GLIBCPP_NEED_WLIBIO_FALSE@@GLIBCPP_NEED_LIBIO_TRUE@cleanup.lo
|
||||
@GLIBCPP_NEED_WLIBIO_FALSE@@GLIBCPP_NEED_LIBIO_FALSE@libio_la_OBJECTS =
|
||||
CFLAGS = @CFLAGS@
|
||||
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
@ -339,18 +375,6 @@ installdirs mostlyclean-generic distclean-generic clean-generic \
|
||||
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
|
||||
|
||||
|
||||
# Specify that *.o depend on this one header
|
||||
$(libio_la_OBJECTS): $(LIBIO_CONFIG_H)
|
||||
|
||||
# Generate this file.
|
||||
_G_config.h: $(srcdir)/gen-params
|
||||
rootme=`pwd`/ ; export rootme; \
|
||||
CC="$(CC) $(CINCLUDES)"; export CC; \
|
||||
CXX="$(CXX) $(CXXINCLUDES) $(NOSTDINC) $(CXXFLAGS)"; export CXX; \
|
||||
CONFIG_NM="$(NM)"; export CONFIG_NM; \
|
||||
$(SHELL) $(srcdir)/gen-params LIB_VERSION=$(VERSION) $(G_CONFIG_ARGS) >tmp-params.h
|
||||
mv tmp-params.h _G_config.h
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
||||
|
130
libstdc++-v3/libio/_G_config.h
Normal file
130
libstdc++-v3/libio/_G_config.h
Normal file
@ -0,0 +1,130 @@
|
||||
/* This file is needed by libio to define various configuration parameters.
|
||||
These are always the same in the GNU C library. */
|
||||
|
||||
#ifndef _G_config_h
|
||||
#define _G_config_h 1
|
||||
|
||||
#ifndef _LIBC
|
||||
# include <bits/c++config.h>
|
||||
#endif
|
||||
|
||||
/* Define types for libio in terms of the standard internal type names. */
|
||||
|
||||
#include <sys/types.h>
|
||||
#define __need_size_t
|
||||
#define __need_wchar_t
|
||||
#define __need_wint_t
|
||||
#define __need_NULL
|
||||
#include <bits/std_cstddef.h>
|
||||
|
||||
|
||||
/* For use as part of glibc (native) or as part of libstdc++ (maybe
|
||||
not glibc) */
|
||||
#if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 1)
|
||||
# ifdef _GLIBCPP_USE_WCHAR_T
|
||||
# include <bits/std_cwchar.h>
|
||||
typedef mbstate_t __mbstate_t;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef _WINT_T
|
||||
/* Integral type unchanged by default argument promotions that can
|
||||
hold any value corresponding to members of the extended character
|
||||
set, as well as at least one value that does not correspond to any
|
||||
member of the extended character set. */
|
||||
# define _WINT_T
|
||||
typedef unsigned int wint_t;
|
||||
#endif
|
||||
#define __need_mbstate_t
|
||||
#include <bits/std_cwchar.h>
|
||||
#define _G_size_t size_t
|
||||
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
|
||||
typedef struct
|
||||
{
|
||||
__off_t __pos;
|
||||
__mbstate_t __state;
|
||||
} _G_fpos_t;
|
||||
typedef struct
|
||||
{
|
||||
__off64_t __pos;
|
||||
__mbstate_t __state;
|
||||
} _G_fpos64_t;
|
||||
#else
|
||||
typedef __off_t _G_fpos_t;
|
||||
typedef __off64_t _G_fpos64_t;
|
||||
#endif
|
||||
#define _G_ssize_t __ssize_t
|
||||
#define _G_off_t __off_t
|
||||
#define _G_off64_t __off64_t
|
||||
#define _G_pid_t __pid_t
|
||||
#define _G_uid_t __uid_t
|
||||
#define _G_wchar_t wchar_t
|
||||
#define _G_wint_t wint_t
|
||||
#define _G_stat64 stat64
|
||||
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
|
||||
# include <iconv.h>
|
||||
typedef iconv_t _G_iconv_t;
|
||||
# if 0
|
||||
/* XXX Commented out because outside glibc we have to use iconv()
|
||||
and not gconv(). */
|
||||
typedef union
|
||||
{
|
||||
struct __gconv_info __cd;
|
||||
struct
|
||||
{
|
||||
struct __gconv_info __cd;
|
||||
struct __gconv_step_data __data;
|
||||
} __combined;
|
||||
} _G_iconv_t;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
typedef int _G_int16_t __attribute__ ((__mode__ (__HI__)));
|
||||
typedef int _G_int32_t __attribute__ ((__mode__ (__SI__)));
|
||||
typedef unsigned int _G_uint16_t __attribute__ ((__mode__ (__HI__)));
|
||||
typedef unsigned int _G_uint32_t __attribute__ ((__mode__ (__SI__)));
|
||||
|
||||
#define _G_HAVE_BOOL 1
|
||||
|
||||
|
||||
/* These library features are always available in the GNU C library. */
|
||||
#define _G_HAVE_ATEXIT 1
|
||||
#define _G_HAVE_SYS_CDEFS 1
|
||||
#define _G_HAVE_SYS_WAIT 1
|
||||
#define _G_NEED_STDARG_H 1
|
||||
#define _G_va_list __gnuc_va_list
|
||||
|
||||
#define _G_HAVE_PRINTF_FP 1
|
||||
#define _G_HAVE_MMAP 1
|
||||
#define _G_HAVE_LONG_DOUBLE_IO 1
|
||||
#define _G_HAVE_IO_FILE_OPEN 1
|
||||
#define _G_HAVE_IO_GETLINE_INFO 1
|
||||
|
||||
#define _G_IO_IO_FILE_VERSION 0x20001
|
||||
|
||||
//#define _G_OPEN64 __open64
|
||||
//#define _G_LSEEK64 __lseek64
|
||||
//#define _G_FSTAT64(fd,buf) __fxstat64 (_STAT_VER, fd, buf)
|
||||
|
||||
/* This is defined by <bits/stat.h> if `st_blksize' exists. */
|
||||
#define _G_HAVE_ST_BLKSIZE defined (_STATBUF_ST_BLKSIZE)
|
||||
|
||||
#define _G_BUFSIZ 8192
|
||||
|
||||
/* These are the vtbl details for ELF. */
|
||||
#define _G_NAMES_HAVE_UNDERSCORE 0
|
||||
#define _G_VTABLE_LABEL_HAS_LENGTH 1
|
||||
#define _G_USING_THUNKS 1
|
||||
#define _G_VTABLE_LABEL_PREFIX "__vt_"
|
||||
#define _G_VTABLE_LABEL_PREFIX_ID __vt_
|
||||
|
||||
#define _G_INTERNAL_CCS "UCS4"
|
||||
|
||||
|
||||
#if defined __cplusplus || defined __STDC__
|
||||
# define _G_ARGS(ARGLIST) ARGLIST
|
||||
#else
|
||||
# define _G_ARGS(ARGLIST) ()
|
||||
#endif
|
||||
|
||||
#endif /* _G_config.h */
|
@ -27,34 +27,24 @@
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. [rescinded 22 July 1999]
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the University of California, Berkeley. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
/* Modified for GNU iostream by Per Bothner 1991, 1992. */
|
||||
|
||||
#ifndef _POSIX_SOURCE
|
||||
# define _POSIX_SOURCE
|
||||
#endif
|
||||
#include "libioP.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@ -83,9 +73,9 @@ _IO_file_doallocate (fp)
|
||||
_IO_size_t size;
|
||||
int couldbetty;
|
||||
char *p;
|
||||
struct stat st;
|
||||
struct _G_stat64 st;
|
||||
|
||||
#if !defined(_LIBC) && !defined(__linux__)
|
||||
#ifndef _LIBC
|
||||
/* If _IO_cleanup_registration_needed is non-zero, we should call the
|
||||
function it points to. This is to make sure _IO_cleanup gets called
|
||||
on exit. We call it from _IO_file_doallocate, since that is likely
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 1993, 1995, 1997 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1993, 1995, 1997-1999, 2000 Free Software Foundation, Inc.
|
||||
This file is part of the GNU IO Library.
|
||||
Written by Per Bothner <bothner@cygnus.com>.
|
||||
|
||||
@ -25,25 +25,50 @@
|
||||
General Public License. */
|
||||
|
||||
|
||||
#ifndef _POSIX_SOURCE
|
||||
# define _POSIX_SOURCE
|
||||
#endif
|
||||
#include "libioP.h"
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#ifdef __STDC__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#if _LIBC
|
||||
# include "../wcsmbs/wcsmbsload.h"
|
||||
# include <shlib-compat.h>
|
||||
#endif
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
#endif
|
||||
#ifndef __set_errno
|
||||
# define __set_errno(Val) errno = (Val)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _LIBC
|
||||
# define open(Name, Flags, Prot) __open (Name, Flags, Prot)
|
||||
# define close(FD) __close (FD)
|
||||
# define fstat(FD, Statbuf) __fstat (FD, Statbuf)
|
||||
# define lseek(FD, Offset, Whence) __lseek (FD, Offset, Whence)
|
||||
# define read(FD, Buf, NBytes) __read (FD, Buf, NBytes)
|
||||
# define write(FD, Buf, NBytes) __write (FD, Buf, NBytes)
|
||||
#else
|
||||
# define _IO_new_do_write _IO_do_write
|
||||
# define _IO_new_file_attach _IO_file_attach
|
||||
# define _IO_new_file_close_it _IO_file_close_it
|
||||
# define _IO_new_file_finish _IO_file_finish
|
||||
# define _IO_new_file_fopen _IO_file_fopen
|
||||
# define _IO_new_file_init _IO_file_init
|
||||
# define _IO_new_file_setbuf _IO_file_setbuf
|
||||
# define _IO_new_file_sync _IO_file_sync
|
||||
# define _IO_new_file_overflow _IO_file_overflow
|
||||
# define _IO_new_file_seekoff _IO_file_seekoff
|
||||
# define _IO_new_file_underflow _IO_file_underflow
|
||||
# define _IO_new_file_write _IO_file_write
|
||||
# define _IO_new_file_xsputn _IO_file_xsputn
|
||||
#endif
|
||||
|
||||
/* An fstream can be in at most one of put mode, get mode, or putback mode.
|
||||
@ -101,21 +126,21 @@ extern int errno;
|
||||
|
||||
|
||||
void
|
||||
_IO_file_init (fp)
|
||||
_IO_FILE *fp;
|
||||
_IO_new_file_init (fp)
|
||||
struct _IO_FILE_plus *fp;
|
||||
{
|
||||
/* POSIX.1 allows another file handle to be used to change the position
|
||||
of our file descriptor. Hence we actually don't know the actual
|
||||
position before we do the first fseek (and until a following fflush). */
|
||||
fp->_offset = _IO_pos_BAD;
|
||||
fp->_IO_file_flags |= CLOSED_FILEBUF_FLAGS;
|
||||
fp->file._offset = _IO_pos_BAD;
|
||||
fp->file._IO_file_flags |= CLOSED_FILEBUF_FLAGS;
|
||||
|
||||
_IO_link_in(fp);
|
||||
fp->_fileno = -1;
|
||||
_IO_link_in (fp);
|
||||
fp->file._fileno = -1;
|
||||
}
|
||||
|
||||
int
|
||||
_IO_file_close_it (fp)
|
||||
_IO_new_file_close_it (fp)
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
int write_status, close_status;
|
||||
@ -129,20 +154,31 @@ _IO_file_close_it (fp)
|
||||
close_status = _IO_SYSCLOSE (fp);
|
||||
|
||||
/* Free buffer. */
|
||||
_IO_setb (fp, NULL, NULL, 0);
|
||||
_IO_setg (fp, NULL, NULL, NULL);
|
||||
_IO_setp (fp, NULL, NULL);
|
||||
if (fp->_mode <= 0)
|
||||
{
|
||||
_IO_setb (fp, NULL, NULL, 0);
|
||||
_IO_setg (fp, NULL, NULL, NULL);
|
||||
_IO_setp (fp, NULL, NULL);
|
||||
}
|
||||
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
|
||||
else
|
||||
{
|
||||
_IO_wsetb (fp, NULL, NULL, 0);
|
||||
_IO_wsetg (fp, NULL, NULL, NULL);
|
||||
_IO_wsetp (fp, NULL, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
_IO_un_link (fp);
|
||||
_IO_un_link ((struct _IO_FILE_plus *) fp);
|
||||
fp->_flags = _IO_MAGIC|CLOSED_FILEBUF_FLAGS;
|
||||
fp->_fileno = EOF;
|
||||
fp->_fileno = -1;
|
||||
fp->_offset = _IO_pos_BAD;
|
||||
|
||||
return close_status ? close_status : write_status;
|
||||
}
|
||||
|
||||
void
|
||||
_IO_file_finish (fp, dummy)
|
||||
_IO_new_file_finish (fp, dummy)
|
||||
_IO_FILE *fp;
|
||||
int dummy;
|
||||
{
|
||||
@ -155,27 +191,57 @@ _IO_file_finish (fp, dummy)
|
||||
_IO_default_finish (fp, 0);
|
||||
}
|
||||
|
||||
#if _G_IO_IO_FILE_VERSION == 0x20001
|
||||
_IO_FILE *
|
||||
_IO_file_fopen (fp, filename, mode, some_int)
|
||||
_IO_FILE *fp;
|
||||
const char *filename;
|
||||
const char *mode;
|
||||
int some_int;
|
||||
#else
|
||||
_IO_FILE *
|
||||
_IO_file_fopen (fp, filename, mode)
|
||||
_IO_FILE *fp;
|
||||
const char *filename;
|
||||
const char *mode;
|
||||
#if defined __GNUC__ && __GNUC__ >= 2
|
||||
__inline__
|
||||
#endif
|
||||
_IO_FILE *
|
||||
_IO_file_open (fp, filename, posix_mode, prot, read_write, is32not64)
|
||||
_IO_FILE *fp;
|
||||
const char *filename;
|
||||
int posix_mode;
|
||||
int prot;
|
||||
int read_write;
|
||||
int is32not64;
|
||||
{
|
||||
int fdesc;
|
||||
#ifdef _G_OPEN64
|
||||
fdesc = (is32not64
|
||||
? open (filename, posix_mode, prot)
|
||||
: _G_OPEN64 (filename, posix_mode, prot));
|
||||
#else
|
||||
fdesc = open (filename, posix_mode, prot);
|
||||
#endif
|
||||
if (fdesc < 0)
|
||||
return NULL;
|
||||
fp->_fileno = fdesc;
|
||||
_IO_mask_flags (fp, read_write,_IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);
|
||||
if (read_write & _IO_IS_APPENDING)
|
||||
if (_IO_SEEKOFF (fp, (_IO_off64_t)0, _IO_seek_end, _IOS_INPUT|_IOS_OUTPUT)
|
||||
== _IO_pos_BAD && errno != ESPIPE)
|
||||
return NULL;
|
||||
_IO_link_in ((struct _IO_FILE_plus *) fp);
|
||||
return fp;
|
||||
}
|
||||
|
||||
_IO_FILE *
|
||||
_IO_new_file_fopen (fp, filename, mode, is32not64)
|
||||
_IO_FILE *fp;
|
||||
const char *filename;
|
||||
const char *mode;
|
||||
int is32not64;
|
||||
{
|
||||
int oflags = 0, omode;
|
||||
int read_write, fdesc;
|
||||
int read_write;
|
||||
int oprot = 0666;
|
||||
int i;
|
||||
_IO_FILE *result;
|
||||
#if _LIBC
|
||||
const char *cs;
|
||||
#endif
|
||||
|
||||
if (_IO_file_is_open (fp))
|
||||
return 0;
|
||||
switch (*mode++)
|
||||
switch (*mode)
|
||||
{
|
||||
case 'r':
|
||||
omode = O_RDONLY;
|
||||
@ -195,26 +261,81 @@ _IO_file_fopen (fp, filename, mode)
|
||||
__set_errno (EINVAL);
|
||||
return NULL;
|
||||
}
|
||||
if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+'))
|
||||
for (i = 1; i < 4; ++i)
|
||||
{
|
||||
omode = O_RDWR;
|
||||
read_write &= _IO_IS_APPENDING;
|
||||
switch (*++mode)
|
||||
{
|
||||
case '\0':
|
||||
break;
|
||||
case '+':
|
||||
omode = O_RDWR;
|
||||
read_write &= _IO_IS_APPENDING;
|
||||
continue;
|
||||
case 'x':
|
||||
oflags |= O_EXCL;
|
||||
continue;
|
||||
case 'b':
|
||||
default:
|
||||
/* Ignore. */
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
fdesc = open (filename, omode|oflags, oprot);
|
||||
if (fdesc < 0)
|
||||
return NULL;
|
||||
fp->_fileno = fdesc;
|
||||
_IO_mask_flags (fp, read_write,_IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);
|
||||
if (read_write & _IO_IS_APPENDING)
|
||||
if (_IO_SEEKOFF (fp, (_IO_off_t)0, _IO_seek_end, _IOS_INPUT|_IOS_OUTPUT)
|
||||
== _IO_pos_BAD && errno != ESPIPE)
|
||||
return NULL;
|
||||
_IO_link_in (fp);
|
||||
return fp;
|
||||
|
||||
result = _IO_file_open (fp, filename, omode|oflags, oprot, read_write,
|
||||
is32not64);
|
||||
|
||||
|
||||
#if _LIBC
|
||||
/* Test whether the mode string specifies the conversion. */
|
||||
cs = strstr (mode, ",ccs=");
|
||||
if (cs != NULL)
|
||||
{
|
||||
/* Yep. Load the appropriate conversions and set the orientation
|
||||
to wide. */
|
||||
struct gconv_fcts fcts;
|
||||
struct _IO_codecvt *cc;
|
||||
|
||||
if (! _IO_CHECK_WIDE (fp) || __wcsmbs_named_conv (&fcts, cs + 5) != 0)
|
||||
{
|
||||
/* Something went wrong, we cannot load the conversion modules.
|
||||
This means we cannot proceed since the user explicitly asked
|
||||
for these. */
|
||||
_IO_new_fclose (result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cc = &fp->_wide_data->_codecvt;
|
||||
|
||||
/* The functions are always the same. */
|
||||
*cc = __libio_codecvt;
|
||||
|
||||
cc->__cd_in.__cd.__nsteps = 1; /* Only one step allowed. */
|
||||
cc->__cd_in.__cd.__steps = fcts.towc;
|
||||
|
||||
cc->__cd_in.__cd.__data[0].__invocation_counter = 0;
|
||||
cc->__cd_in.__cd.__data[0].__internal_use = 1;
|
||||
cc->__cd_in.__cd.__data[0].__flags = __GCONV_IS_LAST;
|
||||
cc->__cd_in.__cd.__data[0].__statep = &result->_wide_data->_IO_state;
|
||||
|
||||
cc->__cd_out.__cd.__nsteps = 1; /* Only one step allowed. */
|
||||
cc->__cd_out.__cd.__steps = fcts.tomb;
|
||||
|
||||
cc->__cd_out.__cd.__data[0].__invocation_counter = 0;
|
||||
cc->__cd_out.__cd.__data[0].__internal_use = 1;
|
||||
cc->__cd_out.__cd.__data[0].__flags = __GCONV_IS_LAST;
|
||||
cc->__cd_out.__cd.__data[0].__statep = &result->_wide_data->_IO_state;
|
||||
|
||||
/* Set the mode now. */
|
||||
result->_mode = 1;
|
||||
}
|
||||
#endif /* GNU libc */
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
_IO_FILE *
|
||||
_IO_file_attach (fp, fd)
|
||||
_IO_new_file_attach (fp, fd)
|
||||
_IO_FILE *fp;
|
||||
int fd;
|
||||
{
|
||||
@ -226,67 +347,79 @@ _IO_file_attach (fp, fd)
|
||||
/* Get the current position of the file. */
|
||||
/* We have to do that since that may be junk. */
|
||||
fp->_offset = _IO_pos_BAD;
|
||||
if (_IO_SEEKOFF (fp, (_IO_off_t)0, _IO_seek_cur, _IOS_INPUT|_IOS_OUTPUT)
|
||||
if (_IO_SEEKOFF (fp, (_IO_off64_t)0, _IO_seek_cur, _IOS_INPUT|_IOS_OUTPUT)
|
||||
== _IO_pos_BAD && errno != ESPIPE)
|
||||
return NULL;
|
||||
return fp;
|
||||
}
|
||||
|
||||
_IO_FILE *
|
||||
_IO_file_setbuf (fp, p, len)
|
||||
_IO_new_file_setbuf (fp, p, len)
|
||||
_IO_FILE *fp;
|
||||
char *p;
|
||||
_IO_ssize_t len;
|
||||
{
|
||||
if (_IO_default_setbuf (fp, p, len) == NULL)
|
||||
return NULL;
|
||||
if (_IO_default_setbuf (fp, p, len) == NULL)
|
||||
return NULL;
|
||||
|
||||
fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end
|
||||
= fp->_IO_buf_base;
|
||||
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
|
||||
fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end
|
||||
= fp->_IO_buf_base;
|
||||
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
|
||||
|
||||
return fp;
|
||||
return fp;
|
||||
}
|
||||
|
||||
static int new_do_write __P ((_IO_FILE *, const char *, _IO_size_t));
|
||||
|
||||
/* Write TO_DO bytes from DATA to FP.
|
||||
Then mark FP as having empty buffers. */
|
||||
|
||||
int
|
||||
_IO_do_write (fp, data, to_do)
|
||||
_IO_new_do_write (fp, data, to_do)
|
||||
_IO_FILE *fp;
|
||||
const char *data;
|
||||
_IO_size_t to_do;
|
||||
{
|
||||
return (to_do == 0 || new_do_write (fp, data, to_do) == to_do)
|
||||
? 0 : EOF;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
new_do_write (fp, data, to_do)
|
||||
_IO_FILE *fp;
|
||||
const char *data;
|
||||
_IO_size_t to_do;
|
||||
{
|
||||
_IO_size_t count;
|
||||
if (to_do == 0)
|
||||
return 0;
|
||||
if (fp->_flags & _IO_IS_APPENDING)
|
||||
/* On a system without a proper O_APPEND implementation,
|
||||
you would need to sys_seek(0, SEEK_END) here, but it
|
||||
you would need to sys_seek(0, SEEK_END) here, but is
|
||||
is not needed nor desirable for Unix- or Posix-like systems.
|
||||
Instead, just indicate that offset (before and after) is
|
||||
unpredictable. */
|
||||
fp->_offset = _IO_pos_BAD;
|
||||
else if (fp->_IO_read_end != fp->_IO_write_base)
|
||||
{
|
||||
_IO_pos_t new_pos
|
||||
_IO_off64_t new_pos
|
||||
= _IO_SYSSEEK (fp, fp->_IO_write_base - fp->_IO_read_end, 1);
|
||||
if (new_pos == _IO_pos_BAD)
|
||||
return EOF;
|
||||
return 0;
|
||||
fp->_offset = new_pos;
|
||||
}
|
||||
count = _IO_SYSWRITE (fp, data, to_do);
|
||||
if (fp->_cur_column)
|
||||
fp->_cur_column = _IO_adjust_column (fp->_cur_column - 1, data, to_do) + 1;
|
||||
if (fp->_cur_column && count)
|
||||
fp->_cur_column = _IO_adjust_column (fp->_cur_column - 1, data, count) + 1;
|
||||
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
|
||||
fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_buf_base;
|
||||
fp->_IO_write_end = ((fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
|
||||
fp->_IO_write_end = (fp->_mode < 0
|
||||
&& (fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
|
||||
? fp->_IO_buf_base : fp->_IO_buf_end);
|
||||
return count != to_do ? EOF : 0;
|
||||
return count;
|
||||
}
|
||||
|
||||
int
|
||||
_IO_file_underflow (fp)
|
||||
_IO_new_file_underflow (fp)
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
_IO_ssize_t count;
|
||||
@ -298,6 +431,7 @@ _IO_file_underflow (fp)
|
||||
|
||||
if (fp->_flags & _IO_NO_READS)
|
||||
{
|
||||
fp->_flags |= _IO_ERR_SEEN;
|
||||
__set_errno (EBADF);
|
||||
return EOF;
|
||||
}
|
||||
@ -305,7 +439,15 @@ _IO_file_underflow (fp)
|
||||
return *(unsigned char *) fp->_IO_read_ptr;
|
||||
|
||||
if (fp->_IO_buf_base == NULL)
|
||||
_IO_doallocbuf (fp);
|
||||
{
|
||||
/* Maybe we already have a push back pointer. */
|
||||
if (fp->_IO_save_base != NULL)
|
||||
{
|
||||
free (fp->_IO_save_base);
|
||||
fp->_flags &= ~_IO_IN_BACKUP;
|
||||
}
|
||||
_IO_doallocbuf (fp);
|
||||
}
|
||||
|
||||
/* Flush all line buffered files before reading. */
|
||||
/* FIXME This can/should be moved to genops ?? */
|
||||
@ -341,7 +483,7 @@ _IO_file_underflow (fp)
|
||||
}
|
||||
|
||||
int
|
||||
_IO_file_overflow (f, ch)
|
||||
_IO_new_file_overflow (f, ch)
|
||||
_IO_FILE *f;
|
||||
int ch;
|
||||
{
|
||||
@ -352,7 +494,7 @@ _IO_file_overflow (f, ch)
|
||||
return EOF;
|
||||
}
|
||||
/* If currently reading or no buffer allocated. */
|
||||
if ((f->_flags & _IO_CURRENTLY_PUTTING) == 0)
|
||||
if ((f->_flags & _IO_CURRENTLY_PUTTING) == 0 || f->_IO_write_base == 0)
|
||||
{
|
||||
/* Allocate a buffer if needed. */
|
||||
if (f->_IO_write_base == 0)
|
||||
@ -374,32 +516,32 @@ _IO_file_overflow (f, ch)
|
||||
f->_IO_write_end = f->_IO_buf_end;
|
||||
f->_IO_read_base = f->_IO_read_ptr = f->_IO_read_end;
|
||||
|
||||
if (f->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
|
||||
f->_IO_write_end = f->_IO_write_ptr;
|
||||
f->_flags |= _IO_CURRENTLY_PUTTING;
|
||||
if (f->_mode < 0 && f->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
|
||||
f->_IO_write_end = f->_IO_write_ptr;
|
||||
}
|
||||
if (ch == EOF)
|
||||
return _IO_do_flush (f);
|
||||
return _IO_new_do_write(f, f->_IO_write_base,
|
||||
f->_IO_write_ptr - f->_IO_write_base);
|
||||
if (f->_IO_write_ptr == f->_IO_buf_end ) /* Buffer is really full */
|
||||
if (_IO_do_flush (f) == EOF)
|
||||
return EOF;
|
||||
*f->_IO_write_ptr++ = ch;
|
||||
if ((f->_flags & _IO_UNBUFFERED)
|
||||
|| ((f->_flags & _IO_LINE_BUF) && ch == '\n'))
|
||||
if (_IO_do_flush (f) == EOF)
|
||||
if (_IO_new_do_write(f, f->_IO_write_base,
|
||||
f->_IO_write_ptr - f->_IO_write_base) == EOF)
|
||||
return EOF;
|
||||
return (unsigned char) ch;
|
||||
}
|
||||
|
||||
int
|
||||
_IO_file_sync (fp)
|
||||
_IO_new_file_sync (fp)
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
_IO_size_t delta;
|
||||
_IO_ssize_t delta;
|
||||
int retval = 0;
|
||||
|
||||
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
|
||||
_IO_flockfile (fp);
|
||||
/* char* ptr = cur_ptr(); */
|
||||
if (fp->_IO_write_ptr > fp->_IO_write_base)
|
||||
if (_IO_do_flush(fp)) return EOF;
|
||||
@ -410,8 +552,8 @@ _IO_file_sync (fp)
|
||||
if (_IO_in_backup (fp))
|
||||
delta -= eGptr () - Gbase ();
|
||||
#endif
|
||||
_IO_off_t new_pos = _IO_SYSSEEK (fp, delta, 1);
|
||||
if (new_pos != (_IO_off_t) EOF)
|
||||
_IO_off64_t new_pos = _IO_SYSSEEK (fp, delta, 1);
|
||||
if (new_pos != (_IO_off64_t) EOF)
|
||||
fp->_IO_read_end = fp->_IO_read_ptr;
|
||||
#ifdef ESPIPE
|
||||
else if (errno == ESPIPE)
|
||||
@ -424,28 +566,18 @@ _IO_file_sync (fp)
|
||||
fp->_offset = _IO_pos_BAD;
|
||||
/* FIXME: Cleanup - can this be shared? */
|
||||
/* setg(base(), ptr, ptr); */
|
||||
_IO_cleanup_region_end (1);
|
||||
return retval;
|
||||
}
|
||||
|
||||
#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
||||
_IO_off64_t
|
||||
_IO_file_seekoff (fp, offset, dir, mode)
|
||||
_IO_new_file_seekoff (fp, offset, dir, mode)
|
||||
_IO_FILE *fp;
|
||||
_IO_off64_t offset;
|
||||
int dir;
|
||||
int mode;
|
||||
#else
|
||||
_IO_off_t
|
||||
_IO_file_seekoff (fp, offset, dir, mode)
|
||||
_IO_FILE *fp;
|
||||
_IO_off_t offset;
|
||||
int dir;
|
||||
int mode;
|
||||
#endif
|
||||
{
|
||||
_IO_pos_t result;
|
||||
_IO_off_t delta, new_offset;
|
||||
_IO_off64_t result;
|
||||
_IO_off64_t delta, new_offset;
|
||||
long count;
|
||||
/* POSIX.1 8.2.3.7 says that after a call the fflush() the file
|
||||
offset of the underlying file must be exact. */
|
||||
@ -469,6 +601,12 @@ _IO_file_seekoff (fp, offset, dir, mode)
|
||||
|
||||
if (fp->_IO_buf_base == NULL)
|
||||
{
|
||||
/* It could be that we already have a pushback buffer. */
|
||||
if (fp->_IO_read_base != NULL)
|
||||
{
|
||||
free (fp->_IO_read_base);
|
||||
fp->_flags &= ~_IO_IN_BACKUP;
|
||||
}
|
||||
_IO_doallocbuf (fp);
|
||||
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
|
||||
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
|
||||
@ -482,7 +620,7 @@ _IO_file_seekoff (fp, offset, dir, mode)
|
||||
if (fp->_offset == _IO_pos_BAD)
|
||||
goto dumb;
|
||||
/* Make offset absolute, assuming current pointer is file_ptr(). */
|
||||
offset += _IO_pos_as_off (fp->_offset);
|
||||
offset += fp->_offset;
|
||||
|
||||
dir = _IO_seek_set;
|
||||
break;
|
||||
@ -490,7 +628,7 @@ _IO_file_seekoff (fp, offset, dir, mode)
|
||||
break;
|
||||
case _IO_seek_end:
|
||||
{
|
||||
struct stat st;
|
||||
struct _G_stat64 st;
|
||||
if (_IO_SYSSTAT (fp, &st) == 0 && S_ISREG (st.st_mode))
|
||||
{
|
||||
offset += st.st_size;
|
||||
@ -502,13 +640,17 @@ _IO_file_seekoff (fp, offset, dir, mode)
|
||||
}
|
||||
/* At this point, dir==_IO_seek_set. */
|
||||
|
||||
/* If we are only interested in the current position we've found it now. */
|
||||
if (mode == 0)
|
||||
return offset;
|
||||
|
||||
/* If destination is within current buffer, optimize: */
|
||||
if (fp->_offset != _IO_pos_BAD && fp->_IO_read_base != NULL
|
||||
&& !_IO_in_backup (fp))
|
||||
{
|
||||
/* Offset relative to start of main get area. */
|
||||
_IO_pos_t rel_offset = (offset - fp->_offset
|
||||
+ (fp->_IO_read_end - fp->_IO_read_base));
|
||||
_IO_off64_t rel_offset = (offset - fp->_offset
|
||||
+ (fp->_IO_read_end - fp->_IO_read_base));
|
||||
if (rel_offset >= 0)
|
||||
{
|
||||
#if 0
|
||||
@ -520,7 +662,10 @@ _IO_file_seekoff (fp, offset, dir, mode)
|
||||
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base + rel_offset,
|
||||
fp->_IO_read_end);
|
||||
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
|
||||
return offset;
|
||||
{
|
||||
_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
|
||||
goto resync;
|
||||
}
|
||||
}
|
||||
#ifdef TODO
|
||||
/* If we have streammarkers, seek forward by reading ahead. */
|
||||
@ -530,7 +675,8 @@ _IO_file_seekoff (fp, offset, dir, mode)
|
||||
- (fp->_IO_read_ptr - fp->_IO_read_base);
|
||||
if (ignore (to_skip) != to_skip)
|
||||
goto dumb;
|
||||
return offset;
|
||||
_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
|
||||
goto resync;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -540,7 +686,8 @@ _IO_file_seekoff (fp, offset, dir, mode)
|
||||
if (!_IO_in_backup (fp))
|
||||
_IO_switch_to_backup_area (fp);
|
||||
gbump (fp->_IO_read_end + rel_offset - fp->_IO_read_ptr);
|
||||
return offset;
|
||||
_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
|
||||
goto resync;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -589,11 +736,23 @@ _IO_file_seekoff (fp, offset, dir, mode)
|
||||
_IO_unsave_markers (fp);
|
||||
result = _IO_SYSSEEK (fp, offset, dir);
|
||||
if (result != EOF)
|
||||
_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
|
||||
fp->_offset = result;
|
||||
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
|
||||
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
|
||||
{
|
||||
_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
|
||||
fp->_offset = result;
|
||||
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
|
||||
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
|
||||
}
|
||||
return result;
|
||||
|
||||
resync:
|
||||
/* We need to do it since it is possible that the file offset in
|
||||
the kernel may be changed behind our back. It may happen when
|
||||
we fopen a file and then do a fork. One process may access the
|
||||
the file and the kernel file offset will be changed. */
|
||||
if (fp->_offset >= 0)
|
||||
_IO_SYSSEEK (fp, fp->_offset, 0);
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
_IO_ssize_t
|
||||
@ -605,21 +764,17 @@ _IO_file_read (fp, buf, size)
|
||||
return read (fp->_fileno, buf, size);
|
||||
}
|
||||
|
||||
#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
||||
_IO_off64_t
|
||||
_IO_file_seek (fp, offset, dir)
|
||||
_IO_FILE *fp;
|
||||
_IO_off64_t offset;
|
||||
int dir;
|
||||
#else
|
||||
_IO_off_t
|
||||
_IO_file_seek (fp, offset, dir)
|
||||
_IO_FILE *fp;
|
||||
_IO_off_t offset;
|
||||
int dir;
|
||||
#endif
|
||||
{
|
||||
#ifdef _G_LSEEK64
|
||||
return _G_LSEEK64 (fp->_fileno, offset, dir);
|
||||
#else
|
||||
return lseek (fp->_fileno, offset, dir);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
@ -627,7 +782,11 @@ _IO_file_stat (fp, st)
|
||||
_IO_FILE *fp;
|
||||
void *st;
|
||||
{
|
||||
#ifdef _G_FSTAT64
|
||||
return _G_FSTAT64 (fp->_fileno, (struct _G_stat64 *) st);
|
||||
#else
|
||||
return fstat (fp->_fileno, (struct stat *) st);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
@ -638,7 +797,7 @@ _IO_file_close (fp)
|
||||
}
|
||||
|
||||
_IO_ssize_t
|
||||
_IO_file_write (f, data, n)
|
||||
_IO_new_file_write (f, data, n)
|
||||
_IO_FILE *f;
|
||||
const void *data;
|
||||
_IO_ssize_t n;
|
||||
@ -647,7 +806,7 @@ _IO_file_write (f, data, n)
|
||||
while (to_do > 0)
|
||||
{
|
||||
_IO_ssize_t count = write (f->_fileno, data, to_do);
|
||||
if (count == EOF)
|
||||
if (count < 0)
|
||||
{
|
||||
f->_flags |= _IO_ERR_SEEN;
|
||||
break;
|
||||
@ -662,12 +821,12 @@ _IO_file_write (f, data, n)
|
||||
}
|
||||
|
||||
_IO_size_t
|
||||
_IO_file_xsputn (f, data, n)
|
||||
_IO_new_file_xsputn (f, data, n)
|
||||
_IO_FILE *f;
|
||||
const void *data;
|
||||
_IO_size_t n;
|
||||
{
|
||||
register const char *s = (char *) data;
|
||||
register const char *s = (const char *) data;
|
||||
_IO_size_t to_do = n;
|
||||
int must_flush = 0;
|
||||
_IO_size_t count;
|
||||
@ -704,7 +863,12 @@ _IO_file_xsputn (f, data, n)
|
||||
count = to_do;
|
||||
if (count > 20)
|
||||
{
|
||||
#ifdef _LIBC
|
||||
f->_IO_write_ptr = __mempcpy (f->_IO_write_ptr, s, count);
|
||||
#else
|
||||
memcpy (f->_IO_write_ptr, s, count);
|
||||
f->_IO_write_ptr += count;
|
||||
#endif
|
||||
s += count;
|
||||
}
|
||||
else
|
||||
@ -713,125 +877,174 @@ _IO_file_xsputn (f, data, n)
|
||||
register int i = (int) count;
|
||||
while (--i >= 0)
|
||||
*p++ = *s++;
|
||||
f->_IO_write_ptr = p;
|
||||
}
|
||||
f->_IO_write_ptr += count;
|
||||
to_do -= count;
|
||||
}
|
||||
if (to_do + must_flush > 0)
|
||||
{
|
||||
_IO_size_t block_size, dont_write;
|
||||
_IO_size_t block_size, do_write;
|
||||
/* Next flush the (full) buffer. */
|
||||
if (__overflow (f, EOF) == EOF)
|
||||
if (_IO_OVERFLOW (f, EOF) == EOF)
|
||||
return n - to_do;
|
||||
|
||||
/* Try to maintain alignment: write a whole number of blocks.
|
||||
dont_write is what gets left over. */
|
||||
block_size = f->_IO_buf_end - f->_IO_buf_base;
|
||||
dont_write = block_size >= 128 ? to_do % block_size : 0;
|
||||
do_write = to_do - (block_size >= 128 ? to_do % block_size : 0);
|
||||
|
||||
count = to_do - dont_write;
|
||||
if (_IO_do_write (f, s, count) == EOF)
|
||||
return n - to_do;
|
||||
to_do = dont_write;
|
||||
if (do_write)
|
||||
{
|
||||
count = new_do_write (f, s, do_write);
|
||||
to_do -= count;
|
||||
if (count < do_write)
|
||||
return n - to_do;
|
||||
}
|
||||
|
||||
/* Now write out the remainder. Normally, this will fit in the
|
||||
buffer, but it's somewhat messier for line-buffered files,
|
||||
so we let _IO_default_xsputn handle the general case. */
|
||||
if (dont_write)
|
||||
to_do -= _IO_default_xsputn (f, s+count, dont_write);
|
||||
if (to_do)
|
||||
to_do -= _IO_default_xsputn (f, s+do_write, to_do);
|
||||
}
|
||||
return n - to_do;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Work in progress */
|
||||
_IO_size_t
|
||||
_IO_file_xsgetn (fp, data, n)
|
||||
_IO_FILE *fp;
|
||||
void *data;
|
||||
_IO_size_t n;
|
||||
{
|
||||
register _IO_size_t more = n;
|
||||
register _IO_size_t want, have;
|
||||
register _IO_ssize_t count;
|
||||
register char *s = data;
|
||||
for (;;)
|
||||
{
|
||||
/* Data available. */
|
||||
_IO_ssize_t count = fp->_IO_read_end - fp->_IO_read_ptr;
|
||||
if (count > 0)
|
||||
{
|
||||
if (count > more)
|
||||
count = more;
|
||||
if (count > 20)
|
||||
{
|
||||
memcpy (s, fp->_IO_read_ptr, count);
|
||||
s += count;
|
||||
fp->_IO_read_ptr += count;
|
||||
}
|
||||
else if (count <= 0)
|
||||
count = 0;
|
||||
else
|
||||
{
|
||||
register char *p = fp->_IO_read_ptr;
|
||||
register int i = (int) count;
|
||||
while (--i >= 0)
|
||||
*s++ = *p++;
|
||||
fp->_IO_read_ptr = p;
|
||||
}
|
||||
more -= count;
|
||||
}
|
||||
#if 0
|
||||
if (! _IO_in put_mode (fp)
|
||||
&& ! _IO_have_markers (fp) && ! IO_have_backup (fp))
|
||||
{
|
||||
/* This is an optimization of _IO_file_underflow */
|
||||
if (fp->_flags & _IO_NO_READS)
|
||||
break;
|
||||
/* If we're reading a lot of data, don't bother allocating
|
||||
a buffer. But if we're only reading a bit, perhaps we should ??*/
|
||||
if (count <= 512 && fp->_IO_buf_base == NULL)
|
||||
_IO_doallocbuf (fp);
|
||||
if (fp->_flags & (_IO_LINE_BUF|_IO_UNBUFFERED))
|
||||
_IO_flush_all_linebuffered ();
|
||||
|
||||
_IO_switch_to_get_mode (fp); ???;
|
||||
count = _IO_SYSREAD (fp, s, more);
|
||||
want = n;
|
||||
|
||||
if (fp->_IO_buf_base == NULL)
|
||||
{
|
||||
/* Maybe we already have a push back pointer. */
|
||||
if (fp->_IO_save_base != NULL)
|
||||
{
|
||||
free (fp->_IO_save_base);
|
||||
fp->_flags &= ~_IO_IN_BACKUP;
|
||||
}
|
||||
_IO_doallocbuf (fp);
|
||||
}
|
||||
|
||||
while (want > 0)
|
||||
{
|
||||
have = fp->_IO_read_end - fp->_IO_read_ptr;
|
||||
if (want <= have)
|
||||
{
|
||||
memcpy (s, fp->_IO_read_ptr, want);
|
||||
fp->_IO_read_ptr += want;
|
||||
want = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (have > 0)
|
||||
{
|
||||
#ifdef _LIBC
|
||||
s = __mempcpy (s, fp->_IO_read_ptr, have);
|
||||
#else
|
||||
memcpy (s, fp->_IO_read_ptr, have);
|
||||
s += have;
|
||||
#endif
|
||||
want -= have;
|
||||
fp->_IO_read_ptr += have;
|
||||
}
|
||||
|
||||
/* Check for backup and repeat */
|
||||
if (_IO_in_backup (fp))
|
||||
{
|
||||
_IO_switch_to_main_get_area (fp);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* If we now want less than a buffer, underflow and repeat
|
||||
the copy. Otherwise, _IO_SYSREAD directly to
|
||||
the user buffer. */
|
||||
if (fp->_IO_buf_base && want < fp->_IO_buf_end - fp->_IO_buf_base)
|
||||
{
|
||||
if (__underflow (fp) == EOF)
|
||||
break;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
/* These must be set before the sysread as we might longjmp out
|
||||
waiting for input. */
|
||||
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
|
||||
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
|
||||
|
||||
/* Try to maintain alignment: read a whole number of blocks. */
|
||||
count = want;
|
||||
if (fp->_IO_buf_base)
|
||||
{
|
||||
_IO_size_t block_size = fp->_IO_buf_end - fp->_IO_buf_base;
|
||||
if (block_size >= 128)
|
||||
count -= want % block_size;
|
||||
}
|
||||
|
||||
count = _IO_SYSREAD (fp, s, count);
|
||||
if (count <= 0)
|
||||
{
|
||||
if (count == 0)
|
||||
fp->_flags |= _IO_EOF_SEEN;
|
||||
else
|
||||
fp->_flags |= _IO_ERR_SEEN, count = 0;
|
||||
}
|
||||
{
|
||||
if (count == 0)
|
||||
fp->_flags |= _IO_EOF_SEEN;
|
||||
else
|
||||
fp->_flags |= _IO_ERR_SEEN;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
s += count;
|
||||
more -= count;
|
||||
want -= count;
|
||||
if (fp->_offset != _IO_pos_BAD)
|
||||
_IO_pos_adjust (fp->_offset, count);
|
||||
}
|
||||
#endif
|
||||
if (more == 0 || __underflow (fp) == EOF)
|
||||
break;
|
||||
}
|
||||
return n - more;
|
||||
|
||||
return n - want;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct _IO_jump_t _IO_file_jumps =
|
||||
{
|
||||
JUMP_INIT_DUMMY,
|
||||
JUMP_INIT(finish, _IO_file_finish),
|
||||
JUMP_INIT(overflow, _IO_file_overflow),
|
||||
JUMP_INIT(underflow, _IO_file_underflow),
|
||||
JUMP_INIT(finish, _IO_new_file_finish),
|
||||
JUMP_INIT(overflow, _IO_new_file_overflow),
|
||||
JUMP_INIT(underflow, _IO_new_file_underflow),
|
||||
JUMP_INIT(uflow, _IO_default_uflow),
|
||||
JUMP_INIT(pbackfail, _IO_default_pbackfail),
|
||||
JUMP_INIT(xsputn, _IO_file_xsputn),
|
||||
JUMP_INIT(xsgetn, _IO_default_xsgetn),
|
||||
JUMP_INIT(seekoff, _IO_file_seekoff),
|
||||
JUMP_INIT(xsputn, _IO_new_file_xsputn),
|
||||
JUMP_INIT(xsgetn, _IO_file_xsgetn),
|
||||
JUMP_INIT(seekoff, _IO_new_file_seekoff),
|
||||
JUMP_INIT(seekpos, _IO_default_seekpos),
|
||||
JUMP_INIT(setbuf, _IO_file_setbuf),
|
||||
JUMP_INIT(sync, _IO_file_sync),
|
||||
JUMP_INIT(setbuf, _IO_new_file_setbuf),
|
||||
JUMP_INIT(sync, _IO_new_file_sync),
|
||||
JUMP_INIT(doallocate, _IO_file_doallocate),
|
||||
JUMP_INIT(read, _IO_file_read),
|
||||
JUMP_INIT(write, _IO_file_write),
|
||||
JUMP_INIT(write, _IO_new_file_write),
|
||||
JUMP_INIT(seek, _IO_file_seek),
|
||||
JUMP_INIT(close, _IO_file_close),
|
||||
JUMP_INIT(stat, _IO_file_stat)
|
||||
JUMP_INIT(stat, _IO_file_stat),
|
||||
JUMP_INIT(showmanyc, _IO_default_showmanyc),
|
||||
JUMP_INIT(imbue, _IO_default_imbue)
|
||||
};
|
||||
|
||||
#ifdef _LIBC
|
||||
versioned_symbol (libc, _IO_new_do_write, _IO_do_write, GLIBC_2_1);
|
||||
versioned_symbol (libc, _IO_new_file_attach, _IO_file_attach, GLIBC_2_1);
|
||||
versioned_symbol (libc, _IO_new_file_close_it, _IO_file_close_it, GLIBC_2_1);
|
||||
versioned_symbol (libc, _IO_new_file_finish, _IO_file_finish, GLIBC_2_1);
|
||||
versioned_symbol (libc, _IO_new_file_fopen, _IO_file_fopen, GLIBC_2_1);
|
||||
versioned_symbol (libc, _IO_new_file_init, _IO_file_init, GLIBC_2_1);
|
||||
versioned_symbol (libc, _IO_new_file_setbuf, _IO_file_setbuf, GLIBC_2_1);
|
||||
versioned_symbol (libc, _IO_new_file_sync, _IO_file_sync, GLIBC_2_1);
|
||||
versioned_symbol (libc, _IO_new_file_overflow, _IO_file_overflow, GLIBC_2_1);
|
||||
versioned_symbol (libc, _IO_new_file_seekoff, _IO_file_seekoff, GLIBC_2_1);
|
||||
versioned_symbol (libc, _IO_new_file_underflow, _IO_file_underflow, GLIBC_2_1);
|
||||
versioned_symbol (libc, _IO_new_file_write, _IO_file_write, GLIBC_2_1);
|
||||
versioned_symbol (libc, _IO_new_file_xsputn, _IO_file_xsputn, GLIBC_2_1);
|
||||
#endif
|
||||
|
@ -1,751 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 1992, 1993, 1994, 1997, 1998, 1999 Free Software Foundation
|
||||
#
|
||||
# This file is part of the GNU IO Library. This library is free
|
||||
# software; you can redistribute it and/or modify it under the
|
||||
# terms of the GNU General Public License as published by the
|
||||
# Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this library; see the file COPYING. If not, write to the Free
|
||||
# Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
# Written by Per Bothner (bothner@cygnus.com)
|
||||
|
||||
# This is a shell-script that figures out various things about a
|
||||
# system, and writes (to stdout) a C-style include files with
|
||||
# suitable definitions, including all the standard Posix types.
|
||||
# It works by compiling various test programs -- some are run through
|
||||
# the C pre-processor, and the output examined.
|
||||
# The test programs are only compiled, not executed, so the script
|
||||
# should even if you're cross-compiling.
|
||||
# It uses $CC (which defaults to cc) to compile C programs (extension .c),
|
||||
# and $CXX (which defaults to gcc) to compile C++ programs (extension .C).
|
||||
# The shell-script is written for libg++.a.
|
||||
|
||||
# Usage: gen-params [NAME1=name1 ...]
|
||||
# - where an assignment (such as size_t="unsigned int" means to
|
||||
# use that value, instead of trying to figure it out.
|
||||
|
||||
# Uncomment following line for debugging
|
||||
# set -x
|
||||
|
||||
SED=sed
|
||||
|
||||
# Evaluate the arguments (which should be assignments):
|
||||
for arg in "$@"; do
|
||||
# Quote arg (i.e. FOO=bar => FOO='bar'), then eval it.
|
||||
eval `echo "$arg" | ${SED} -e "s|^\(.*\)=\(.*\)|\1='\2'|"`
|
||||
done
|
||||
|
||||
macro_prefix=${macro_prefix-"_G_"}
|
||||
rootdir=`pwd`/..
|
||||
gccdir=${gccdir-${rootdir}/gcc}
|
||||
binutilsdir=${binutilsdir-${rootdir}/binutils}
|
||||
CC=${CC-`if [ -f ${gccdir}/xgcc ] ; \
|
||||
then echo ${gccdir}/xgcc -B${gccdir}/ ; \
|
||||
else echo cc ; fi`}
|
||||
CXX=${CXX-`if [ -f ${gccdir}/xgcc ] ; \
|
||||
then echo ${gccdir}/xgcc -B${gccdir}/ ; \
|
||||
else echo gcc ; fi`}
|
||||
CPP=${CPP-`echo ${CC} -E`}
|
||||
CONFIG_NM=${CONFIG_NM-`if [ -f ${binutilsdir}/nm.new ] ; \
|
||||
then echo ${binutilsdir}/nm.new ; \
|
||||
else echo nm ; fi`}
|
||||
|
||||
# 2000-02-20 bkoz
|
||||
# Eventually use AC_CHECK_PROG(NM,nm,nm) instead of this hackery.
|
||||
# For now, as solaris and cygwin seem to require this, hardwire it.
|
||||
if test -z "$CONFIG_NM"; then
|
||||
CONFIG_NM=nm
|
||||
fi
|
||||
|
||||
cat <<!EOF!
|
||||
/* AUTOMATICALLY GENERATED; DO NOT EDIT! */
|
||||
#ifndef ${macro_prefix}config_h
|
||||
#define ${macro_prefix}config_h
|
||||
!EOF!
|
||||
|
||||
if [ x"${LIB_VERSION}" != "x" ] ; then
|
||||
echo "#define ${macro_prefix}LIB_VERSION" '"'${LIB_VERSION}'"'
|
||||
fi
|
||||
|
||||
# This program is used to test if the compiler prepends '_' before identifiers.
|
||||
# It is also used to check the g++ uses '$' or '.' various places.
|
||||
|
||||
if test -z "${NAMES_HAVE_UNDERSCORE}" \
|
||||
|| test -z "${DOLLAR_IN_LABEL}" \
|
||||
|| test -z "${VTABLE_LABEL_PREFIX}"; then
|
||||
cat >dummy.h <<!EOF!
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
struct filebuf {
|
||||
virtual int foo();
|
||||
};
|
||||
!EOF!
|
||||
cat >dummy.C <<!EOF!
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include "dummy.h"
|
||||
int filebuf::foo() { return 0; }
|
||||
extern "C" int FUNC(int);
|
||||
int FUNC(int i) { return i+10; }
|
||||
!EOF!
|
||||
|
||||
if ${CXX} -O -c dummy.C ; then
|
||||
if test -z "${NAMES_HAVE_UNDERSCORE}" ; then
|
||||
if test "`${CONFIG_NM} dummy.o | grep _FUNC`" != ""; then
|
||||
NAMES_HAVE_UNDERSCORE=1
|
||||
elif test "`${CONFIG_NM} dummy.o | grep FUNC`" != ""; then
|
||||
NAMES_HAVE_UNDERSCORE=0
|
||||
else
|
||||
echo "${CONFIG_NM} failed to find FUNC in dummy.o!" 1>&2; exit -1;
|
||||
fi
|
||||
fi
|
||||
echo "#define ${macro_prefix}NAMES_HAVE_UNDERSCORE ${NAMES_HAVE_UNDERSCORE}"
|
||||
|
||||
if test -z "${VTABLE_LABEL_PREFIX}" ; then
|
||||
# Determine how virtual function tables are named. This is fragile,
|
||||
# because different nm's produce output in different formats.
|
||||
${CONFIG_NM} dummy.o >TMP
|
||||
if [ -n "`${SED} -n -e 's/ virtual table/nope/p' <TMP`" ] ; then
|
||||
${CONFIG_NM} --no-cplus dummy.o >TMP 2>/dev/null ||
|
||||
${CONFIG_NM} --no-demangle dummy.o >TMP 2>/dev/null ||
|
||||
${CONFIG_NM} dummy.o >TMP 2>/dev/null
|
||||
fi
|
||||
# First we look for a pattern that matches historical output from g++.
|
||||
# We surround the actual label name by <> to separate it from
|
||||
# other nm junk.
|
||||
${SED} -n -e 's/_*vt[$_.]7*filebuf/<&>/p' <TMP >dummy.out
|
||||
# For paranoia's sake (e.g. if we're using some other C++ compiler)
|
||||
# we try a more general pattern, and append the result.
|
||||
grep -v foo <TMP \
|
||||
| ${SED} -n -e 's/[a-zA-Z0-9_.$]*filebuf[a-zA-Z0-9_.$]*/<&>/p' \
|
||||
>>dummy.out
|
||||
# Now we get rid of the <>, and any other junk on the nm output line.
|
||||
# (We get rid of <filebuf> in case nm included debugging output for
|
||||
# class filebuf itself.) On windows32, we also need to delete the
|
||||
# unique sections (.data$_vt$*), otherwise we get the wrong result.
|
||||
# Finally, we select the first line of the result, and hope that's
|
||||
# what we wanted!
|
||||
vtab_name=`${SED} -n -e '/<filebuf>/d' \
|
||||
-e '/\.data[$_.]<_vt\$7filebuf>/d' \
|
||||
-e 's/^.*<\(.*\)>.*$/\1/p' \
|
||||
<dummy.out | ${SED} -n -e '1p'`
|
||||
case "${vtab_name}" in
|
||||
*7filebuf) echo "#define ${macro_prefix}VTABLE_LABEL_HAS_LENGTH 1" ;;
|
||||
*) echo "#define ${macro_prefix}VTABLE_LABEL_HAS_LENGTH 0" ;;
|
||||
esac
|
||||
VTABLE_LABEL_PREFIX=`echo $vtab_name | ${SED} -e 's/7*filebuf//'`
|
||||
fi
|
||||
echo "#define ${macro_prefix}VTABLE_LABEL_PREFIX" '"'"${VTABLE_LABEL_PREFIX}"'"'
|
||||
if [ "${VTABLE_LABEL_PREFIX}" = "__vt_" -o \
|
||||
"${VTABLE_LABEL_PREFIX}" = "___vt_" ] ; then
|
||||
echo "#define ${macro_prefix}USING_THUNKS"
|
||||
fi
|
||||
|
||||
# VTABLE_LABEL_PREFIX_ID is the same as VTABLE_LABEL_PREFIX,
|
||||
# but the former is a C identifier, while the latter is a quoted
|
||||
# st
|
||||
if [ -z ""`echo ${VTABLE_LABEL_PREFIX} | ${SED} -e 's/[a-zA-Z0-9_]//g'` ] ; then
|
||||
if [ "${NAMES_HAVE_UNDERSCORE}" = "1" ] ; then
|
||||
VTABLE_LABEL_PREFIX=`echo ${VTABLE_LABEL_PREFIX} | ${SED} -e 's/^_//'`
|
||||
fi
|
||||
echo "#define ${macro_prefix}VTABLE_LABEL_PREFIX_ID ${VTABLE_LABEL_PREFIX}"
|
||||
fi
|
||||
|
||||
# if test -n "${DOLLAR_IN_LABEL}" ; then
|
||||
# echo "#define ${macro_prefix}DOLLAR_IN_LABEL ${DOLLAR_IN_LABEL}"
|
||||
# elif test "`${CONFIG_NM} dummy.o | grep 'vt[$$]7filebuf'`" != ""; then
|
||||
# echo "#define ${macro_prefix}DOLLAR_IN_LABEL 1"
|
||||
# elif test "`${CONFIG_NM} dummy.o | grep 'vt[.]7filebuf'`" != ""; then
|
||||
# echo "#define ${macro_prefix}DOLLAR_IN_LABEL 0"
|
||||
# elif test "`${CONFIG_NM} dummy.o | grep 'vtbl__7filebuf'`" != ""; then
|
||||
# echo "#define ${macro_prefix}DOLLAR_IN_LABEL 0"
|
||||
# else
|
||||
# echo "gen-params: ${CONFIG_NM} failed to find vt[.\$]filebuf in dummy.o!" 1>&2; exit 1
|
||||
# fi
|
||||
else
|
||||
# The compile failed for some reason (no C++?)
|
||||
echo "gen-params: could not compile dummy.C with ${CXX}" 1>&2; exit 1;
|
||||
fi
|
||||
fi
|
||||
|
||||
# A little test program to check if struct stat has st_blksize.
|
||||
cat >dummy.c <<!EOF!
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
int BLKSIZE(struct stat *st)
|
||||
{
|
||||
return st->st_blksize;
|
||||
}
|
||||
!EOF!
|
||||
|
||||
if ${CC} -c dummy.c >/dev/null 2>&1 ; then
|
||||
echo "#define ${macro_prefix}HAVE_ST_BLKSIZE 1"
|
||||
else
|
||||
echo "#define ${macro_prefix}HAVE_ST_BLKSIZE 0"
|
||||
fi
|
||||
|
||||
# A little test program to check if the name 'clog' is defined in libm,
|
||||
# as it is under DEC UNIX.
|
||||
cat >dummy.c <<!EOF!
|
||||
int clog;
|
||||
main () {}
|
||||
!EOF!
|
||||
|
||||
if ${CC} dummy.c -lm 2>&1 >/dev/null | grep clog >/dev/null; then
|
||||
echo "#define ${macro_prefix}CLOG_CONFLICT 1"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# Next, generate definitions for the standard types (such as mode_t)
|
||||
# compatible with those in the standard C header files.
|
||||
# It works by a dummy program through the C pre-processor, and then
|
||||
# using sed to search for typedefs in the output.
|
||||
|
||||
for hdr in wchar wctype; do
|
||||
eval $hdr=0
|
||||
cat >dummy.c <<EOF
|
||||
#include <${hdr}.h>
|
||||
EOF
|
||||
if ${CPP} dummy.c >/dev/null 2>&1 ; then eval $hdr=1; fi
|
||||
done
|
||||
|
||||
cat >dummy.c <<!EOF!
|
||||
#include <sys/types.h>
|
||||
#include <stddef.h>
|
||||
#ifdef __STDC__
|
||||
#include <stdarg.h>
|
||||
#else /* !__STDC__ */
|
||||
#include <varargs.h>
|
||||
#endif /* __STDC__ */
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <signal.h>
|
||||
#ifdef __STDC__
|
||||
#include <limits.h>
|
||||
#endif
|
||||
#if WCHAR == 1
|
||||
#include <wchar.h>
|
||||
#endif
|
||||
#if WCTYPE == 1
|
||||
#include <wctype.h>
|
||||
#endif
|
||||
#ifdef size_t
|
||||
typedef size_t Xsize_t;
|
||||
#elif defined(__SIZE_TYPE__)
|
||||
typedef __SIZE_TYPE__ Xsize_t;
|
||||
#endif
|
||||
#ifdef ptrdiff_t
|
||||
typedef ptrdiff_t Xptrdiff_t;
|
||||
#elif defined(__PTRDIFF_TYPE__)
|
||||
typedef __PTRDIFF_TYPE__ Xptrdiff_t;
|
||||
#endif
|
||||
#ifdef wchar_t
|
||||
typedef wchar_t Xwchar_t;
|
||||
#elif defined(__WCHAR_TYPE__)
|
||||
typedef __WCHAR_TYPE__ Xwchar_t;
|
||||
#endif
|
||||
#ifdef va_list
|
||||
typedef va_list XXXva_list;
|
||||
#endif
|
||||
#ifdef BUFSIZ
|
||||
long XBUFSIZ=BUFSIZ;
|
||||
#endif
|
||||
#ifdef FOPEN_MAX
|
||||
long XFOPEN_MAX=FOPEN_MAX;
|
||||
#endif
|
||||
#ifdef FILENAME_MAX
|
||||
long XFILENAME_MAX=FILENAME_MAX;
|
||||
#endif
|
||||
#ifdef SHRT_MAX
|
||||
long XSHRT_MAX=SHRT_MAX;
|
||||
#endif
|
||||
#ifdef INT_MAX
|
||||
long XINT_MAX=INT_MAX;
|
||||
#endif
|
||||
#ifdef LONG_MAX
|
||||
long XLONG_MAX=LONG_MAX;
|
||||
#endif
|
||||
#ifdef LONG_LONG_MAX
|
||||
long XLONG_LONG_MAX=LONG_LONG_MAX;
|
||||
#endif
|
||||
!EOF!
|
||||
|
||||
if ${CPP} dummy.c -DWCHAR=$wchar -DWCTYPE=$wctype >TMP ; then true
|
||||
else
|
||||
echo "gen-params: could not invoke ${CPP} on dummy.c" 1>&2 ; exit 1
|
||||
fi
|
||||
tr ' ' ' ' <TMP >dummy.out
|
||||
|
||||
for TYPE in dev_t clock_t fpos_t gid_t ino_t mode_t nlink_t off_t pid_t ptrdiff_t sigset_t size_t ssize_t time_t uid_t va_list wchar_t wint_t int16_t uint16_t int32_t uint_32_t u_int16_t u_int32_t; do
|
||||
eval IMPORTED=\$$TYPE
|
||||
if [ -n "${IMPORTED}" ] ; then
|
||||
eval "$TYPE='$IMPORTED'"
|
||||
else
|
||||
t=$TYPE
|
||||
VALUE=''
|
||||
|
||||
# Follow `typedef VALUE TYPE' chains, but don't loop indefinitely.
|
||||
for iteration in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
|
||||
# Search dummy.out for a typedef for X*$t.
|
||||
sed_script="
|
||||
s/unsigned long long int/_G_ullong/g
|
||||
s/long long int/_G_llong/g
|
||||
s/unsigned long long/_G_ullong/g
|
||||
s/long long/_G_llong/g
|
||||
/.*typedef *\\(.*[^ ]\\) *X*$t *;.*/{s||\1|;p;q;}
|
||||
/.*typedef *\\(.*[^ a-zA-Z0-9_]\\)X*$t *;.*/{s||\1|;p;q;}
|
||||
"
|
||||
t=`${SED} -n "$sed_script" <dummy.out`
|
||||
case "$t" in
|
||||
'')
|
||||
break;;
|
||||
*)
|
||||
# Found a type $t; save it in VALUE.
|
||||
VALUE=$t
|
||||
# If it won't cause problems in matching,
|
||||
# look for a typedef for it in turn.
|
||||
case "$VALUE" in
|
||||
*.* | */* | *\ * | *\** | *\[* | *\\*) break;;
|
||||
esac;;
|
||||
esac
|
||||
done
|
||||
|
||||
case "$VALUE" in
|
||||
?*) eval "$TYPE=\"$VALUE\""
|
||||
esac
|
||||
fi
|
||||
done
|
||||
|
||||
# Look for some standard macros.
|
||||
for NAME in BUFSIZ FOPEN_MAX FILENAME_MAX NULL; do
|
||||
eval IMPORTED=\$$NAME
|
||||
if [ -n "${IMPORTED}" ] ; then
|
||||
eval "$NAME='$IMPORTED /* specified */'"
|
||||
else
|
||||
rm -f TMP
|
||||
${SED} -n -e 's| *;|;|g' -e "s|long X${NAME}= *\(.*\);|\1|w TMP" \
|
||||
<dummy.out>/dev/null
|
||||
# Now select the first definition.
|
||||
if [ -s TMP ]; then
|
||||
eval "$NAME='"`${SED} -e '2,$d' <TMP`"'"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# These macros must be numerical constants; strip any trailing 'L's.
|
||||
for NAME in SHRT_MAX INT_MAX LONG_MAX LONG_LONG_MAX; do
|
||||
eval IMPORTED=\$$NAME
|
||||
if [ -n "${IMPORTED}" ] ; then
|
||||
eval "$NAME='$IMPORTED /* specified */'"
|
||||
else
|
||||
rm -f TMP
|
||||
${SED} -n -e 's| *;|;|g' -e "s|long X${NAME}= *\([0-9]*\)L* *;|\1|w TMP" \
|
||||
<dummy.out>/dev/null
|
||||
# Now select the first definition.
|
||||
if [ -s TMP ]; then
|
||||
eval "$NAME='"`${SED} -e '2,$d' <TMP`"'"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# Figure out integral type sizes.
|
||||
|
||||
default_int16='short /* deduction failed */'
|
||||
default_int32='long /* deduction failed */'
|
||||
INT16=32767
|
||||
INT32=2147483647
|
||||
|
||||
if [ "${SHRT_MAX}" = $INT16 ] ; then
|
||||
default_int16='short /* deduced */'
|
||||
if [ "${LONG_MAX}" = $INT32 ] ; then
|
||||
default_int32='long /* deduced */'
|
||||
elif [ "${INT_MAX}" = $INT32 ] ; then
|
||||
default_int32='int /* deduced */'
|
||||
fi
|
||||
fi
|
||||
|
||||
[ -n "$u_int16_t" ] && uint16_t="$u_int16_t"
|
||||
[ -n "$u_int32_t" ] && uint32_t="$u_int32_t"
|
||||
|
||||
[ -z "$int16_t" ] && int16_t="$default_int16"
|
||||
[ -z "$uint16_t" ] && uint16_t="unsigned $int16_t"
|
||||
[ -z "$int32_t" ] && int32_t="$default_int32"
|
||||
[ -z "$uint32_t" ] && uint32_t="unsigned $int32_t"
|
||||
|
||||
cat <<!EOF!
|
||||
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
|
||||
typedef int ${macro_prefix}int8_t __attribute__((__mode__(__QI__)));
|
||||
typedef unsigned int ${macro_prefix}uint8_t __attribute__((__mode__(__QI__)));
|
||||
typedef int ${macro_prefix}int16_t __attribute__((__mode__(__HI__)));
|
||||
typedef unsigned int ${macro_prefix}uint16_t __attribute__((__mode__(__HI__)));
|
||||
typedef int ${macro_prefix}int32_t __attribute__((__mode__(__SI__)));
|
||||
typedef unsigned int ${macro_prefix}uint32_t __attribute__((__mode__(__SI__)));
|
||||
typedef int ${macro_prefix}int64_t __attribute__((__mode__(__DI__)));
|
||||
typedef unsigned int ${macro_prefix}uint64_t __attribute__((__mode__(__DI__)));
|
||||
#if __GNUC__ > 2 || __GNUC_MINOR__ >= 8
|
||||
__extension__ typedef long long ${macro_prefix}llong;
|
||||
__extension__ typedef unsigned long long ${macro_prefix}ullong;
|
||||
#endif
|
||||
#else
|
||||
typedef $int16_t ${macro_prefix}int16_t;
|
||||
typedef $uint16_t ${macro_prefix}uint16_t;
|
||||
typedef $int32_t ${macro_prefix}int32_t;
|
||||
typedef $uint32_t ${macro_prefix}uint32_t;
|
||||
#endif
|
||||
|
||||
typedef ${clock_t-int /* default */} ${macro_prefix}clock_t;
|
||||
typedef ${dev_t-int /* default */} ${macro_prefix}dev_t;
|
||||
typedef ${fpos_t-long /* default */} ${macro_prefix}fpos_t;
|
||||
typedef ${gid_t-int /* default */} ${macro_prefix}gid_t;
|
||||
typedef ${ino_t-int /* default */} ${macro_prefix}ino_t;
|
||||
typedef ${mode_t-int /* default */} ${macro_prefix}mode_t;
|
||||
typedef ${nlink_t-int /* default */} ${macro_prefix}nlink_t;
|
||||
typedef ${off_t-long /* default */} ${macro_prefix}off_t;
|
||||
typedef ${pid_t-int /* default */} ${macro_prefix}pid_t;
|
||||
#ifndef __PTRDIFF_TYPE__
|
||||
#define __PTRDIFF_TYPE__ ${ptrdiff_t-long int /* default */}
|
||||
#endif
|
||||
typedef __PTRDIFF_TYPE__ ${macro_prefix}ptrdiff_t;
|
||||
typedef ${sigset_t-int /* default */} ${macro_prefix}sigset_t;
|
||||
#ifndef __SIZE_TYPE__
|
||||
#define __SIZE_TYPE__ ${size_t-unsigned long /* default */}
|
||||
#endif
|
||||
typedef __SIZE_TYPE__ ${macro_prefix}size_t;
|
||||
typedef ${time_t-int /* default */} ${macro_prefix}time_t;
|
||||
typedef ${uid_t-int /* default */} ${macro_prefix}uid_t;
|
||||
typedef ${wchar_t-int /* default */} ${macro_prefix}wchar_t;
|
||||
|
||||
#define ${macro_prefix}BUFSIZ ${BUFSIZ-1024 /* default */}
|
||||
#define ${macro_prefix}FOPEN_MAX ${FOPEN_MAX-32 /* default */}
|
||||
#define ${macro_prefix}FILENAME_MAX ${FILENAME_MAX-1024 /* default */}
|
||||
#if defined (__cplusplus) || defined (__STDC__)
|
||||
#define ${macro_prefix}ARGS(ARGLIST) ARGLIST
|
||||
#else
|
||||
#define ${macro_prefix}ARGS(ARGLIST) ()
|
||||
#endif
|
||||
#if !defined (__GNUG__) || defined (__STRICT_ANSI__)
|
||||
#define ${macro_prefix}NO_NRV
|
||||
#endif
|
||||
#if !defined (__GNUG__)
|
||||
#define _G_NO_EXTERN_TEMPLATES
|
||||
#endif
|
||||
!EOF!
|
||||
|
||||
# ssize_t is the signed version of size_t
|
||||
if [ -n "${ssize_t}" ] ; then
|
||||
echo "typedef ${ssize_t} ${macro_prefix}ssize_t;"
|
||||
elif [ -z "${size_t}" ] ; then
|
||||
echo "typedef long ${macro_prefix}ssize_t;"
|
||||
else
|
||||
# Remove "unsigned" from ${size_t} to get ${ssize_t}.
|
||||
tmp="`echo ${size_t} | ${SED} -e 's|unsigned||g' -e 's| | |g'`"
|
||||
if [ -z "$tmp" ] ; then
|
||||
tmp=int
|
||||
else
|
||||
# check $tmp doesn't conflict with <unistd.h>
|
||||
echo "#include <unistd.h>
|
||||
extern $tmp read();" >dummy.c
|
||||
${CC} -c dummy.c >/dev/null 2>&1 || tmp=int
|
||||
fi
|
||||
echo "typedef $tmp /* default */ ${macro_prefix}ssize_t;"
|
||||
fi
|
||||
|
||||
# wint_t is often the integral type to which wchar_t promotes.
|
||||
if [ -z "${wint_t}" ] ; then
|
||||
for TYPE in int 'unsigned int' 'long int' 'long unsigned int'; do
|
||||
cat >dummy.C <<!EOF!
|
||||
#ifndef __WCHAR_TYPE__
|
||||
#define __WCHAR_TYPE__ ${wchar_t-int /* default */}
|
||||
#endif
|
||||
typedef __WCHAR_TYPE__ ${macro_prefix}wchar_t;
|
||||
void foo ($TYPE);
|
||||
void foo (double);
|
||||
void bar (${macro_prefix}wchar_t w)
|
||||
{
|
||||
foo (w);
|
||||
}
|
||||
!EOF!
|
||||
if ${CXX} -c dummy.C >/dev/null 2>&1 ; then
|
||||
wint_t="$TYPE /* default */"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
echo "typedef ${wint_t-int /* wchar_t is broken */} ${macro_prefix}wint_t;"
|
||||
|
||||
# va_list can cause problems (e.g. some systems have va_list as a struct).
|
||||
# Check to see if ${va_list-char*} really is compatible with stdarg.h.
|
||||
cat >dummy.C <<!EOF!
|
||||
#define X_va_list ${va_list-char* /* default */}
|
||||
extern long foo(X_va_list ap); /* Check that X_va_list compiles on its own */
|
||||
extern "C" {
|
||||
#include <stdarg.h>
|
||||
}
|
||||
long foo(X_va_list ap) { return va_arg(ap, long); }
|
||||
long bar(int i, ...)
|
||||
{ va_list ap; long j; va_start(ap, i); j = foo(ap); va_end(ap); return j; }
|
||||
!EOF!
|
||||
if ${CXX} -c dummy.C >/dev/null 2>&1 ; then
|
||||
# Ok: We have something that works.
|
||||
echo "typedef ${va_list-char* /* default */} ${macro_prefix}va_list;"
|
||||
else
|
||||
echo "#define ${macro_prefix}NEED_STDARG_H"
|
||||
# Check and see if we have __gnuc_va_list, as we might set up define
|
||||
# loops if we use va_list.
|
||||
cat >dummy.C <<!EOF!
|
||||
#include <stdarg.h>
|
||||
long foo(__gnuc_va_list ap) { return va_arg(ap, long); }
|
||||
!EOF!
|
||||
if ${CXX} -c dummy.C >/dev/null 2>&1 ; then
|
||||
echo "#define ${macro_prefix}va_list __gnuc_va_list"
|
||||
else
|
||||
echo "#define ${macro_prefix}va_list va_list"
|
||||
fi
|
||||
fi
|
||||
|
||||
cat >dummy.c <<!EOF!
|
||||
#include <signal.h>
|
||||
extern int (*signal())();
|
||||
extern int dummy (int);
|
||||
main()
|
||||
{
|
||||
int (*oldsig)(int) = signal (1, dummy);
|
||||
(void) signal (2, oldsig);
|
||||
return 0;
|
||||
}
|
||||
!EOF!
|
||||
if ${CC} -c dummy.c >/dev/null 2>&1 ; then
|
||||
echo "#define ${macro_prefix}signal_return_type int"
|
||||
else
|
||||
echo "#define ${macro_prefix}signal_return_type void"
|
||||
fi
|
||||
|
||||
# check sprintf return type
|
||||
|
||||
cat >dummy.c <<!EOF!
|
||||
#include <stdio.h>
|
||||
extern int sprintf(); char buf[100];
|
||||
int main() { return sprintf(buf, "%d", 34); }
|
||||
!EOF!
|
||||
if ${CC} -c dummy.c >/dev/null 2>&1 ; then
|
||||
echo "#define ${macro_prefix}sprintf_return_type int"
|
||||
else
|
||||
echo "#define ${macro_prefix}sprintf_return_type char*"
|
||||
fi
|
||||
|
||||
if test -n "${HAVE_ATEXIT}" ; then
|
||||
echo "#define ${macro_prefix}HAVE_ATEXIT ${HAVE_ATEXIT}"
|
||||
else
|
||||
cat >dummy.c <<!EOF!
|
||||
#include <stdlib.h>
|
||||
int main()
|
||||
{
|
||||
atexit (0);
|
||||
}
|
||||
!EOF!
|
||||
if ${CC} dummy.c >/dev/null 2>&1 ; then
|
||||
echo "#define ${macro_prefix}HAVE_ATEXIT 1"
|
||||
else
|
||||
echo "#define ${macro_prefix}HAVE_ATEXIT 0"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# *** Check for presence of certain include files ***
|
||||
|
||||
# check for sys/resource.h
|
||||
|
||||
if test -n "${HAVE_SYS_RESOURCE}" ; then
|
||||
echo "#define ${macro_prefix}HAVE_SYS_RESOURCE ${HAVE_SYS_RESOURCE}"
|
||||
else
|
||||
cat >dummy.c <<!EOF!
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
int main()
|
||||
{
|
||||
struct rusage res;
|
||||
getrusage(RUSAGE_SELF, &res);
|
||||
return (int)(res.ru_utime.tv_sec + (res.ru_utime.tv_usec / 1000000.0));
|
||||
}
|
||||
!EOF!
|
||||
# Note: We link because some systems have sys/resource, but not getrusage().
|
||||
if ${CC} dummy.c >/dev/null 2>&1 ; then
|
||||
echo "#define ${macro_prefix}HAVE_SYS_RESOURCE 1"
|
||||
else
|
||||
echo "#define ${macro_prefix}HAVE_SYS_RESOURCE 0"
|
||||
fi
|
||||
fi
|
||||
|
||||
# check for struct tms in sys/times.h
|
||||
|
||||
if test -n "${HAVE_SYS_TIMES}" ; then
|
||||
echo "#define ${macro_prefix}HAVE_SYS_TIMES ${HAVE_SYS_TIMES}"
|
||||
else
|
||||
cat >dummy.c <<!EOF!
|
||||
#include <sys/types.h>
|
||||
#include <sys/times.h>
|
||||
int main()
|
||||
{
|
||||
struct tms s;
|
||||
return s.tms_utime;
|
||||
}
|
||||
!EOF!
|
||||
if ${CC} -c dummy.c >/dev/null 2>&1 ; then
|
||||
echo "#define ${macro_prefix}HAVE_SYS_TIMES 1"
|
||||
else
|
||||
echo "#define ${macro_prefix}HAVE_SYS_TIMES 0"
|
||||
fi
|
||||
fi
|
||||
|
||||
# check for sys/socket.h
|
||||
|
||||
if test -n "${HAVE_SYS_SOCKET}" ; then
|
||||
echo "#define ${macro_prefix}HAVE_SYS_SOCKET ${HAVE_SYS_SOCKET}"
|
||||
else
|
||||
echo '#include <sys/types.h>' >dummy.c
|
||||
echo '#include <sys/socket.h>' >>dummy.c
|
||||
if ${CC} -c dummy.c >/dev/null 2>&1 ; then
|
||||
echo "#define ${macro_prefix}HAVE_SYS_SOCKET 1"
|
||||
else
|
||||
echo "#define ${macro_prefix}HAVE_SYS_SOCKET 0"
|
||||
fi
|
||||
fi
|
||||
|
||||
# check for sys/cdefs.h
|
||||
|
||||
if test -n "${HAVE_SYS_CDEFS}" ; then
|
||||
echo "#define ${macro_prefix}HAVE_SYS_CDEFS ${HAVE_SYS_CDEFS}"
|
||||
else
|
||||
echo '#include <sys/cdefs.h>' >dummy.c
|
||||
echo 'extern int myfunc __P((int, int));' >>dummy.c
|
||||
if ${CC} -c dummy.c >/dev/null 2>&1 ; then
|
||||
echo "#define ${macro_prefix}HAVE_SYS_CDEFS 1"
|
||||
else
|
||||
echo "#define ${macro_prefix}HAVE_SYS_CDEFS 0"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check for a (Posix-compatible) sys/wait.h */
|
||||
|
||||
if test -n "${HAVE_SYS_WAIT}" ; then
|
||||
echo "#define ${macro_prefix}HAVE_SYS_WAIT ${HAVE_SYS_WAIT}"
|
||||
else
|
||||
cat >dummy.c <<!EOF!
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
int f() { int i; wait(&i); return i; }
|
||||
!EOF!
|
||||
if ${CC} -c dummy.c >/dev/null 2>&1 ; then
|
||||
echo "#define ${macro_prefix}HAVE_SYS_WAIT 1"
|
||||
else
|
||||
echo "#define ${macro_prefix}HAVE_SYS_WAIT 0"
|
||||
fi
|
||||
fi
|
||||
|
||||
if test -n "${HAVE_UNISTD}" ; then
|
||||
echo "#define ${macro_prefix}HAVE_UNISTD ${HAVE_UNISTD}"
|
||||
else
|
||||
echo '#include <unistd.h>' >dummy.c
|
||||
if ${CC} -c dummy.c >/dev/null 2>&1 ; then
|
||||
echo "#define ${macro_prefix}HAVE_UNISTD 1"
|
||||
else
|
||||
echo "#define ${macro_prefix}HAVE_UNISTD 0"
|
||||
fi
|
||||
fi
|
||||
|
||||
if test -n "${HAVE_DIRENT}" ; then
|
||||
echo "#define ${macro_prefix}HAVE_DIRENT ${HAVE_DIRENT}"
|
||||
else
|
||||
echo '#include <sys/types.h>
|
||||
#include <dirent.h>' >dummy.c
|
||||
if ${CC} -c dummy.c >/dev/null 2>&1 ; then
|
||||
echo "#define ${macro_prefix}HAVE_DIRENT 1"
|
||||
else
|
||||
echo "#define ${macro_prefix}HAVE_DIRENT 0"
|
||||
fi
|
||||
fi
|
||||
|
||||
if test -n "${HAVE_CURSES}" ; then
|
||||
echo "#define ${macro_prefix}HAVE_CURSES ${HAVE_CURSES}"
|
||||
else
|
||||
echo '#include <curses.h>' >dummy.c
|
||||
if ${CC} -c dummy.c >/dev/null 2>&1 ; then
|
||||
echo "#define ${macro_prefix}HAVE_CURSES 1"
|
||||
else
|
||||
echo "#define ${macro_prefix}HAVE_CURSES 0"
|
||||
fi
|
||||
fi
|
||||
|
||||
# There is no test for this at the moment; it is just set by the
|
||||
# configuration files.
|
||||
if test -n "${MATH_H_INLINES}" ; then
|
||||
echo "#define ${macro_prefix}MATH_H_INLINES ${MATH_H_INLINES}"
|
||||
else
|
||||
echo "#define ${macro_prefix}MATH_H_INLINES 0"
|
||||
fi
|
||||
|
||||
if test -n "${HAVE_BOOL}" ; then
|
||||
echo "#define ${macro_prefix}HAVE_BOOL ${HAVE_BOOL}"
|
||||
else
|
||||
echo 'bool i=true,j=false;' >dummy.C
|
||||
if ${CXX} -c dummy.C >/dev/null 2>&1 ; then
|
||||
echo "#define ${macro_prefix}HAVE_BOOL 1"
|
||||
else
|
||||
echo "#define ${macro_prefix}HAVE_BOOL 0"
|
||||
fi
|
||||
fi
|
||||
|
||||
if test -n "${NO_USE_DTOA}" ; then
|
||||
echo "#define ${macro_prefix}NO_USE_DTOA 1"
|
||||
fi
|
||||
if test -n "${USE_INT32_FLAGS}" ; then
|
||||
echo "#define ${macro_prefix}USE_INT32_FLAGS 1"
|
||||
fi
|
||||
|
||||
if test -n "$HAVE_PRINTF_FP"; then
|
||||
echo "#define ${macro_prefix}HAVE_PRINTF_FP $HAVE_PRINTF_FP"
|
||||
echo "#define ${macro_prefix}HAVE_LONG_DOUBLE_IO $HAVE_LONG_DOUBLE_IO"
|
||||
else
|
||||
# A little test program to check if __printf_fp is available.
|
||||
cat >dummy.c <<EOF
|
||||
int main()
|
||||
{
|
||||
return __printf_fp ();
|
||||
}
|
||||
EOF
|
||||
|
||||
if ${CC} dummy.c >/dev/null 2>&1 ; then
|
||||
echo "#define ${macro_prefix}HAVE_PRINTF_FP 1"
|
||||
echo "#define ${macro_prefix}HAVE_LONG_DOUBLE_IO 1"
|
||||
else
|
||||
echo "#define ${macro_prefix}HAVE_PRINTF_FP 0"
|
||||
echo "#define ${macro_prefix}HAVE_LONG_DOUBLE_IO 0"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Uncomment the following line if you don't have working templates.
|
||||
# echo "#define ${macro_prefix}NO_TEMPLATES"
|
||||
|
||||
# Override bogus definitions of NULL in system headers.
|
||||
cat <<EOF
|
||||
#undef NULL
|
||||
#define __need_NULL
|
||||
#include <stddef.h>
|
||||
EOF
|
||||
|
||||
rm -f dummy.C dummy.o dummy.c dummy.out TMP core a.out
|
||||
|
||||
echo "#endif /* !${macro_prefix}config_h */"
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 1993, 1995, 1997, 1998 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1993, 1995, 1997-1999, 2000 Free Software Foundation, Inc.
|
||||
This file is part of the GNU IO Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
@ -31,46 +31,63 @@
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _IO_MTSAFE_IO
|
||||
static _IO_lock_t list_all_lock = _IO_lock_initializer;
|
||||
#endif
|
||||
|
||||
void
|
||||
_IO_un_link (fp)
|
||||
_IO_FILE *fp;
|
||||
struct _IO_FILE_plus *fp;
|
||||
{
|
||||
if (fp->_flags & _IO_LINKED)
|
||||
if (fp->file._flags & _IO_LINKED)
|
||||
{
|
||||
_IO_FILE **f;
|
||||
for (f = &_IO_list_all; *f != NULL; f = &(*f)->_chain)
|
||||
struct _IO_FILE_plus **f;
|
||||
#ifdef _IO_MTSAFE_IO
|
||||
_IO_lock_lock (list_all_lock);
|
||||
#endif
|
||||
for (f = &_IO_list_all; *f != NULL; f = &(*f)->file._chain)
|
||||
{
|
||||
if (*f == fp)
|
||||
{
|
||||
*f = fp->_chain;
|
||||
*f = fp->file._chain;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fp->_flags &= ~_IO_LINKED;
|
||||
#ifdef _IO_MTSAFE_IO
|
||||
_IO_lock_unlock (list_all_lock);
|
||||
#endif
|
||||
fp->file._flags &= ~_IO_LINKED;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_IO_link_in (fp)
|
||||
_IO_FILE *fp;
|
||||
struct _IO_FILE_plus *fp;
|
||||
{
|
||||
if ((fp->_flags & _IO_LINKED) == 0)
|
||||
if ((fp->file._flags & _IO_LINKED) == 0)
|
||||
{
|
||||
fp->_flags |= _IO_LINKED;
|
||||
fp->_chain = _IO_list_all;
|
||||
fp->file._flags |= _IO_LINKED;
|
||||
#ifdef _IO_MTSAFE_IO
|
||||
_IO_lock_lock (list_all_lock);
|
||||
#endif
|
||||
fp->file._chain = _IO_list_all;
|
||||
_IO_list_all = fp;
|
||||
#ifdef _IO_MTSAFE_IO
|
||||
_IO_lock_unlock (list_all_lock);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* Return minimum _pos markers
|
||||
Assumes the current get area is the main get area. */
|
||||
static _IO_size_t _IO_least_marker __P ((_IO_FILE *fp));
|
||||
_IO_ssize_t _IO_least_marker __P ((_IO_FILE *fp, char *end_p));
|
||||
|
||||
static _IO_size_t
|
||||
_IO_least_marker (fp)
|
||||
_IO_ssize_t
|
||||
_IO_least_marker (fp, end_p)
|
||||
_IO_FILE *fp;
|
||||
char *end_p;
|
||||
{
|
||||
_IO_ssize_t least_so_far = fp->_IO_read_end - fp->_IO_read_base;
|
||||
_IO_ssize_t least_so_far = end_p - fp->_IO_read_base;
|
||||
struct _IO_marker *mark;
|
||||
for (mark = fp->_markers; mark != NULL; mark = mark->_next)
|
||||
if (mark->_pos < least_so_far)
|
||||
@ -94,7 +111,7 @@ _IO_switch_to_main_get_area (fp)
|
||||
tmp = fp->_IO_read_base;
|
||||
fp->_IO_read_base = fp->_IO_save_base;
|
||||
fp->_IO_save_base = tmp;
|
||||
|
||||
/* Set _IO_read_ptr. */
|
||||
fp->_IO_read_ptr = fp->_IO_read_base;
|
||||
}
|
||||
|
||||
@ -110,11 +127,11 @@ _IO_switch_to_backup_area (fp)
|
||||
tmp = fp->_IO_read_end;
|
||||
fp->_IO_read_end = fp->_IO_save_end;
|
||||
fp->_IO_save_end = tmp;
|
||||
/* Swap _gbase and _IO_save_base. */
|
||||
/* Swap _IO_read_base and _IO_save_base. */
|
||||
tmp = fp->_IO_read_base;
|
||||
fp->_IO_read_base = fp->_IO_save_base;
|
||||
fp->_IO_save_base = tmp;
|
||||
|
||||
/* Set _IO_read_ptr. */
|
||||
fp->_IO_read_ptr = fp->_IO_read_end;
|
||||
}
|
||||
|
||||
@ -180,19 +197,28 @@ __overflow (f, ch)
|
||||
return _IO_OVERFLOW (f, ch);
|
||||
}
|
||||
|
||||
static int save_for_backup __P ((_IO_FILE *fp));
|
||||
static int save_for_backup __P ((_IO_FILE *fp, char *end_p))
|
||||
#ifdef _LIBC
|
||||
internal_function
|
||||
#endif
|
||||
;
|
||||
|
||||
static int
|
||||
save_for_backup (fp)
|
||||
static int
|
||||
#ifdef _LIBC
|
||||
internal_function
|
||||
#endif
|
||||
save_for_backup (fp, end_p)
|
||||
_IO_FILE *fp;
|
||||
char *end_p;
|
||||
{
|
||||
/* Append [_IO_read_base.._IO_read_end] to backup area. */
|
||||
int least_mark = _IO_least_marker (fp);
|
||||
/* Append [_IO_read_base..end_p] to backup area. */
|
||||
_IO_ssize_t least_mark = _IO_least_marker (fp, end_p);
|
||||
/* needed_size is how much space we need in the backup area. */
|
||||
int needed_size = (fp->_IO_read_end - fp->_IO_read_base) - least_mark;
|
||||
int current_Bsize = fp->_IO_save_end - fp->_IO_save_base;
|
||||
int avail; /* Extra space available for future expansion. */
|
||||
int delta;
|
||||
_IO_size_t needed_size = (end_p - fp->_IO_read_base) - least_mark;
|
||||
/* FIXME: Dubious arithmetic if pointers are NULL */
|
||||
_IO_size_t current_Bsize = fp->_IO_save_end - fp->_IO_save_base;
|
||||
_IO_size_t avail; /* Extra space available for future expansion. */
|
||||
_IO_ssize_t delta;
|
||||
struct _IO_marker *mark;
|
||||
if (needed_size > current_Bsize)
|
||||
{
|
||||
@ -203,12 +229,20 @@ save_for_backup (fp)
|
||||
return EOF; /* FIXME */
|
||||
if (least_mark < 0)
|
||||
{
|
||||
#ifdef _LIBC
|
||||
__mempcpy (__mempcpy (new_buffer + avail,
|
||||
fp->_IO_save_end + least_mark,
|
||||
-least_mark),
|
||||
fp->_IO_read_base,
|
||||
end_p - fp->_IO_read_base);
|
||||
#else
|
||||
memcpy (new_buffer + avail,
|
||||
fp->_IO_save_end + least_mark,
|
||||
-least_mark);
|
||||
memcpy (new_buffer + avail - least_mark,
|
||||
fp->_IO_read_base,
|
||||
fp->_IO_read_end - fp->_IO_read_base);
|
||||
end_p - fp->_IO_read_base);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
memcpy (new_buffer + avail,
|
||||
@ -229,17 +263,16 @@ save_for_backup (fp)
|
||||
-least_mark);
|
||||
memcpy (fp->_IO_save_base + avail - least_mark,
|
||||
fp->_IO_read_base,
|
||||
fp->_IO_read_end - fp->_IO_read_base);
|
||||
end_p - fp->_IO_read_base);
|
||||
}
|
||||
else if (needed_size > 0)
|
||||
memcpy (fp->_IO_save_base + avail,
|
||||
fp->_IO_read_base + least_mark,
|
||||
needed_size);
|
||||
}
|
||||
/* FIXME: Dubious arithmetic if pointers are NULL */
|
||||
fp->_IO_backup_base = fp->_IO_save_base + avail;
|
||||
/* Adjust all the streammarkers. */
|
||||
delta = fp->_IO_read_end - fp->_IO_read_base;
|
||||
delta = end_p - fp->_IO_read_base;
|
||||
for (mark = fp->_markers; mark != NULL; mark = mark->_next)
|
||||
mark->_pos -= delta;
|
||||
return 0;
|
||||
@ -249,6 +282,11 @@ int
|
||||
__underflow (fp)
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
|
||||
if (fp->_vtable_offset == 0 && _IO_fwide (fp, -1) != -1)
|
||||
return EOF;
|
||||
#endif
|
||||
|
||||
if (_IO_in_put_mode (fp))
|
||||
if (_IO_switch_to_get_mode (fp) == EOF)
|
||||
return EOF;
|
||||
@ -262,7 +300,7 @@ __underflow (fp)
|
||||
}
|
||||
if (_IO_have_markers (fp))
|
||||
{
|
||||
if (save_for_backup (fp))
|
||||
if (save_for_backup (fp, fp->_IO_read_end))
|
||||
return EOF;
|
||||
}
|
||||
else if (_IO_have_backup (fp))
|
||||
@ -274,6 +312,11 @@ int
|
||||
__uflow (fp)
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
|
||||
if (fp->_vtable_offset == 0 && _IO_fwide (fp, -1) != -1)
|
||||
return EOF;
|
||||
#endif
|
||||
|
||||
if (_IO_in_put_mode (fp))
|
||||
if (_IO_switch_to_get_mode (fp) == EOF)
|
||||
return EOF;
|
||||
@ -287,7 +330,7 @@ __uflow (fp)
|
||||
}
|
||||
if (_IO_have_markers (fp))
|
||||
{
|
||||
if (save_for_backup (fp))
|
||||
if (save_for_backup (fp, fp->_IO_read_end))
|
||||
return EOF;
|
||||
}
|
||||
else if (_IO_have_backup (fp))
|
||||
@ -361,9 +404,13 @@ _IO_default_xsputn (f, data, n)
|
||||
count = more;
|
||||
if (count > 20)
|
||||
{
|
||||
#ifdef _LIBC
|
||||
f->_IO_write_ptr = __mempcpy (f->_IO_write_ptr, s, count);
|
||||
#else
|
||||
memcpy (f->_IO_write_ptr, s, count);
|
||||
s += count;
|
||||
f->_IO_write_ptr += count;
|
||||
#endif
|
||||
s += count;
|
||||
}
|
||||
else if (count <= 0)
|
||||
count = 0;
|
||||
@ -377,7 +424,7 @@ _IO_default_xsputn (f, data, n)
|
||||
}
|
||||
more -= count;
|
||||
}
|
||||
if (more == 0 || __overflow (f, (unsigned char) *s++) == EOF)
|
||||
if (more == 0 || _IO_OVERFLOW (f, (unsigned char) *s++) == EOF)
|
||||
break;
|
||||
more--;
|
||||
}
|
||||
@ -412,8 +459,12 @@ _IO_default_xsgetn (fp, data, n)
|
||||
count = more;
|
||||
if (count > 20)
|
||||
{
|
||||
#ifdef _LIBC
|
||||
s = __mempcpy (s, fp->_IO_read_ptr, count);
|
||||
#else
|
||||
memcpy (s, fp->_IO_read_ptr, count);
|
||||
s += count;
|
||||
#endif
|
||||
fp->_IO_read_ptr += count;
|
||||
}
|
||||
else if (count <= 0)
|
||||
@ -467,24 +518,15 @@ _IO_default_setbuf (fp, p, len)
|
||||
return fp;
|
||||
}
|
||||
|
||||
#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
||||
_IO_off64_t
|
||||
_IO_default_seekpos (fp, pos, mode)
|
||||
_IO_FILE *fp;
|
||||
_IO_off64_t pos;
|
||||
int mode;
|
||||
#else
|
||||
_IO_off_t
|
||||
_IO_default_seekpos (fp, pos, mode)
|
||||
_IO_FILE *fp;
|
||||
_IO_off_t pos;
|
||||
int mode;
|
||||
#endif
|
||||
{
|
||||
return _IO_SEEKOFF (fp, pos, 0, mode);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
_IO_default_doallocate (fp)
|
||||
_IO_FILE *fp;
|
||||
@ -500,6 +542,17 @@ void
|
||||
_IO_init (fp, flags)
|
||||
_IO_FILE *fp;
|
||||
int flags;
|
||||
{
|
||||
_IO_no_init (fp, flags, -1, NULL, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
_IO_no_init (fp, flags, orientation, wd, jmp)
|
||||
_IO_FILE *fp;
|
||||
int flags;
|
||||
int orientation;
|
||||
struct _IO_wide_data *wd;
|
||||
struct _IO_jump_t *jmp;
|
||||
{
|
||||
fp->_flags = _IO_MAGIC|flags;
|
||||
fp->_IO_buf_base = NULL;
|
||||
@ -517,8 +570,31 @@ _IO_init (fp, flags)
|
||||
fp->_IO_save_end = NULL;
|
||||
fp->_markers = NULL;
|
||||
fp->_cur_column = 0;
|
||||
#if _IO_JUMPS_OFFSET
|
||||
fp->_vtable_offset = 0;
|
||||
#endif
|
||||
#ifdef _IO_MTSAFE_IO
|
||||
_IO_lock_init (*fp->_lock);
|
||||
#endif
|
||||
fp->_mode = orientation;
|
||||
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
|
||||
if (orientation >= 0)
|
||||
{
|
||||
fp->_wide_data = wd;
|
||||
fp->_wide_data->_IO_buf_base = NULL;
|
||||
fp->_wide_data->_IO_buf_end = NULL;
|
||||
fp->_wide_data->_IO_read_base = NULL;
|
||||
fp->_wide_data->_IO_read_ptr = NULL;
|
||||
fp->_wide_data->_IO_read_end = NULL;
|
||||
fp->_wide_data->_IO_write_base = NULL;
|
||||
fp->_wide_data->_IO_write_ptr = NULL;
|
||||
fp->_wide_data->_IO_write_end = NULL;
|
||||
fp->_wide_data->_IO_save_base = NULL;
|
||||
fp->_wide_data->_IO_backup_base = NULL;
|
||||
fp->_wide_data->_IO_save_end = NULL;
|
||||
|
||||
fp->_wide_data->_wide_vtable = jmp;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -557,24 +633,15 @@ _IO_default_finish (fp, dummy)
|
||||
_IO_lock_fini (*fp->_lock);
|
||||
#endif
|
||||
|
||||
_IO_un_link (fp);
|
||||
_IO_un_link ((struct _IO_FILE_plus *) fp);
|
||||
}
|
||||
|
||||
#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
||||
_IO_off64_t
|
||||
_IO_default_seekoff (fp, offset, dir, mode)
|
||||
_IO_FILE *fp;
|
||||
_IO_off64_t offset;
|
||||
int dir;
|
||||
int mode;
|
||||
#else
|
||||
_IO_off_t
|
||||
_IO_default_seekoff (fp, offset, dir, mode)
|
||||
_IO_FILE *fp;
|
||||
_IO_off_t offset;
|
||||
int dir;
|
||||
int mode;
|
||||
#endif
|
||||
{
|
||||
return _IO_pos_BAD;
|
||||
}
|
||||
@ -678,10 +745,17 @@ int
|
||||
_IO_flush_all ()
|
||||
{
|
||||
int result = 0;
|
||||
_IO_FILE *fp;
|
||||
for (fp = _IO_list_all; fp != NULL; fp = fp->_chain)
|
||||
if (fp->_IO_write_ptr > fp->_IO_write_base
|
||||
&& _IO_OVERFLOW (fp, EOF) == EOF)
|
||||
struct _IO_FILE_plus *fp;
|
||||
for (fp = _IO_list_all; fp != NULL; fp = fp->file._chain)
|
||||
if (((fp->file._mode < 0 && fp->file._IO_write_ptr > fp->file._IO_write_base)
|
||||
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
|
||||
|
||||
|| (fp->file._vtable_offset == 0
|
||||
&& fp->file._mode > 0 && (fp->file._wide_data->_IO_write_ptr
|
||||
> fp->file._wide_data->_IO_write_base))
|
||||
#endif
|
||||
)
|
||||
&& _IO_OVERFLOW (&fp->file, EOF) == EOF)
|
||||
result = EOF;
|
||||
return result;
|
||||
}
|
||||
@ -689,27 +763,29 @@ _IO_flush_all ()
|
||||
void
|
||||
_IO_flush_all_linebuffered ()
|
||||
{
|
||||
_IO_FILE *fp;
|
||||
for (fp = _IO_list_all; fp != NULL; fp = fp->_chain)
|
||||
if ((fp->_flags & _IO_NO_WRITES) == 0 && fp->_flags & _IO_LINE_BUF)
|
||||
_IO_OVERFLOW (fp, EOF);
|
||||
struct _IO_FILE_plus *fp;
|
||||
for (fp = _IO_list_all; fp != NULL; fp = fp->file._chain)
|
||||
if ((fp->file._flags & _IO_NO_WRITES) == 0 && fp->file._flags & _IO_LINE_BUF)
|
||||
_IO_OVERFLOW (&fp->file, EOF);
|
||||
}
|
||||
|
||||
static void _IO_unbuffer_all __P ((void));
|
||||
static void _IO_unbuffer_write __P ((void));
|
||||
|
||||
static void
|
||||
_IO_unbuffer_all ()
|
||||
_IO_unbuffer_write ()
|
||||
{
|
||||
_IO_FILE *fp;
|
||||
for (fp = _IO_list_all; fp != NULL; fp = fp->_chain)
|
||||
if (! (fp->_flags & _IO_UNBUFFERED))
|
||||
_IO_SETBUF (fp, NULL, 0);
|
||||
struct _IO_FILE_plus *fp;
|
||||
for (fp = _IO_list_all; fp != NULL; fp = fp->file._chain)
|
||||
if (! (fp->file._flags & _IO_UNBUFFERED)
|
||||
&& (! (fp->file._flags & _IO_NO_WRITES)
|
||||
|| (fp->file._flags & _IO_IS_APPENDING)))
|
||||
_IO_SETBUF (&fp->file, NULL, 0);
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
_IO_cleanup ()
|
||||
{
|
||||
_IO_flush_all ();
|
||||
int result = _IO_flush_all ();
|
||||
|
||||
/* We currently don't have a reliable mechanism for making sure that
|
||||
C++ static destructors are executed in the correct order.
|
||||
@ -718,9 +794,12 @@ _IO_cleanup ()
|
||||
|
||||
The following will make the standard streambufs be unbuffered,
|
||||
which forces any output from late destructors to be written out. */
|
||||
_IO_unbuffer_all ();
|
||||
_IO_unbuffer_write ();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_IO_init_marker (marker, fp)
|
||||
struct _IO_marker *marker;
|
||||
@ -857,23 +936,34 @@ _IO_default_pbackfail (fp, c)
|
||||
_IO_FILE *fp;
|
||||
int c;
|
||||
{
|
||||
if (fp->_IO_read_ptr <= fp->_IO_read_base)
|
||||
if (fp->_IO_read_ptr > fp->_IO_read_base && !_IO_in_backup (fp)
|
||||
&& (unsigned char) fp->_IO_read_ptr[-1] == c)
|
||||
--fp->_IO_read_ptr;
|
||||
else
|
||||
{
|
||||
/* Need to handle a filebuf in write mode (switch to read mode). FIXME!*/
|
||||
if (_IO_have_backup (fp) && !_IO_in_backup (fp))
|
||||
_IO_switch_to_backup_area (fp);
|
||||
|
||||
if (!_IO_have_backup (fp))
|
||||
if (!_IO_in_backup (fp))
|
||||
{
|
||||
/* No backup buffer: allocate one. */
|
||||
/* Use nshort buffer, if unused? (probably not) FIXME */
|
||||
int backup_size = 128;
|
||||
char *bbuf = (char *) malloc (backup_size);
|
||||
if (bbuf == NULL)
|
||||
return EOF;
|
||||
fp->_IO_save_base = bbuf;
|
||||
fp->_IO_save_end = fp->_IO_save_base + backup_size;
|
||||
fp->_IO_backup_base = fp->_IO_save_end;
|
||||
/* We need to keep the invariant that the main get area
|
||||
logically follows the backup area. */
|
||||
if (fp->_IO_read_ptr > fp->_IO_read_base && _IO_have_backup (fp))
|
||||
{
|
||||
if (save_for_backup (fp, fp->_IO_read_ptr))
|
||||
return EOF;
|
||||
}
|
||||
else if (!_IO_have_backup (fp))
|
||||
{
|
||||
/* No backup buffer: allocate one. */
|
||||
/* Use nshort buffer, if unused? (probably not) FIXME */
|
||||
int backup_size = 128;
|
||||
char *bbuf = (char *) malloc (backup_size);
|
||||
if (bbuf == NULL)
|
||||
return EOF;
|
||||
fp->_IO_save_base = bbuf;
|
||||
fp->_IO_save_end = fp->_IO_save_base + backup_size;
|
||||
fp->_IO_backup_base = fp->_IO_save_end;
|
||||
}
|
||||
fp->_IO_read_base = fp->_IO_read_ptr;
|
||||
_IO_switch_to_backup_area (fp);
|
||||
}
|
||||
else if (fp->_IO_read_ptr <= fp->_IO_read_base)
|
||||
@ -893,26 +983,17 @@ _IO_default_pbackfail (fp, c)
|
||||
new_buf + new_size);
|
||||
fp->_IO_backup_base = fp->_IO_read_ptr;
|
||||
}
|
||||
|
||||
*--fp->_IO_read_ptr = c;
|
||||
}
|
||||
--fp->_IO_read_ptr;
|
||||
if (c != EOF && *fp->_IO_read_ptr != c)
|
||||
*fp->_IO_read_ptr = c;
|
||||
return (unsigned char) *fp->_IO_read_ptr;
|
||||
return (unsigned char) c;
|
||||
}
|
||||
|
||||
#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
||||
_IO_off64_t
|
||||
_IO_default_seek (fp, offset, dir)
|
||||
_IO_FILE *fp;
|
||||
_IO_off64_t offset;
|
||||
int dir;
|
||||
#else
|
||||
_IO_off_t
|
||||
_IO_default_seek (fp, offset, dir)
|
||||
_IO_FILE *fp;
|
||||
_IO_off_t offset;
|
||||
int dir;
|
||||
#endif
|
||||
{
|
||||
return _IO_pos_BAD;
|
||||
}
|
||||
@ -943,6 +1024,70 @@ _IO_default_write (fp, data, n)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
_IO_default_showmanyc (fp)
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
_IO_default_imbue (fp, locale)
|
||||
_IO_FILE *fp;
|
||||
void *locale;
|
||||
{
|
||||
}
|
||||
|
||||
_IO_ITER
|
||||
_IO_iter_begin()
|
||||
{
|
||||
return _IO_list_all;
|
||||
}
|
||||
|
||||
_IO_ITER
|
||||
_IO_iter_end()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
_IO_ITER
|
||||
_IO_iter_next(iter)
|
||||
_IO_ITER iter;
|
||||
{
|
||||
return iter->file._chain;
|
||||
}
|
||||
|
||||
_IO_FILE *
|
||||
_IO_iter_file(iter)
|
||||
_IO_ITER iter;
|
||||
{
|
||||
return (_IO_FILE *) iter;
|
||||
}
|
||||
|
||||
void
|
||||
_IO_list_lock()
|
||||
{
|
||||
#ifdef _IO_MTSAFE_IO
|
||||
_IO_lock_lock (list_all_lock);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
_IO_list_unlock()
|
||||
{
|
||||
#ifdef _IO_MTSAFE_IO
|
||||
_IO_lock_unlock (list_all_lock);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
_IO_list_resetlock()
|
||||
{
|
||||
#ifdef _IO_MTSAFE_IO
|
||||
_IO_lock_init (list_all_lock);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifdef TODO
|
||||
#if defined(linux)
|
||||
@ -963,8 +1108,6 @@ __io_defs io_defs__;
|
||||
|
||||
#ifdef weak_alias
|
||||
weak_alias (_IO_cleanup, _cleanup)
|
||||
#elif defined(_G_STDIO_USES_LIBIO) && defined(_G_HAVE_WEAK_SYMBOL)
|
||||
void _cleanup () __attribute__ ((weak, alias ("_IO_cleanup")));
|
||||
#endif
|
||||
|
||||
#ifdef text_set_element
|
||||
|
472
libstdc++-v3/libio/iofwide.c
Normal file
472
libstdc++-v3/libio/iofwide.c
Normal file
@ -0,0 +1,472 @@
|
||||
/* Copyright (C) 1999, 2000 Free Software Foundation, Inc.
|
||||
This file is part of the GNU IO Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2, or (at
|
||||
your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this library; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does
|
||||
not cause the resulting executable to be covered by the GNU General
|
||||
Public License. This exception does not however invalidate any
|
||||
other reasons why the executable file might be covered by the GNU
|
||||
General Public License. */
|
||||
|
||||
#include <libioP.h>
|
||||
#ifdef _LIBC
|
||||
# include <dlfcn.h>
|
||||
# include <wchar.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _LIBC
|
||||
# include <langinfo.h>
|
||||
# include <locale/localeinfo.h>
|
||||
# include <wcsmbs/wcsmbsload.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* Prototypes of libio's codecvt functions. */
|
||||
static enum __codecvt_result do_out (struct _IO_codecvt *codecvt,
|
||||
__mbstate_t *statep,
|
||||
const wchar_t *from_start,
|
||||
const wchar_t *from_end,
|
||||
const wchar_t **from_stop, char *to_start,
|
||||
char *to_end, char **to_stop);
|
||||
static enum __codecvt_result do_unshift (struct _IO_codecvt *codecvt,
|
||||
__mbstate_t *statep, char *to_start,
|
||||
char *to_end, char **to_stop);
|
||||
static enum __codecvt_result do_in (struct _IO_codecvt *codecvt,
|
||||
__mbstate_t *statep,
|
||||
const char *from_start,
|
||||
const char *from_end,
|
||||
const char **from_stop, wchar_t *to_start,
|
||||
wchar_t *to_end, wchar_t **to_stop);
|
||||
static int do_encoding (struct _IO_codecvt *codecvt);
|
||||
static int do_length (struct _IO_codecvt *codecvt, __mbstate_t *statep,
|
||||
const char *from_start,
|
||||
const char *from_end, _IO_size_t max);
|
||||
static int do_max_length (struct _IO_codecvt *codecvt);
|
||||
static int do_always_noconv (struct _IO_codecvt *codecvt);
|
||||
|
||||
|
||||
/* The functions used in `codecvt' for libio are always the same. */
|
||||
struct _IO_codecvt __libio_codecvt =
|
||||
{
|
||||
.__codecvt_destr = NULL, /* Destructor, never used. */
|
||||
.__codecvt_do_out = do_out,
|
||||
.__codecvt_do_unshift = do_unshift,
|
||||
.__codecvt_do_in = do_in,
|
||||
.__codecvt_do_encoding = do_encoding,
|
||||
.__codecvt_do_always_noconv = do_always_noconv,
|
||||
.__codecvt_do_length = do_length,
|
||||
.__codecvt_do_max_length = do_max_length
|
||||
};
|
||||
|
||||
|
||||
/* Return orientation of stream. If mode is nonzero try to change
|
||||
the orientation first. */
|
||||
#undef _IO_fwide
|
||||
int
|
||||
_IO_fwide (fp, mode)
|
||||
_IO_FILE *fp;
|
||||
int mode;
|
||||
{
|
||||
/* Normalize the value. */
|
||||
mode = mode < 0 ? -1 : (mode == 0 ? 0 : 1);
|
||||
|
||||
if (mode == 0 || fp->_mode != 0)
|
||||
/* The caller simply wants to know about the current orientation
|
||||
or the orientation already has been determined. */
|
||||
return fp->_mode;
|
||||
|
||||
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
|
||||
_IO_flockfile (fp);
|
||||
|
||||
/* Set the orientation appropriately. */
|
||||
if (mode > 0)
|
||||
{
|
||||
struct _IO_codecvt *cc = &fp->_wide_data->_codecvt;
|
||||
|
||||
fp->_wide_data->_IO_read_ptr = fp->_wide_data->_IO_read_end;
|
||||
fp->_wide_data->_IO_write_ptr = fp->_wide_data->_IO_write_base;
|
||||
|
||||
/* The functions are always the same. */
|
||||
*cc = __libio_codecvt;
|
||||
|
||||
/* Get the character conversion functions based on the currently
|
||||
selected locale for LC_CTYPE. */
|
||||
#ifdef _LIBC
|
||||
{
|
||||
struct gconv_fcts fcts;
|
||||
|
||||
/* Clear the state. We start all over again. */
|
||||
memset (&fp->_wide_data->_IO_state, '\0', sizeof (__mbstate_t));
|
||||
memset (&fp->_wide_data->_IO_last_state, '\0', sizeof (__mbstate_t));
|
||||
|
||||
__wcsmbs_clone_conv (&fcts);
|
||||
|
||||
cc->__cd_in.__cd.__nsteps = 1; /* Only one step allowed. */
|
||||
cc->__cd_in.__cd.__steps = fcts.towc;
|
||||
|
||||
cc->__cd_in.__cd.__data[0].__invocation_counter = 0;
|
||||
cc->__cd_in.__cd.__data[0].__internal_use = 1;
|
||||
cc->__cd_in.__cd.__data[0].__flags = __GCONV_IS_LAST;
|
||||
cc->__cd_in.__cd.__data[0].__statep = &fp->_wide_data->_IO_state;
|
||||
|
||||
/* XXX For now no transliteration. */
|
||||
cc->__cd_in.__cd.__data[0].__trans = NULL;
|
||||
|
||||
cc->__cd_out.__cd.__nsteps = 1; /* Only one step allowed. */
|
||||
cc->__cd_out.__cd.__steps = fcts.tomb;
|
||||
|
||||
cc->__cd_out.__cd.__data[0].__invocation_counter = 0;
|
||||
cc->__cd_out.__cd.__data[0].__internal_use = 1;
|
||||
cc->__cd_out.__cd.__data[0].__flags = __GCONV_IS_LAST;
|
||||
cc->__cd_out.__cd.__data[0].__statep = &fp->_wide_data->_IO_state;
|
||||
|
||||
/* XXX For now no transliteration. */
|
||||
cc->__cd_out.__cd.__data[0].__trans = NULL;
|
||||
}
|
||||
#else
|
||||
# ifdef _GLIBCPP_USE_WCHAR_T
|
||||
{
|
||||
/* Determine internal and external character sets.
|
||||
|
||||
XXX For now we make our life easy: we assume a fixed internal
|
||||
encoding (as most sane systems have; hi HP/UX!). If somebody
|
||||
cares about systems which changing internal charsets they
|
||||
should come up with a solution for the determination of the
|
||||
currently used internal character set. */
|
||||
const char *internal_ccs = _G_INTERNAL_CCS;
|
||||
const char *external_ccs = NULL;
|
||||
|
||||
# ifdef HAVE_NL_LANGINFO
|
||||
external_ccs = nl_langinfo (CODESET);
|
||||
# endif
|
||||
if (external_ccs == NULL)
|
||||
external_ccs = "ISO-8859-1";
|
||||
|
||||
cc->__cd_in = iconv_open (internal_ccs, external_ccs);
|
||||
if (cc->__cd_in != (iconv_t) -1)
|
||||
cc->__cd_out = iconv_open (external_ccs, internal_ccs);
|
||||
|
||||
if (cc->__cd_in != (iconv_t) -1 || cc->__cd_out != (iconv_t) -1)
|
||||
/* XXX */
|
||||
abort ();
|
||||
}
|
||||
# else
|
||||
# error "somehow determine this from LC_CTYPE"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* From now on use the wide character callback functions. */
|
||||
((struct _IO_FILE_plus *) fp)->vtable = fp->_wide_data->_wide_vtable;
|
||||
}
|
||||
|
||||
/* Set the mode now. */
|
||||
fp->_mode = mode;
|
||||
|
||||
_IO_funlockfile (fp);
|
||||
_IO_cleanup_region_end (0);
|
||||
|
||||
return mode;
|
||||
}
|
||||
|
||||
#ifdef weak_alias
|
||||
weak_alias (_IO_fwide, fwide)
|
||||
#endif
|
||||
|
||||
|
||||
static enum __codecvt_result
|
||||
do_out (struct _IO_codecvt *codecvt, __mbstate_t *statep,
|
||||
const wchar_t *from_start, const wchar_t *from_end,
|
||||
const wchar_t **from_stop, char *to_start, char *to_end,
|
||||
char **to_stop)
|
||||
{
|
||||
enum __codecvt_result result;
|
||||
|
||||
#ifdef _LIBC
|
||||
struct __gconv_step *gs = codecvt->__cd_out.__cd.__steps;
|
||||
int status;
|
||||
size_t dummy;
|
||||
const unsigned char *from_start_copy = (unsigned char *) from_start;
|
||||
|
||||
codecvt->__cd_out.__cd.__data[0].__outbuf = to_start;
|
||||
codecvt->__cd_out.__cd.__data[0].__outbufend = to_end;
|
||||
codecvt->__cd_out.__cd.__data[0].__statep = statep;
|
||||
|
||||
status = DL_CALL_FCT (gs->__fct,
|
||||
(gs, codecvt->__cd_out.__cd.__data, &from_start_copy,
|
||||
(const unsigned char *) from_end, NULL,
|
||||
&dummy, 0, 0));
|
||||
|
||||
*from_stop = (wchar_t *) from_start_copy;
|
||||
*to_stop = codecvt->__cd_out.__cd.__data[0].__outbuf;
|
||||
|
||||
switch (status)
|
||||
{
|
||||
case __GCONV_OK:
|
||||
case __GCONV_EMPTY_INPUT:
|
||||
result = __codecvt_ok;
|
||||
break;
|
||||
|
||||
case __GCONV_FULL_OUTPUT:
|
||||
case __GCONV_INCOMPLETE_INPUT:
|
||||
result = __codecvt_partial;
|
||||
break;
|
||||
|
||||
default:
|
||||
result = __codecvt_error;
|
||||
break;
|
||||
}
|
||||
#else
|
||||
# ifdef _GLIBCPP_USE_WCHAR_T
|
||||
size_t res;
|
||||
const char *from_start_copy = (const char *) from_start;
|
||||
size_t from_len = from_end - from_start;
|
||||
char *to_start_copy = (char *) from_start;
|
||||
size_t to_len = to_end - to_start;
|
||||
|
||||
res = iconv (codecvt->__cd_out, &from_start_copy, &from_len,
|
||||
&to_start_copy, &to_len);
|
||||
|
||||
if (res == 0 || from_len == 0)
|
||||
result = __codecvt_ok;
|
||||
else if (to_len < codecvt->__codecvt_do_max_length (codecvt))
|
||||
result = __codecvt_partial;
|
||||
else
|
||||
result = __codecvt_error;
|
||||
# else
|
||||
/* Decide what to do. */
|
||||
result = __codecvt_error;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static enum __codecvt_result
|
||||
do_unshift (struct _IO_codecvt *codecvt, __mbstate_t *statep,
|
||||
char *to_start, char *to_end, char **to_stop)
|
||||
{
|
||||
enum __codecvt_result result;
|
||||
|
||||
#ifdef _LIBC
|
||||
struct __gconv_step *gs = codecvt->__cd_out.__cd.__steps;
|
||||
int status;
|
||||
size_t dummy;
|
||||
|
||||
codecvt->__cd_out.__cd.__data[0].__outbuf = to_start;
|
||||
codecvt->__cd_out.__cd.__data[0].__outbufend = to_end;
|
||||
codecvt->__cd_out.__cd.__data[0].__statep = statep;
|
||||
|
||||
status = DL_CALL_FCT (gs->__fct,
|
||||
(gs, codecvt->__cd_out.__cd.__data, NULL, NULL,
|
||||
NULL, &dummy, 1, 0));
|
||||
|
||||
*to_stop = codecvt->__cd_out.__cd.__data[0].__outbuf;
|
||||
|
||||
switch (status)
|
||||
{
|
||||
case __GCONV_OK:
|
||||
case __GCONV_EMPTY_INPUT:
|
||||
result = __codecvt_ok;
|
||||
break;
|
||||
|
||||
case __GCONV_FULL_OUTPUT:
|
||||
case __GCONV_INCOMPLETE_INPUT:
|
||||
result = __codecvt_partial;
|
||||
break;
|
||||
|
||||
default:
|
||||
result = __codecvt_error;
|
||||
break;
|
||||
}
|
||||
#else
|
||||
# ifdef _GLIBCPP_USE_WCHAR_T
|
||||
size_t res;
|
||||
char *to_start_copy = (char *) to_start;
|
||||
size_t to_len = to_end - to_start;
|
||||
|
||||
res = iconv (codecvt->__cd_out, NULL, NULL, &to_start_copy, &to_len);
|
||||
|
||||
if (res == 0)
|
||||
result = __codecvt_ok;
|
||||
else if (to_len < codecvt->__codecvt_do_max_length (codecvt))
|
||||
result = __codecvt_partial;
|
||||
else
|
||||
result = __codecvt_error;
|
||||
# else
|
||||
/* Decide what to do. */
|
||||
result = __codecvt_error;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static enum __codecvt_result
|
||||
do_in (struct _IO_codecvt *codecvt, __mbstate_t *statep,
|
||||
const char *from_start, const char *from_end, const char **from_stop,
|
||||
wchar_t *to_start, wchar_t *to_end, wchar_t **to_stop)
|
||||
{
|
||||
enum __codecvt_result result;
|
||||
|
||||
#ifdef _LIBC
|
||||
struct __gconv_step *gs = codecvt->__cd_in.__cd.__steps;
|
||||
int status;
|
||||
size_t dummy;
|
||||
const unsigned char *from_start_copy = (unsigned char *) from_start;
|
||||
|
||||
codecvt->__cd_in.__cd.__data[0].__outbuf = (char *) to_start;
|
||||
codecvt->__cd_in.__cd.__data[0].__outbufend = (char *) to_end;
|
||||
codecvt->__cd_in.__cd.__data[0].__statep = statep;
|
||||
|
||||
status = DL_CALL_FCT (gs->__fct,
|
||||
(gs, codecvt->__cd_in.__cd.__data, &from_start_copy,
|
||||
from_end, NULL, &dummy, 0, 0));
|
||||
|
||||
*from_stop = from_start_copy;
|
||||
*to_stop = (wchar_t *) codecvt->__cd_in.__cd.__data[0].__outbuf;
|
||||
|
||||
switch (status)
|
||||
{
|
||||
case __GCONV_OK:
|
||||
case __GCONV_EMPTY_INPUT:
|
||||
result = __codecvt_ok;
|
||||
break;
|
||||
|
||||
case __GCONV_FULL_OUTPUT:
|
||||
case __GCONV_INCOMPLETE_INPUT:
|
||||
result = __codecvt_partial;
|
||||
break;
|
||||
|
||||
default:
|
||||
result = __codecvt_error;
|
||||
break;
|
||||
}
|
||||
#else
|
||||
# ifdef _GLIBCPP_USE_WCHAR_T
|
||||
size_t res;
|
||||
const char *from_start_copy = (const char *) from_start;
|
||||
size_t from_len = from_end - from_start;
|
||||
char *to_start_copy = (char *) from_start;
|
||||
size_t to_len = to_end - to_start;
|
||||
|
||||
res = iconv (codecvt->__cd_in, &from_start_copy, &from_len,
|
||||
&to_start_copy, &to_len);
|
||||
|
||||
if (res == 0)
|
||||
result = __codecvt_ok;
|
||||
else if (to_len == 0)
|
||||
result = __codecvt_partial;
|
||||
else if (from_len < codecvt->__codecvt_do_max_length (codecvt))
|
||||
result = __codecvt_partial;
|
||||
else
|
||||
result = __codecvt_error;
|
||||
# else
|
||||
/* Decide what to do. */
|
||||
result = __codecvt_error;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
do_encoding (struct _IO_codecvt *codecvt)
|
||||
{
|
||||
#ifdef _LIBC
|
||||
/* See whether the encoding is stateful. */
|
||||
if (codecvt->__cd_in.__cd.__steps[0].__stateful)
|
||||
return -1;
|
||||
/* Fortunately not. Now determine the input bytes for the conversion
|
||||
necessary for each wide character. */
|
||||
if (codecvt->__cd_in.__cd.__steps[0].__min_needed_from
|
||||
!= codecvt->__cd_in.__cd.__steps[0].__max_needed_from)
|
||||
/* Not a constant value. */
|
||||
return 0;
|
||||
|
||||
return codecvt->__cd_in.__cd.__steps[0].__min_needed_from;
|
||||
#else
|
||||
/* Worst case scenario. */
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
do_always_noconv (struct _IO_codecvt *codecvt)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
do_length (struct _IO_codecvt *codecvt, __mbstate_t *statep,
|
||||
const char *from_start, const char *from_end, _IO_size_t max)
|
||||
{
|
||||
int result;
|
||||
#ifdef _LIBC
|
||||
const unsigned char *cp = (const unsigned char *) from_start;
|
||||
wchar_t to_buf[max];
|
||||
struct __gconv_step *gs = codecvt->__cd_in.__cd.__steps;
|
||||
int status;
|
||||
size_t dummy;
|
||||
|
||||
codecvt->__cd_in.__cd.__data[0].__outbuf = (char *) to_buf;
|
||||
codecvt->__cd_in.__cd.__data[0].__outbufend = (char *) &to_buf[max];
|
||||
codecvt->__cd_in.__cd.__data[0].__statep = statep;
|
||||
|
||||
status = DL_CALL_FCT (gs->__fct,
|
||||
(gs, codecvt->__cd_in.__cd.__data, &cp, from_end,
|
||||
NULL, &dummy, 0, 0));
|
||||
|
||||
result = cp - (const unsigned char *) from_start;
|
||||
#else
|
||||
# ifdef _GLIBCPP_USE_WCHAR_T
|
||||
const char *from_start_copy = (const char *) from_start;
|
||||
size_t from_len = from_end - from_start;
|
||||
wchar_t to_buf[max];
|
||||
size_t res;
|
||||
char *to_start = (char *) to_buf;
|
||||
|
||||
res = iconv (codecvt->__cd_in, &from_start_copy, &from_len,
|
||||
&to_start, &max);
|
||||
|
||||
result = from_start_copy - (char *) from_start;
|
||||
# else
|
||||
/* Decide what to do. */
|
||||
result = 0;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
do_max_length (struct _IO_codecvt *codecvt)
|
||||
{
|
||||
#ifdef _LIBC
|
||||
return codecvt->__cd_in.__cd.__steps[0].__max_needed_from;
|
||||
#else
|
||||
return MB_CUR_MAX;
|
||||
#endif
|
||||
}
|
@ -8,14 +8,23 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
extern int _IO_fclose __P((_IO_FILE*));
|
||||
extern int _IO_new_fclose __P((_IO_FILE*));
|
||||
extern int _IO_old_fclose __P((_IO_FILE*));
|
||||
extern _IO_FILE *_IO_fdopen __P((int, const char*));
|
||||
extern _IO_FILE *_IO_old_fdopen __P((int, const char*));
|
||||
extern _IO_FILE *_IO_new_fdopen __P((int, const char*));
|
||||
extern int _IO_fflush __P((_IO_FILE*));
|
||||
extern int _IO_fgetpos __P((_IO_FILE*, _IO_fpos_t*));
|
||||
extern int _IO_fgetpos64 __P((_IO_FILE*, _IO_fpos64_t*));
|
||||
extern char* _IO_fgets __P((char*, int, _IO_FILE*));
|
||||
extern _IO_FILE *_IO_fopen __P((const char*, const char*));
|
||||
extern _IO_FILE *_IO_old_fopen __P((const char*, const char*));
|
||||
extern _IO_FILE *_IO_new_fopen __P((const char*, const char*));
|
||||
extern _IO_FILE *_IO_fopen64 __P((const char*, const char*));
|
||||
extern int _IO_fprintf __P((_IO_FILE*, const char*, ...));
|
||||
extern int _IO_fputs __P((const char*, _IO_FILE*));
|
||||
extern int _IO_fsetpos __P((_IO_FILE*, const _IO_fpos_t *));
|
||||
extern int _IO_fsetpos64 __P((_IO_FILE*, const _IO_fpos64_t *));
|
||||
extern long int _IO_ftell __P((_IO_FILE*));
|
||||
extern _IO_size_t _IO_fread __P((void*, _IO_size_t, _IO_size_t, _IO_FILE*));
|
||||
extern _IO_size_t _IO_fwrite __P((const void*,
|
||||
@ -32,32 +41,40 @@ extern int _IO_sprintf __P((char *, const char*, ...));
|
||||
extern int _IO_ungetc __P((int, _IO_FILE*));
|
||||
extern int _IO_vsscanf __P((const char *, const char *, _IO_va_list));
|
||||
extern int _IO_vsprintf __P((char*, const char*, _IO_va_list));
|
||||
extern int _IO_vswprintf __P((wchar_t*, _IO_size_t, const wchar_t*,
|
||||
_IO_va_list));
|
||||
|
||||
struct obstack;
|
||||
extern int _IO_obstack_vprintf __P ((struct obstack *, const char *,
|
||||
_IO_va_list));
|
||||
_IO_va_list));
|
||||
extern int _IO_obstack_printf __P ((struct obstack *, const char *, ...));
|
||||
#ifndef _IO_pos_BAD
|
||||
#define _IO_pos_BAD ((_IO_fpos_t)(-1))
|
||||
#define _IO_pos_BAD ((_IO_off64_t)(-1))
|
||||
#endif
|
||||
#define _IO_clearerr(FP) ((FP)->_flags &= ~(_IO_ERR_SEEN|_IO_EOF_SEEN))
|
||||
#define _IO_fseek(__fp, __offset, __whence) \
|
||||
(_IO_seekoff(__fp, __offset, __whence, _IOS_INPUT|_IOS_OUTPUT) == _IO_pos_BAD ? EOF : 0)
|
||||
#define _IO_rewind(FILE) (void)_IO_seekoff(FILE, 0, 0, _IOS_INPUT|_IOS_OUTPUT)
|
||||
#define _IO_vprintf(FORMAT, ARGS) _IO_vfprintf(_IO_stdout, FORMAT, ARGS)
|
||||
#if _G_IO_IO_FILE_VERSION == 0x20001
|
||||
#define _IO_freopen(FILENAME, MODE, FP) \
|
||||
(_IO_file_close_it(FP), _IO_file_fopen(FP, FILENAME, MODE, 0))
|
||||
#else
|
||||
#define _IO_freopen(FILENAME, MODE, FP) \
|
||||
(_IO_file_close_it(FP), _IO_file_fopen(FP, FILENAME, MODE))
|
||||
#endif
|
||||
#define _IO_old_freopen(FILENAME, MODE, FP) \
|
||||
(_IO_old_file_close_it (FP), _IO_old_file_fopen(FP, FILENAME, MODE))
|
||||
#define _IO_freopen64(FILENAME, MODE, FP) \
|
||||
(_IO_file_close_it(FP), _IO_file_fopen(FP, FILENAME, MODE, 1))
|
||||
#define _IO_fileno(FP) ((FP)->_fileno)
|
||||
extern _IO_FILE* _IO_popen __P((const char*, const char*));
|
||||
extern _IO_FILE* _IO_new_popen __P((const char*, const char*));
|
||||
extern _IO_FILE* _IO_old_popen __P((const char*, const char*));
|
||||
extern int __new_pclose __P((_IO_FILE *));
|
||||
extern int __old_pclose __P((_IO_FILE *));
|
||||
#define _IO_pclose _IO_fclose
|
||||
#define _IO_setbuf(_FP, _BUF) _IO_setbuffer(_FP, _BUF, _IO_BUFSIZ)
|
||||
#define _IO_setlinebuf(_FP) _IO_setvbuf(_FP, NULL, 1, 0)
|
||||
|
||||
_IO_FILE *__new_freopen __P ((const char *, const char *, _IO_FILE *));
|
||||
_IO_FILE *__old_freopen __P ((const char *, const char *, _IO_FILE *));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 1991, 92, 93, 94, 95, 97, 98 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1991,92,93,94,95,97,98,99,2000 Free Software Foundation, Inc.
|
||||
This file is part of the GNU IO Library.
|
||||
Written by Per Bothner <bothner@cygnus.com>.
|
||||
|
||||
@ -28,21 +28,22 @@
|
||||
#define _IO_STDIO_H
|
||||
|
||||
#include <_G_config.h>
|
||||
/* ALL of these should be defined in _G_config.h */
|
||||
#define _IO_pos_t _G_fpos_t /* obsolete */
|
||||
#define _IO_fpos_t _G_fpos_t
|
||||
#define _IO_fpos64_t _G_fpos64_t
|
||||
#define _IO_size_t _G_size_t
|
||||
#define _IO_ssize_t _G_ssize_t
|
||||
#define _IO_off_t _G_off_t
|
||||
#define _IO_off64_t _G_off64_t
|
||||
#define _IO_pid_t _G_pid_t
|
||||
#define _IO_uid_t _G_uid_t
|
||||
#define _IO_iconv_t _G_iconv_t
|
||||
#define _IO_HAVE_SYS_WAIT _G_HAVE_SYS_WAIT
|
||||
#define _IO_HAVE_ST_BLKSIZE _G_HAVE_ST_BLKSIZE
|
||||
#define _IO_BUFSIZ _G_BUFSIZ
|
||||
#define _IO_va_list _G_va_list
|
||||
#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
||||
#define _IO_fpos64_t _G_fpos64_t
|
||||
#define _IO_off64_t _G_off64_t
|
||||
#endif
|
||||
#define _IO_wint_t _G_wint_t
|
||||
|
||||
#ifdef _G_NEED_STDARG_H
|
||||
/* This define avoids name pollution if we're using GNU stdarg.h */
|
||||
@ -60,30 +61,26 @@
|
||||
# else
|
||||
# ifdef __STDC__
|
||||
# define __P(p) p
|
||||
# define __PMT(p) p
|
||||
# else
|
||||
# define __P(p) ()
|
||||
# define __PMT(p) ()
|
||||
# endif
|
||||
# endif
|
||||
#endif /*!__P*/
|
||||
|
||||
#ifndef __PMT
|
||||
# ifdef __STDC__
|
||||
# define __PMT(p) p
|
||||
# else
|
||||
# define __PMT(p) ()
|
||||
# endif
|
||||
#endif /*!__P*/
|
||||
|
||||
/* For backward compatibility */
|
||||
#ifndef _PARAMS
|
||||
# define _PARAMS(protos) __P(protos)
|
||||
#endif /*!_PARAMS*/
|
||||
|
||||
#ifndef __STDC__
|
||||
# define const
|
||||
# ifndef const
|
||||
# define const
|
||||
# endif
|
||||
#endif
|
||||
#define _IO_UNIFIED_JUMPTABLES 1
|
||||
#if !_G_HAVE_PRINTF_FP
|
||||
#ifndef _G_HAVE_PRINTF_FP
|
||||
# define _IO_USE_DTOA 1
|
||||
#endif
|
||||
|
||||
@ -162,28 +159,12 @@ struct _IO_jump_t; struct _IO_FILE;
|
||||
/* Handle lock. */
|
||||
#ifdef _IO_MTSAFE_IO
|
||||
# if defined __GLIBC__ && __GLIBC__ >= 2
|
||||
# if __GLIBC_MINOR__ > 0
|
||||
# include <bits/stdio-lock.h>
|
||||
# else
|
||||
# include <stdio-lock.h>
|
||||
# endif
|
||||
# define _IO_LOCK_T _IO_lock_t *
|
||||
# include <bits/stdio-lock.h>
|
||||
# else
|
||||
/*# include <comthread.h>*/
|
||||
# endif
|
||||
#else
|
||||
# if defined(__GLIBC__) && __GLIBC__ >= 2
|
||||
typedef void _IO_lock_t;
|
||||
# define _IO_LOCK_T void *
|
||||
# else
|
||||
# ifdef __linux__
|
||||
struct _IO_lock_t { void *ptr; short int field1; short int field2; };
|
||||
# define _IO_LOCK_T struct _IO_lock_t
|
||||
# else
|
||||
typedef void _IO_lock_t;
|
||||
# define _IO_LOCK_T void *
|
||||
# endif
|
||||
# endif
|
||||
typedef void _IO_lock_t;
|
||||
#endif
|
||||
|
||||
|
||||
@ -208,6 +189,78 @@ struct _IO_marker {
|
||||
#endif
|
||||
};
|
||||
|
||||
/* This is the structure from the libstdc++ codecvt class. */
|
||||
enum __codecvt_result
|
||||
{
|
||||
__codecvt_ok,
|
||||
__codecvt_partial,
|
||||
__codecvt_error,
|
||||
__codecvt_noconv
|
||||
};
|
||||
|
||||
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
|
||||
/* The order of the elements in the following struct must match the order
|
||||
of the virtual functions in the libstdc++ codecvt class. */
|
||||
struct _IO_codecvt
|
||||
{
|
||||
void (*__codecvt_destr) (struct _IO_codecvt *);
|
||||
enum __codecvt_result (*__codecvt_do_out) (struct _IO_codecvt *,
|
||||
__mbstate_t *,
|
||||
const wchar_t *,
|
||||
const wchar_t *,
|
||||
const wchar_t **, char *,
|
||||
char *, char **);
|
||||
enum __codecvt_result (*__codecvt_do_unshift) (struct _IO_codecvt *,
|
||||
__mbstate_t *, char *,
|
||||
char *, char **);
|
||||
enum __codecvt_result (*__codecvt_do_in) (struct _IO_codecvt *,
|
||||
__mbstate_t *,
|
||||
const char *, const char *,
|
||||
const char **, wchar_t *,
|
||||
wchar_t *, wchar_t **);
|
||||
int (*__codecvt_do_encoding) (struct _IO_codecvt *);
|
||||
int (*__codecvt_do_always_noconv) (struct _IO_codecvt *);
|
||||
int (*__codecvt_do_length) (struct _IO_codecvt *, __mbstate_t *,
|
||||
const char *, const char *, _IO_size_t);
|
||||
int (*__codecvt_do_max_length) (struct _IO_codecvt *);
|
||||
|
||||
_IO_iconv_t __cd_in;
|
||||
_IO_iconv_t __cd_out;
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Extra data for wide character streams. */
|
||||
struct _IO_wide_data
|
||||
{
|
||||
wchar_t *_IO_read_ptr; /* Current read pointer */
|
||||
wchar_t *_IO_read_end; /* End of get area. */
|
||||
wchar_t *_IO_read_base; /* Start of putback+get area. */
|
||||
wchar_t *_IO_write_base; /* Start of put area. */
|
||||
wchar_t *_IO_write_ptr; /* Current put pointer. */
|
||||
wchar_t *_IO_write_end; /* End of put area. */
|
||||
wchar_t *_IO_buf_base; /* Start of reserve area. */
|
||||
wchar_t *_IO_buf_end; /* End of reserve area. */
|
||||
/* The following fields are used to support backing up and undo. */
|
||||
wchar_t *_IO_save_base; /* Pointer to start of non-current get area. */
|
||||
wchar_t *_IO_backup_base; /* Pointer to first valid character of
|
||||
backup area */
|
||||
wchar_t *_IO_save_end; /* Pointer to end of non-current get area. */
|
||||
|
||||
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
|
||||
__mbstate_t _IO_state;
|
||||
__mbstate_t _IO_last_state;
|
||||
struct _IO_codecvt _codecvt;
|
||||
#endif
|
||||
|
||||
wchar_t _shortbuf[1];
|
||||
|
||||
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
|
||||
struct _IO_jump_t *_wide_vtable;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct _IO_FILE_plus;
|
||||
|
||||
struct _IO_FILE {
|
||||
int _flags; /* High-order word is _IO_MAGIC; rest is flags. */
|
||||
#define _IO_file_flags _flags
|
||||
@ -229,30 +282,38 @@ struct _IO_FILE {
|
||||
|
||||
struct _IO_marker *_markers;
|
||||
|
||||
struct _IO_FILE *_chain;
|
||||
struct _IO_FILE_plus *_chain;
|
||||
|
||||
int _fileno;
|
||||
int _blksize;
|
||||
#ifdef _G_IO_IO_FILE_VERSION
|
||||
_IO_off_t _old_offset;
|
||||
#else
|
||||
_IO_off_t _offset;
|
||||
#endif
|
||||
_IO_off_t _old_offset; /* This used to be _offset but it's too small. */
|
||||
|
||||
#define __HAVE_COLUMN /* temporary */
|
||||
/* 1+column number of pbase(); 0 is unknown. */
|
||||
unsigned short _cur_column;
|
||||
char _unused;
|
||||
signed char _vtable_offset;
|
||||
char _shortbuf[1];
|
||||
|
||||
/* char* _save_gptr; char* _save_egptr; */
|
||||
|
||||
#ifdef _IO_LOCK_T
|
||||
_IO_LOCK_T _lock;
|
||||
_IO_lock_t *_lock;
|
||||
#ifdef _IO_USE_OLD_IO_FILE
|
||||
};
|
||||
|
||||
struct _IO_FILE_complete
|
||||
{
|
||||
struct _IO_FILE _file;
|
||||
#endif
|
||||
#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
||||
#if defined _G_IO_IO_FILE_VERSION && _G_IO_IO_FILE_VERSION == 0x20001
|
||||
_IO_off64_t _offset;
|
||||
int _unused2[16]; /* Make sure we don't get into trouble again. */
|
||||
# if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
|
||||
/* Wide character stream stuff. */
|
||||
struct _IO_codecvt *_codecvt;
|
||||
struct _IO_wide_data *_wide_data;
|
||||
# endif
|
||||
int _mode;
|
||||
/* Make sure we don't get into trouble again. */
|
||||
char _unused2[15 * sizeof (int) - 2 * sizeof (void *)];
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -260,45 +321,82 @@ struct _IO_FILE {
|
||||
typedef struct _IO_FILE _IO_FILE;
|
||||
#endif
|
||||
|
||||
#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
||||
#define _IO_stdin_ _IO_2_1_stdin_
|
||||
#define _IO_stdout_ _IO_2_1_stdout_
|
||||
#define _IO_stderr_ _IO_2_1_stderr_
|
||||
extern struct _IO_FILE_plus _IO_2_1_stdin_;
|
||||
extern struct _IO_FILE_plus _IO_2_1_stdout_;
|
||||
extern struct _IO_FILE_plus _IO_2_1_stderr_;
|
||||
#ifndef _LIBC
|
||||
#define _IO_stdin ((_IO_FILE*)(&_IO_2_1_stdin_))
|
||||
#define _IO_stdout ((_IO_FILE*)(&_IO_2_1_stdout_))
|
||||
#define _IO_stderr ((_IO_FILE*)(&_IO_2_1_stderr_))
|
||||
#else
|
||||
extern _IO_FILE *_IO_stdin;
|
||||
extern _IO_FILE *_IO_stdout;
|
||||
extern _IO_FILE *_IO_stderr;
|
||||
#endif
|
||||
|
||||
struct _IO_FILE_plus;
|
||||
extern struct _IO_FILE_plus _IO_stdin_, _IO_stdout_, _IO_stderr_;
|
||||
#define _IO_stdin ((_IO_FILE*)(&_IO_stdin_))
|
||||
#define _IO_stdout ((_IO_FILE*)(&_IO_stdout_))
|
||||
#define _IO_stderr ((_IO_FILE*)(&_IO_stderr_))
|
||||
|
||||
/* Functions to do I/O and file management for a stream. */
|
||||
|
||||
/* Read NBYTES bytes from COOKIE into a buffer pointed to by BUF.
|
||||
Return number of bytes read. */
|
||||
typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes);
|
||||
|
||||
/* Write N bytes pointed to by BUF to COOKIE. Write all N bytes
|
||||
unless there is an error. Return number of bytes written, or -1 if
|
||||
there is an error without writing anything. If the file has been
|
||||
opened for append (__mode.__append set), then set the file pointer
|
||||
to the end of the file and then do the write; if not, just write at
|
||||
the current file pointer. */
|
||||
typedef __ssize_t __io_write_fn (void *__cookie, __const char *__buf,
|
||||
size_t __n);
|
||||
|
||||
/* Move COOKIE's file position to *POS bytes from the
|
||||
beginning of the file (if W is SEEK_SET),
|
||||
the current position (if W is SEEK_CUR),
|
||||
or the end of the file (if W is SEEK_END).
|
||||
Set *POS to the new file position.
|
||||
Returns zero if successful, nonzero if not. */
|
||||
typedef int __io_seek_fn (void *__cookie, _IO_off64_t *__pos, int __w);
|
||||
|
||||
/* Close COOKIE. */
|
||||
typedef int __io_close_fn (void *__cookie);
|
||||
|
||||
|
||||
/* Define the user-visible type, with user-friendly member names. */
|
||||
#ifdef _GNU_SOURCE
|
||||
/* User-visible names for the above. */
|
||||
typedef __io_read_fn cookie_read_function_t;
|
||||
typedef __io_write_fn cookie_write_function_t;
|
||||
typedef __io_seek_fn cookie_seek_function_t;
|
||||
typedef __io_close_fn cookie_close_function_t;
|
||||
|
||||
/* The structure with the cookie function pointers. */
|
||||
typedef struct
|
||||
{
|
||||
_IO_ssize_t (*read) __PMT ((struct _IO_FILE *, void *, _IO_ssize_t));
|
||||
_IO_ssize_t (*write) __PMT ((struct _IO_FILE *, const void *, _IO_ssize_t));
|
||||
_IO_off_t (*seek) __PMT ((struct _IO_FILE *, _IO_off_t, int));
|
||||
int (*close) __PMT ((struct _IO_FILE *));
|
||||
__io_read_fn *read; /* Read bytes. */
|
||||
__io_write_fn *write; /* Write bytes. */
|
||||
__io_seek_fn *seek; /* Seek/tell file position. */
|
||||
__io_close_fn *close; /* Close file. */
|
||||
} _IO_cookie_io_functions_t;
|
||||
typedef _IO_cookie_io_functions_t cookie_io_functions_t;
|
||||
|
||||
/* Special file type for fopencookie function. */
|
||||
struct _IO_cookie_file
|
||||
{
|
||||
struct _IO_FILE file;
|
||||
const void *vtable;
|
||||
void *cookie;
|
||||
_IO_cookie_io_functions_t io_functions;
|
||||
};
|
||||
struct _IO_cookie_file;
|
||||
|
||||
/* Initialize one of those. */
|
||||
extern void _IO_cookie_init (struct _IO_cookie_file *__cfile, int __read_write,
|
||||
void *__cookie, _IO_cookie_io_functions_t __fns);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int __underflow __P ((_IO_FILE *));
|
||||
extern int __uflow __P ((_IO_FILE *));
|
||||
extern int __overflow __P ((_IO_FILE *, int));
|
||||
extern int __underflow (_IO_FILE *) __THROW;
|
||||
extern int __uflow (_IO_FILE *) __THROW;
|
||||
extern int __overflow (_IO_FILE *, int) __THROW;
|
||||
extern _IO_wint_t __wunderflow (_IO_FILE *) __THROW;
|
||||
extern _IO_wint_t __wuflow (_IO_FILE *) __THROW;
|
||||
extern _IO_wint_t __woverflow (_IO_FILE *, _IO_wint_t) __THROW;
|
||||
|
||||
#define _IO_getc_unlocked(_fp) \
|
||||
((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end ? __uflow (_fp) \
|
||||
@ -307,29 +405,36 @@ extern int __overflow __P ((_IO_FILE *, int));
|
||||
((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end \
|
||||
&& __underflow (_fp) == EOF ? EOF \
|
||||
: *(unsigned char *) (_fp)->_IO_read_ptr)
|
||||
|
||||
#define _IO_putc_unlocked(_ch, _fp) \
|
||||
(((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end) \
|
||||
? __overflow (_fp, (unsigned char) (_ch)) \
|
||||
: (unsigned char) (*(_fp)->_IO_write_ptr++ = (_ch)))
|
||||
|
||||
#define _IO_getwc_unlocked(_fp) \
|
||||
((_fp)->_wide_data->_IO_read_ptr >= (_fp)->_wide_data->_IO_read_end \
|
||||
? __wuflow (_fp) : (_IO_wint_t) *(_fp)->_wide_data->_IO_read_ptr++)
|
||||
#define _IO_putwc_unlocked(_wch, _fp) \
|
||||
((_fp)->_wide_data->_IO_write_ptr >= (_fp)->_wide_data->_IO_write_end \
|
||||
? __woverflow (_fp, _wch) \
|
||||
: (_IO_wint_t) (*(_fp)->_wide_data->_IO_write_ptr++ = (_wch)))
|
||||
|
||||
#define _IO_feof_unlocked(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0)
|
||||
#define _IO_ferror_unlocked(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0)
|
||||
|
||||
extern int _IO_getc __P ((_IO_FILE *__fp));
|
||||
extern int _IO_putc __P ((int __c, _IO_FILE *__fp));
|
||||
extern int _IO_feof __P ((_IO_FILE *__fp));
|
||||
extern int _IO_ferror __P ((_IO_FILE *__fp));
|
||||
extern int _IO_getc (_IO_FILE *__fp) __THROW;
|
||||
extern int _IO_putc (int __c, _IO_FILE *__fp) __THROW;
|
||||
extern int _IO_feof (_IO_FILE *__fp) __THROW;
|
||||
extern int _IO_ferror (_IO_FILE *__fp) __THROW;
|
||||
|
||||
extern int _IO_peekc_locked __P ((_IO_FILE *__fp));
|
||||
extern int _IO_peekc_locked (_IO_FILE *__fp) __THROW;
|
||||
|
||||
/* This one is for Emacs. */
|
||||
#define _IO_PENDING_OUTPUT_COUNT(_fp) \
|
||||
((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)
|
||||
|
||||
extern void _IO_flockfile __P ((_IO_FILE *));
|
||||
extern void _IO_funlockfile __P ((_IO_FILE *));
|
||||
extern int _IO_ftrylockfile __P ((_IO_FILE *));
|
||||
extern void _IO_flockfile (_IO_FILE *) __THROW;
|
||||
extern void _IO_funlockfile (_IO_FILE *) __THROW;
|
||||
extern int _IO_ftrylockfile (_IO_FILE *) __THROW;
|
||||
|
||||
#ifdef _IO_MTSAFE_IO
|
||||
# define _IO_peekc(_fp) _IO_peekc_locked (_fp)
|
||||
@ -342,24 +447,51 @@ extern int _IO_ftrylockfile __P ((_IO_FILE *));
|
||||
# define _IO_cleanup_region_end(_Doit) /**/
|
||||
#endif /* !_IO_MTSAFE_IO */
|
||||
|
||||
extern int _IO_vfscanf (_IO_FILE * __restrict, const char * __restrict,
|
||||
_IO_va_list, int *__restrict) __THROW;
|
||||
extern int _IO_vfprintf (_IO_FILE *__restrict, const char *__restrict,
|
||||
_IO_va_list) __THROW;
|
||||
extern _IO_ssize_t _IO_padn (_IO_FILE *, int, _IO_ssize_t) __THROW;
|
||||
extern _IO_size_t _IO_sgetn (_IO_FILE *, void *, _IO_size_t) __THROW;
|
||||
|
||||
extern int _IO_vfscanf __P ((_IO_FILE *, const char *, _IO_va_list, int *));
|
||||
extern int _IO_vfprintf __P ((_IO_FILE *, const char *, _IO_va_list));
|
||||
extern _IO_ssize_t _IO_padn __P ((_IO_FILE *, int, _IO_ssize_t));
|
||||
extern _IO_size_t _IO_sgetn __P ((_IO_FILE *, void *, _IO_size_t));
|
||||
extern _IO_off64_t _IO_seekoff (_IO_FILE *, _IO_off64_t, int, int) __THROW;
|
||||
extern _IO_off64_t _IO_seekpos (_IO_FILE *, _IO_off64_t, int) __THROW;
|
||||
|
||||
#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
||||
extern _IO_off64_t _IO_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
|
||||
extern _IO_off64_t _IO_seekpos __P ((_IO_FILE *, _IO_off64_t, int));
|
||||
#else
|
||||
extern _IO_off_t _IO_seekoff __P ((_IO_FILE *, _IO_off_t, int, int));
|
||||
extern _IO_off_t _IO_seekpos __P ((_IO_FILE *, _IO_off_t, int));
|
||||
extern void _IO_free_backup_area (_IO_FILE *) __THROW;
|
||||
|
||||
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
|
||||
extern _IO_wint_t _IO_getwc (_IO_FILE *__fp) __THROW;
|
||||
extern _IO_wint_t _IO_putwc (wchar_t __wc, _IO_FILE *__fp) __THROW;
|
||||
extern int _IO_fwide (_IO_FILE *__fp, int __mode) __THROW;
|
||||
# if __GNUC__ >= 2
|
||||
/* A special optimized version of the function above. It optimizes the
|
||||
case of initializing an unoriented byte stream. */
|
||||
# define _IO_fwide(__fp, __mode) \
|
||||
({ int __result = (__mode); \
|
||||
if (__result < 0) \
|
||||
{ \
|
||||
if ((__fp)->_mode == 0) \
|
||||
/* We know that all we have to do is to set the flag. */ \
|
||||
(__fp)->_mode = -1; \
|
||||
__result = (__fp)->_mode; \
|
||||
} \
|
||||
else \
|
||||
__result = _IO_fwide (__fp, __result); \
|
||||
__result; })
|
||||
# endif
|
||||
|
||||
extern int _IO_vfwscanf (_IO_FILE * __restrict, const wchar_t * __restrict,
|
||||
_IO_va_list, int *__restrict) __THROW;
|
||||
extern int _IO_vfwprintf (_IO_FILE *__restrict, const wchar_t *__restrict,
|
||||
_IO_va_list) __THROW;
|
||||
extern _IO_ssize_t _IO_wpadn (_IO_FILE *, wint_t, _IO_ssize_t) __THROW;
|
||||
extern void _IO_free_wbackup_area (_IO_FILE *) __THROW;
|
||||
#endif
|
||||
|
||||
extern void _IO_free_backup_area __P ((_IO_FILE *));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _IO_STDIO_H */
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1993, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
|
||||
This file is part of the GNU IO Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
@ -23,25 +23,14 @@
|
||||
other reasons why the executable file might be covered by the GNU
|
||||
General Public License. */
|
||||
|
||||
#ifndef _POSIX_SOURCE
|
||||
# define _POSIX_SOURCE
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#ifndef __set_errno
|
||||
# define __set_errno(Val) errno = (Val)
|
||||
#endif
|
||||
|
||||
#ifdef _IO_MTSAFE_IO
|
||||
# if defined __GLIBC__ && __GLIBC__ >= 2
|
||||
# if __GLIBC_MINOR__ > 0
|
||||
# include <bits/libc-lock.h>
|
||||
# else
|
||||
# include <libc-lock.h>
|
||||
# endif
|
||||
# else
|
||||
#if defined __GLIBC__ && __GLIBC__ >= 2
|
||||
# include <bits/libc-lock.h>
|
||||
#else
|
||||
/*# include <comthread.h>*/
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "iolibio.h"
|
||||
@ -75,37 +64,65 @@ extern "C" {
|
||||
* object being acted on (i.e. the 'this' parameter).
|
||||
*/
|
||||
|
||||
#if (!defined _IO_USE_OLD_IO_FILE \
|
||||
&& (!defined _G_IO_NO_BACKWARD_COMPAT || _G_IO_NO_BACKWARD_COMPAT == 0))
|
||||
# define _IO_JUMPS_OFFSET 1
|
||||
#endif
|
||||
|
||||
#define _IO_JUMPS(THIS) ((struct _IO_FILE_plus *) (THIS))->vtable
|
||||
#define _IO_WIDE_JUMPS(THIS) ((struct _IO_FILE *) (THIS))->_wide_data->_wide_vtable
|
||||
#define _IO_CHECK_WIDE(THIS) (((struct _IO_FILE *) (THIS))->_wide_data != NULL)
|
||||
|
||||
#if _IO_JUMPS_OFFSET
|
||||
# define _IO_JUMPS_FUNC(THIS) \
|
||||
(*(struct _IO_jump_t **) ((char *) &_IO_JUMPS ((struct _IO_FILE_plus *) (THIS)) \
|
||||
+ (THIS)->_vtable_offset))
|
||||
#else
|
||||
# define _IO_JUMPS_FUNC(THIS) _IO_JUMPS ((struct _IO_FILE_plus *) (THIS))
|
||||
#endif
|
||||
#define _IO_WIDE_JUMPS_FUNC(THIS) _IO_WIDE_JUMPS(THIS)
|
||||
#ifdef _G_USING_THUNKS
|
||||
# define JUMP_FIELD(TYPE, NAME) TYPE NAME
|
||||
# define JUMP0(FUNC, THIS) _IO_JUMPS(THIS)->FUNC (THIS)
|
||||
# define JUMP1(FUNC, THIS, X1) _IO_JUMPS(THIS)->FUNC (THIS, X1)
|
||||
# define JUMP2(FUNC, THIS, X1, X2) _IO_JUMPS(THIS)->FUNC (THIS, X1, X2)
|
||||
# define JUMP3(FUNC, THIS, X1,X2,X3) _IO_JUMPS(THIS)->FUNC (THIS, X1,X2, X3)
|
||||
# define JUMP0(FUNC, THIS) _IO_JUMPS_FUNC(THIS)->FUNC (THIS)
|
||||
# define JUMP1(FUNC, THIS, X1) _IO_JUMPS_FUNC(THIS)->FUNC (THIS, X1)
|
||||
# define JUMP2(FUNC, THIS, X1, X2) _IO_JUMPS_FUNC(THIS)->FUNC (THIS, X1, X2)
|
||||
# define JUMP3(FUNC, THIS, X1,X2,X3) _IO_JUMPS_FUNC(THIS)->FUNC (THIS, X1,X2, X3)
|
||||
# define JUMP_INIT(NAME, VALUE) VALUE
|
||||
# define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0), JUMP_INIT (dummy2, 0)
|
||||
|
||||
# define WJUMP0(FUNC, THIS) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC (THIS)
|
||||
# define WJUMP1(FUNC, THIS, X1) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC (THIS, X1)
|
||||
# define WJUMP2(FUNC, THIS, X1, X2) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC (THIS, X1, X2)
|
||||
# define WJUMP3(FUNC, THIS, X1,X2,X3) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC (THIS, X1,X2, X3)
|
||||
#else
|
||||
/* These macros will change when we re-implement vtables to use "thunks"! */
|
||||
# define JUMP_FIELD(TYPE, NAME) struct { short delta1, delta2; TYPE pfn; } NAME
|
||||
# define JUMP0(FUNC, THIS) _IO_JUMPS(THIS)->FUNC.pfn (THIS)
|
||||
# define JUMP1(FUNC, THIS, X1) _IO_JUMPS(THIS)->FUNC.pfn (THIS, X1)
|
||||
# define JUMP2(FUNC, THIS, X1, X2) _IO_JUMPS(THIS)->FUNC.pfn (THIS, X1, X2)
|
||||
# define JUMP3(FUNC, THIS, X1,X2,X3) _IO_JUMPS(THIS)->FUNC.pfn (THIS, X1,X2,X3)
|
||||
# define JUMP0(FUNC, THIS) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS)
|
||||
# define JUMP1(FUNC, THIS, X1) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1)
|
||||
# define JUMP2(FUNC, THIS, X1, X2) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1, X2)
|
||||
# define JUMP3(FUNC, THIS, X1,X2,X3) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1,X2,X3)
|
||||
# define JUMP_INIT(NAME, VALUE) {0, 0, VALUE}
|
||||
# define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0)
|
||||
|
||||
# define WJUMP0(FUNC, THIS) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS)
|
||||
# define WJUMP1(FUNC, THIS, X1) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1)
|
||||
# define WJUMP2(FUNC, THIS, X1, X2) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1, X2)
|
||||
# define WJUMP3(FUNC, THIS, X1,X2,X3) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1,X2,X3)
|
||||
#endif
|
||||
|
||||
/* The 'finish' function does any final cleaning up of an _IO_FILE object.
|
||||
It does not delete (free) it, but does everything else to finalize it/
|
||||
It does not delete (free) it, but does everything else to finalize it.
|
||||
It matches the streambuf::~streambuf virtual destructor. */
|
||||
typedef void (*_IO_finish_t) __PMT ((_IO_FILE *, int)); /* finalize */
|
||||
#define _IO_FINISH(FP) JUMP1 (__finish, FP, 0)
|
||||
#define _IO_WFINISH(FP) WJUMP1 (__finish, FP, 0)
|
||||
|
||||
/* The 'overflow' hook flushes the buffer.
|
||||
The second argument is a character, or EOF.
|
||||
It matches the streambuf::overflow virtual function. */
|
||||
typedef int (*_IO_overflow_t) __PMT ((_IO_FILE *, int));
|
||||
#define _IO_OVERFLOW(FP, CH) JUMP1 (__overflow, FP, CH)
|
||||
#define _IO_WOVERFLOW(FP, CH) WJUMP1 (__overflow, FP, CH)
|
||||
|
||||
/* The 'underflow' hook tries to fills the get buffer.
|
||||
It returns the next character (as an unsigned char) or EOF. The next
|
||||
@ -113,6 +130,7 @@ typedef int (*_IO_overflow_t) __PMT ((_IO_FILE *, int));
|
||||
It matches the streambuf::underflow virtual function. */
|
||||
typedef int (*_IO_underflow_t) __PMT ((_IO_FILE *));
|
||||
#define _IO_UNDERFLOW(FP) JUMP0 (__underflow, FP)
|
||||
#define _IO_WUNDERFLOW(FP) WJUMP0 (__underflow, FP)
|
||||
|
||||
/* The 'uflow' hook returns the next character in the input stream
|
||||
(cast to unsigned char), and increments the read position;
|
||||
@ -120,68 +138,68 @@ typedef int (*_IO_underflow_t) __PMT ((_IO_FILE *));
|
||||
It matches the streambuf::uflow virtual function, which is not in the
|
||||
cfront implementation, but was added to C++ by the ANSI/ISO committee. */
|
||||
#define _IO_UFLOW(FP) JUMP0 (__uflow, FP)
|
||||
#define _IO_WUFLOW(FP) WJUMP0 (__uflow, FP)
|
||||
|
||||
/* The 'pbackfail' hook handles backing up.
|
||||
It matches the streambuf::pbackfail virtual function. */
|
||||
typedef int (*_IO_pbackfail_t) __PMT ((_IO_FILE *, int));
|
||||
#define _IO_PBACKFAIL(FP, CH) JUMP1 (__pbackfail, FP, CH)
|
||||
#define _IO_WPBACKFAIL(FP, CH) WJUMP1 (__pbackfail, FP, CH)
|
||||
|
||||
/* The 'xsputn' hook writes upto N characters from buffer DATA.
|
||||
Returns the number of character actually written.
|
||||
It matches the streambuf::xsputn virtual function. */
|
||||
typedef _IO_size_t (*_IO_xsputn_t) __PMT ((_IO_FILE *FP, const void *DATA,
|
||||
_IO_size_t N));
|
||||
_IO_size_t N));
|
||||
#define _IO_XSPUTN(FP, DATA, N) JUMP2 (__xsputn, FP, DATA, N)
|
||||
#define _IO_WXSPUTN(FP, DATA, N) WJUMP2 (__xsputn, FP, DATA, N)
|
||||
|
||||
/* The 'xsgetn' hook reads upto N characters into buffer DATA.
|
||||
Returns the number of character actually read.
|
||||
It matches the streambuf::xsgetn virtual function. */
|
||||
typedef _IO_size_t (*_IO_xsgetn_t) __PMT ((_IO_FILE *FP, void *DATA,
|
||||
_IO_size_t N));
|
||||
_IO_size_t N));
|
||||
#define _IO_XSGETN(FP, DATA, N) JUMP2 (__xsgetn, FP, DATA, N)
|
||||
#define _IO_WXSGETN(FP, DATA, N) WJUMP2 (__xsgetn, FP, DATA, N)
|
||||
|
||||
/* The 'seekoff' hook moves the stream position to a new position
|
||||
relative to the start of the file (if DIR==0), the current position
|
||||
(MODE==1), or the end of the file (MODE==2).
|
||||
It matches the streambuf::seekoff virtual function.
|
||||
It is also used for the ANSI fseek function. */
|
||||
#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
||||
typedef _IO_off64_t (*_IO_seekoff_t) __PMT ((_IO_FILE *FP, _IO_off64_t OFF,
|
||||
int DIR, int MODE));
|
||||
#else
|
||||
typedef _IO_off_t (*_IO_seekoff_t) __PMT ((_IO_FILE *FP, _IO_off_t OFF,
|
||||
int DIR, int MODE));
|
||||
#endif
|
||||
int DIR, int MODE));
|
||||
#define _IO_SEEKOFF(FP, OFF, DIR, MODE) JUMP3 (__seekoff, FP, OFF, DIR, MODE)
|
||||
#define _IO_WSEEKOFF(FP, OFF, DIR, MODE) WJUMP3 (__seekoff, FP, OFF, DIR, MODE)
|
||||
|
||||
/* The 'seekpos' hook also moves the stream position,
|
||||
but to an absolute position given by a fpos_t (seekpos).
|
||||
but to an absolute position given by a fpos64_t (seekpos).
|
||||
It matches the streambuf::seekpos virtual function.
|
||||
It is also used for the ANSI fgetpos and fsetpos functions. */
|
||||
/* The _IO_seek_cur and _IO_seek_end options are not allowed. */
|
||||
#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
||||
typedef _IO_off64_t (*_IO_seekpos_t) __PMT ((_IO_FILE *, _IO_off64_t, int));
|
||||
#else
|
||||
typedef _IO_off_t (*_IO_seekpos_t) __PMT ((_IO_FILE *, _IO_off_t, int));
|
||||
#endif
|
||||
#define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS)
|
||||
#define _IO_WSEEKPOS(FP, POS, FLAGS) WJUMP2 (__seekpos, FP, POS, FLAGS)
|
||||
|
||||
/* The 'setbuf' hook gives a buffer to the file.
|
||||
It matches the streambuf::setbuf virtual function. */
|
||||
typedef _IO_FILE* (*_IO_setbuf_t) __PMT ((_IO_FILE *, char *, _IO_ssize_t));
|
||||
#define _IO_SETBUF(FP, BUFFER, LENGTH) JUMP2 (__setbuf, FP, BUFFER, LENGTH)
|
||||
#define _IO_WSETBUF(FP, BUFFER, LENGTH) WJUMP2 (__setbuf, FP, BUFFER, LENGTH)
|
||||
|
||||
/* The 'sync' hook attempts to synchronize the internal data structures
|
||||
of the file with the external state.
|
||||
It matches the streambuf::sync virtual function. */
|
||||
typedef int (*_IO_sync_t) __PMT ((_IO_FILE *));
|
||||
#define _IO_SYNC(FP) JUMP0 (__sync, FP)
|
||||
#define _IO_WSYNC(FP) WJUMP0 (__sync, FP)
|
||||
|
||||
/* The 'doallocate' hook is used to tell the file to allocate a buffer.
|
||||
It matches the streambuf::doallocate virtual function, which is not
|
||||
in the ANSI/ISO C++ standard, but is part traditional implementations. */
|
||||
typedef int (*_IO_doallocate_t) __PMT ((_IO_FILE *));
|
||||
#define _IO_DOALLOCATE(FP) JUMP0 (__doallocate, FP)
|
||||
#define _IO_WDOALLOCATE(FP) WJUMP0 (__doallocate, FP)
|
||||
|
||||
/* The following four hooks (sysread, syswrite, sysclose, sysseek, and
|
||||
sysstat) are low-level hooks specific to this implementation.
|
||||
@ -200,24 +218,24 @@ typedef int (*_IO_doallocate_t) __PMT ((_IO_FILE *));
|
||||
specific to this implementation. */
|
||||
typedef _IO_ssize_t (*_IO_read_t) __PMT ((_IO_FILE *, void *, _IO_ssize_t));
|
||||
#define _IO_SYSREAD(FP, DATA, LEN) JUMP2 (__read, FP, DATA, LEN)
|
||||
#define _IO_WSYSREAD(FP, DATA, LEN) WJUMP2 (__read, FP, DATA, LEN)
|
||||
|
||||
/* The 'syswrite' hook is used to write data from an existing buffer
|
||||
to an external file. It generalizes the Unix write(2) function.
|
||||
It matches the streambuf::sys_write virtual function, which is
|
||||
specific to this implementation. */
|
||||
typedef _IO_ssize_t (*_IO_write_t) __PMT ((_IO_FILE *,const void *,_IO_ssize_t));
|
||||
typedef _IO_ssize_t (*_IO_write_t) __PMT ((_IO_FILE *, const void *,
|
||||
_IO_ssize_t));
|
||||
#define _IO_SYSWRITE(FP, DATA, LEN) JUMP2 (__write, FP, DATA, LEN)
|
||||
#define _IO_WSYSWRITE(FP, DATA, LEN) WJUMP2 (__write, FP, DATA, LEN)
|
||||
|
||||
/* The 'sysseek' hook is used to re-position an external file.
|
||||
It generalizes the Unix lseek(2) function.
|
||||
It matches the streambuf::sys_seek virtual function, which is
|
||||
specific to this implementation. */
|
||||
#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
||||
typedef _IO_off64_t (*_IO_seek_t) __PMT ((_IO_FILE *, _IO_off64_t, int));
|
||||
#else
|
||||
typedef _IO_off_t (*_IO_seek_t) __PMT ((_IO_FILE *, _IO_off_t, int));
|
||||
#endif
|
||||
#define _IO_SYSSEEK(FP, OFFSET, MODE) JUMP2 (__seek, FP, OFFSET, MODE)
|
||||
#define _IO_WSYSSEEK(FP, OFFSET, MODE) WJUMP2 (__seek, FP, OFFSET, MODE)
|
||||
|
||||
/* The 'sysclose' hook is used to finalize (close, finish up) an
|
||||
external file. It generalizes the Unix close(2) function.
|
||||
@ -225,6 +243,7 @@ typedef _IO_off_t (*_IO_seek_t) __PMT ((_IO_FILE *, _IO_off_t, int));
|
||||
specific to this implementation. */
|
||||
typedef int (*_IO_close_t) __PMT ((_IO_FILE *)); /* finalize */
|
||||
#define _IO_SYSCLOSE(FP) JUMP0 (__close, FP)
|
||||
#define _IO_WSYSCLOSE(FP) WJUMP0 (__close, FP)
|
||||
|
||||
/* The 'sysstat' hook is used to get information about an external file
|
||||
into a struct stat buffer. It generalizes the Unix fstat(2) call.
|
||||
@ -232,19 +251,20 @@ typedef int (*_IO_close_t) __PMT ((_IO_FILE *)); /* finalize */
|
||||
specific to this implementation. */
|
||||
typedef int (*_IO_stat_t) __PMT ((_IO_FILE *, void *));
|
||||
#define _IO_SYSSTAT(FP, BUF) JUMP1 (__stat, FP, BUF)
|
||||
#define _IO_WSYSSTAT(FP, BUF) WJUMP1 (__stat, FP, BUF)
|
||||
|
||||
#if _G_IO_IO_FILE_VERSION == 0x20001
|
||||
/* The 'showmany' hook can be used to get an image how much input is
|
||||
available. In many cases the answer will be 0 which means unknown
|
||||
but some cases one can provide real information. */
|
||||
typedef int (*_IO_showmanyc_t) __PMT ((_IO_FILE *));
|
||||
#define _IO_SHOWMANYC(FP) JUMP0 (__showmanyc, FP)
|
||||
#define _IO_WSHOWMANYC(FP) WJUMP0 (__showmanyc, FP)
|
||||
|
||||
/* The 'imbue' hook is used to get information about the currently
|
||||
installed locales. */
|
||||
typedef void (*_IO_imbue_t) __PMT ((_IO_FILE *, void *));
|
||||
#define _IO_IMBUE(FP, LOCALE) JUMP1 (__imbue, FP, LOCALE)
|
||||
#endif
|
||||
#define _IO_WIMBUE(FP, LOCALE) WJUMP1 (__imbue, FP, LOCALE)
|
||||
|
||||
|
||||
#define _IO_CHAR_TYPE char /* unsigned char ? */
|
||||
@ -274,10 +294,8 @@ struct _IO_jump_t
|
||||
JUMP_FIELD(_IO_seek_t, __seek);
|
||||
JUMP_FIELD(_IO_close_t, __close);
|
||||
JUMP_FIELD(_IO_stat_t, __stat);
|
||||
#if _G_IO_IO_FILE_VERSION == 0x20001
|
||||
JUMP_FIELD(_IO_showmanyc_t, __showmanyc);
|
||||
JUMP_FIELD(_IO_imbue_t, __imbue);
|
||||
#endif
|
||||
#if 0
|
||||
get_column;
|
||||
set_column;
|
||||
@ -295,15 +313,19 @@ struct _IO_FILE_plus
|
||||
const struct _IO_jump_t *vtable;
|
||||
};
|
||||
|
||||
/* Generic functions */
|
||||
/* Special file type for fopencookie function. */
|
||||
struct _IO_cookie_file
|
||||
{
|
||||
struct _IO_FILE_plus __fp;
|
||||
void *__cookie;
|
||||
_IO_cookie_io_functions_t __io_functions;
|
||||
};
|
||||
|
||||
#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
||||
extern _IO_off64_t _IO_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
|
||||
extern _IO_off64_t _IO_seekpos __P ((_IO_FILE *, _IO_off64_t, int));
|
||||
#else
|
||||
extern _IO_off_t _IO_seekoff __P ((_IO_FILE *, _IO_off_t, int, int));
|
||||
extern _IO_off_t _IO_seekpos __P ((_IO_FILE *, _IO_off_t, int));
|
||||
#endif
|
||||
/* Iterator type for walking global linked list of _IO_FILE objects. */
|
||||
|
||||
typedef struct _IO_FILE_plus *_IO_ITER;
|
||||
|
||||
/* Generic functions */
|
||||
|
||||
extern void _IO_switch_to_main_get_area __P ((_IO_FILE *));
|
||||
extern void _IO_switch_to_backup_area __P ((_IO_FILE *));
|
||||
@ -311,130 +333,245 @@ extern int _IO_switch_to_get_mode __P ((_IO_FILE *));
|
||||
extern void _IO_init __P ((_IO_FILE *, int));
|
||||
extern int _IO_sputbackc __P ((_IO_FILE *, int));
|
||||
extern int _IO_sungetc __P ((_IO_FILE *));
|
||||
extern void _IO_un_link __P ((_IO_FILE *));
|
||||
extern void _IO_link_in __P ((_IO_FILE *));
|
||||
extern void _IO_un_link __P ((struct _IO_FILE_plus *));
|
||||
extern void _IO_link_in __P ((struct _IO_FILE_plus *));
|
||||
extern void _IO_doallocbuf __P ((_IO_FILE *));
|
||||
extern void _IO_unsave_markers __P ((_IO_FILE *));
|
||||
extern void _IO_setb __P ((_IO_FILE *, char *, char *, int));
|
||||
extern unsigned _IO_adjust_column __P ((unsigned, const char *, int));
|
||||
#define _IO_sputn(__fp, __s, __n) _IO_XSPUTN (__fp, __s, __n)
|
||||
|
||||
extern void _IO_switch_to_main_wget_area __P ((_IO_FILE *));
|
||||
extern void _IO_switch_to_wbackup_area __P ((_IO_FILE *));
|
||||
extern int _IO_switch_to_wget_mode __P ((_IO_FILE *));
|
||||
extern void _IO_wsetb __P ((_IO_FILE *, wchar_t *, wchar_t *, int));
|
||||
extern wint_t _IO_sputbackwc __P ((_IO_FILE *, wint_t));
|
||||
extern wint_t _IO_sungetwc __P ((_IO_FILE *));
|
||||
extern void _IO_wdoallocbuf __P ((_IO_FILE *));
|
||||
extern void _IO_unsave_wmarkers __P ((_IO_FILE *));
|
||||
extern unsigned _IO_adjust_wcolumn __P ((unsigned, const wchar_t *, int));
|
||||
|
||||
/* Marker-related function. */
|
||||
|
||||
extern void _IO_init_marker __P ((struct _IO_marker *, _IO_FILE *));
|
||||
extern void _IO_init_wmarker __P ((struct _IO_marker *, _IO_FILE *));
|
||||
extern void _IO_remove_marker __P ((struct _IO_marker *));
|
||||
extern int _IO_marker_difference __P ((struct _IO_marker *,
|
||||
struct _IO_marker *));
|
||||
extern int _IO_marker_delta __P ((struct _IO_marker *));
|
||||
extern int _IO_wmarker_delta __P ((struct _IO_marker *));
|
||||
extern int _IO_seekmark __P ((_IO_FILE *, struct _IO_marker *, int));
|
||||
extern int _IO_seekwmark __P ((_IO_FILE *, struct _IO_marker *, int));
|
||||
|
||||
/* Functions for iterating global list and dealing with
|
||||
its lock */
|
||||
|
||||
extern _IO_ITER _IO_iter_begin __P ((void));
|
||||
extern _IO_ITER _IO_iter_end __P ((void));
|
||||
extern _IO_ITER _IO_iter_next __P ((_IO_ITER));
|
||||
extern _IO_FILE *_IO_iter_file __P ((_IO_ITER));
|
||||
extern void _IO_list_lock __P ((void));
|
||||
extern void _IO_list_unlock __P ((void));
|
||||
extern void _IO_list_resetlock __P ((void));
|
||||
|
||||
/* Default jumptable functions. */
|
||||
|
||||
extern int _IO_default_underflow __P ((_IO_FILE *));
|
||||
extern int _IO_default_uflow __P ((_IO_FILE *));
|
||||
extern wint_t _IO_wdefault_uflow __P ((_IO_FILE *));
|
||||
extern int _IO_default_doallocate __P ((_IO_FILE *));
|
||||
extern int _IO_wdefault_doallocate __P ((_IO_FILE *));
|
||||
extern void _IO_default_finish __P ((_IO_FILE *, int));
|
||||
extern void _IO_wdefault_finish __P ((_IO_FILE *, int));
|
||||
extern int _IO_default_pbackfail __P ((_IO_FILE *, int));
|
||||
extern wint_t _IO_wdefault_pbackfail __P ((_IO_FILE *, wint_t));
|
||||
extern _IO_FILE* _IO_default_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
|
||||
extern _IO_FILE* _IO_wdefault_setbuf __P ((_IO_FILE *, wchar_t *,
|
||||
_IO_ssize_t));
|
||||
extern _IO_size_t _IO_default_xsputn __P ((_IO_FILE *, const void *,
|
||||
_IO_size_t));
|
||||
extern _IO_size_t _IO_wdefault_xsputn __P ((_IO_FILE *, const void *,
|
||||
_IO_size_t));
|
||||
extern _IO_size_t _IO_default_xsgetn __P ((_IO_FILE *, void *, _IO_size_t));
|
||||
#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
||||
extern _IO_size_t _IO_wdefault_xsgetn __P ((_IO_FILE *, void *, _IO_size_t));
|
||||
extern _IO_off64_t _IO_default_seekoff __P ((_IO_FILE *,
|
||||
_IO_off64_t, int, int));
|
||||
extern _IO_off64_t _IO_default_seekpos __P ((_IO_FILE *,
|
||||
_IO_off64_t, int));
|
||||
extern _IO_off64_t _IO_default_seek __P ((_IO_FILE *, _IO_off64_t, int));
|
||||
#else
|
||||
extern _IO_off_t _IO_default_seekoff __P ((_IO_FILE *, _IO_off_t, int, int));
|
||||
extern _IO_off_t _IO_default_seekpos __P ((_IO_FILE *, _IO_off_t, int));
|
||||
extern _IO_off_t _IO_default_seek __P ((_IO_FILE *, _IO_off_t, int));
|
||||
#endif
|
||||
_IO_off64_t, int, int));
|
||||
extern _IO_off64_t _IO_default_seekpos __P ((_IO_FILE *, _IO_off64_t, int));
|
||||
extern _IO_ssize_t _IO_default_write __P ((_IO_FILE *, const void *,
|
||||
_IO_ssize_t));
|
||||
extern _IO_ssize_t _IO_default_read __P ((_IO_FILE *, void *, _IO_ssize_t));
|
||||
extern int _IO_default_stat __P ((_IO_FILE *, void *));
|
||||
extern _IO_off64_t _IO_default_seek __P ((_IO_FILE *, _IO_off64_t, int));
|
||||
extern int _IO_default_sync __P ((_IO_FILE *));
|
||||
#define _IO_default_close ((_IO_close_t) _IO_default_sync)
|
||||
extern int _IO_default_showmanyc __P ((_IO_FILE *));
|
||||
extern void _IO_default_imbue __P ((_IO_FILE *, void *));
|
||||
|
||||
extern struct _IO_jump_t _IO_file_jumps;
|
||||
extern struct _IO_jump_t _IO_wfile_jumps;
|
||||
extern struct _IO_jump_t _IO_old_file_jumps;
|
||||
extern struct _IO_jump_t _IO_streambuf_jumps;
|
||||
extern struct _IO_jump_t _IO_proc_jumps;
|
||||
extern struct _IO_jump_t _IO_old_proc_jumps;
|
||||
extern struct _IO_jump_t _IO_str_jumps;
|
||||
extern struct _IO_jump_t _IO_wstr_jumps;
|
||||
extern struct _IO_codecvt __libio_codecvt;
|
||||
extern int _IO_do_write __P ((_IO_FILE *, const char *, _IO_size_t));
|
||||
extern int _IO_new_do_write __P ((_IO_FILE *, const char *, _IO_size_t));
|
||||
extern int _IO_old_do_write __P ((_IO_FILE *, const char *, _IO_size_t));
|
||||
extern int _IO_wdo_write __P ((_IO_FILE *, const wchar_t *, _IO_size_t));
|
||||
extern int _IO_flush_all __P ((void));
|
||||
extern void _IO_cleanup __P ((void));
|
||||
extern int _IO_cleanup __P ((void));
|
||||
extern void _IO_flush_all_linebuffered __P ((void));
|
||||
extern int _IO_new_fgetpos __P ((_IO_FILE *, _IO_fpos_t *));
|
||||
extern int _IO_old_fgetpos __P ((_IO_FILE *, _IO_fpos_t *));
|
||||
extern int _IO_new_fsetpos __P ((_IO_FILE *, const _IO_fpos_t *));
|
||||
extern int _IO_old_fsetpos __P ((_IO_FILE *, const _IO_fpos_t *));
|
||||
extern int _IO_new_fgetpos64 __P ((_IO_FILE *, _IO_fpos64_t *));
|
||||
extern int _IO_old_fgetpos64 __P ((_IO_FILE *, _IO_fpos64_t *));
|
||||
extern int _IO_new_fsetpos64 __P ((_IO_FILE *, const _IO_fpos64_t *));
|
||||
extern int _IO_old_fsetpos64 __P ((_IO_FILE *, const _IO_fpos64_t *));
|
||||
|
||||
#define _IO_do_flush(_f) \
|
||||
_IO_do_write(_f, (_f)->_IO_write_base, \
|
||||
(_f)->_IO_write_ptr-(_f)->_IO_write_base)
|
||||
|
||||
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
|
||||
# define _IO_do_flush(_f) \
|
||||
((_f)->_mode <= 0 \
|
||||
? _IO_do_write(_f, (_f)->_IO_write_base, \
|
||||
(_f)->_IO_write_ptr-(_f)->_IO_write_base) \
|
||||
: _IO_wdo_write(_f, (_f)->_wide_data->_IO_write_base, \
|
||||
((_f)->_wide_data->_IO_write_ptr \
|
||||
- (_f)->_wide_data->_IO_write_base)))
|
||||
#else
|
||||
# define _IO_do_flush(_f) \
|
||||
_IO_do_write(_f, (_f)->_IO_write_base, \
|
||||
(_f)->_IO_write_ptr-(_f)->_IO_write_base)
|
||||
#endif
|
||||
#define _IO_old_do_flush(_f) \
|
||||
_IO_old_do_write(_f, (_f)->_IO_write_base, \
|
||||
(_f)->_IO_write_ptr-(_f)->_IO_write_base)
|
||||
#define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
|
||||
#define _IO_mask_flags(fp, f, mask) \
|
||||
((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
|
||||
#define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\
|
||||
(fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
|
||||
#define _IO_wsetg(fp, eb, g, eg) ((fp)->_wide_data->_IO_read_base = (eb),\
|
||||
(fp)->_wide_data->_IO_read_ptr = (g), \
|
||||
(fp)->_wide_data->_IO_read_end = (eg))
|
||||
#define _IO_setp(__fp, __p, __ep) \
|
||||
((__fp)->_IO_write_base = (__fp)->_IO_write_ptr = __p, (__fp)->_IO_write_end = (__ep))
|
||||
((__fp)->_IO_write_base = (__fp)->_IO_write_ptr \
|
||||
= __p, (__fp)->_IO_write_end = (__ep))
|
||||
#define _IO_wsetp(__fp, __p, __ep) \
|
||||
((__fp)->_wide_data->_IO_write_base \
|
||||
= (__fp)->_wide_data->_IO_write_ptr = __p, \
|
||||
(__fp)->_wide_data->_IO_write_end = (__ep))
|
||||
#define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL)
|
||||
#define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_save_base != NULL)
|
||||
#define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
|
||||
#define _IO_have_markers(fp) ((fp)->_markers != NULL)
|
||||
#define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
|
||||
#define _IO_wblen(fp) ((fp)->_wide_data->_IO_buf_end \
|
||||
- (fp)->_wide_data->_IO_buf_base)
|
||||
|
||||
/* Jumptable functions for files. */
|
||||
|
||||
extern int _IO_file_doallocate __P ((_IO_FILE *));
|
||||
extern _IO_FILE* _IO_file_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
|
||||
#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
||||
extern _IO_off64_t _IO_file_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
|
||||
extern _IO_off64_t _IO_file_seek __P ((_IO_FILE *, _IO_off64_t, int));
|
||||
#else
|
||||
extern _IO_off_t _IO_file_seekoff __P ((_IO_FILE *, _IO_off_t, int, int));
|
||||
extern _IO_off_t _IO_file_seek __P ((_IO_FILE *, _IO_off_t, int));
|
||||
#endif
|
||||
extern _IO_size_t _IO_file_xsputn __P ((_IO_FILE *, const void *, _IO_size_t));
|
||||
extern _IO_size_t _IO_file_xsgetn __P ((_IO_FILE *, void *, _IO_size_t));
|
||||
extern int _IO_file_stat __P ((_IO_FILE *, void *));
|
||||
extern int _IO_file_close __P ((_IO_FILE *));
|
||||
extern int _IO_file_underflow __P ((_IO_FILE *));
|
||||
extern int _IO_file_overflow __P ((_IO_FILE *, int));
|
||||
#define _IO_file_is_open(__fp) ((__fp)->_fileno >= 0)
|
||||
extern void _IO_file_init __P ((_IO_FILE *));
|
||||
#define _IO_file_is_open(__fp) ((__fp)->_fileno != -1)
|
||||
extern void _IO_file_init __P ((struct _IO_FILE_plus *));
|
||||
extern _IO_FILE* _IO_file_attach __P ((_IO_FILE *, int));
|
||||
extern _IO_FILE* _IO_file_open __P ((_IO_FILE *, const char *, int, int,
|
||||
int, int));
|
||||
#if _G_IO_IO_FILE_VERSION == 0x20001
|
||||
extern _IO_FILE* _IO_file_fopen __P ((_IO_FILE *, const char *, const char *,
|
||||
int));
|
||||
#else
|
||||
extern _IO_FILE* _IO_file_fopen __P ((_IO_FILE *, const char *, const char *));
|
||||
#endif
|
||||
extern _IO_ssize_t _IO_file_write __P ((_IO_FILE *, const void *,
|
||||
_IO_ssize_t));
|
||||
extern _IO_ssize_t _IO_file_read __P ((_IO_FILE *, void *, _IO_ssize_t));
|
||||
extern int _IO_file_sync __P ((_IO_FILE *));
|
||||
extern int _IO_file_close_it __P ((_IO_FILE *));
|
||||
extern _IO_off64_t _IO_file_seek __P ((_IO_FILE *, _IO_off64_t, int));
|
||||
extern void _IO_file_finish __P ((_IO_FILE *, int));
|
||||
|
||||
extern _IO_FILE* _IO_new_file_attach __P ((_IO_FILE *, int));
|
||||
extern int _IO_new_file_close_it __P ((_IO_FILE *));
|
||||
extern void _IO_new_file_finish __P ((_IO_FILE *, int));
|
||||
extern _IO_FILE* _IO_new_file_fopen __P ((_IO_FILE *, const char *, const char *,
|
||||
int));
|
||||
extern void _IO_no_init __P ((_IO_FILE *, int, int, struct _IO_wide_data *,
|
||||
struct _IO_jump_t *));
|
||||
extern void _IO_new_file_init __P ((struct _IO_FILE_plus *));
|
||||
extern _IO_FILE* _IO_new_file_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
|
||||
extern int _IO_new_file_sync __P ((_IO_FILE *));
|
||||
extern int _IO_new_file_underflow __P ((_IO_FILE *));
|
||||
extern int _IO_new_file_overflow __P ((_IO_FILE *, int));
|
||||
extern _IO_off64_t _IO_new_file_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
|
||||
extern _IO_ssize_t _IO_new_file_write __P ((_IO_FILE *, const void *,
|
||||
_IO_ssize_t));
|
||||
extern _IO_size_t _IO_new_file_xsputn __P ((_IO_FILE *, const void *, _IO_size_t));
|
||||
|
||||
extern _IO_FILE* _IO_old_file_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
|
||||
extern _IO_off64_t _IO_old_file_seekoff __P ((_IO_FILE *, _IO_off64_t, int,
|
||||
int));
|
||||
extern _IO_size_t _IO_old_file_xsputn __P ((_IO_FILE *, const void *,
|
||||
_IO_size_t));
|
||||
extern int _IO_old_file_underflow __P ((_IO_FILE *));
|
||||
extern int _IO_old_file_overflow __P ((_IO_FILE *, int));
|
||||
extern void _IO_old_file_init __P ((struct _IO_FILE_plus *));
|
||||
extern _IO_FILE* _IO_old_file_attach __P ((_IO_FILE *, int));
|
||||
extern _IO_FILE* _IO_old_file_fopen __P ((_IO_FILE *, const char *,
|
||||
const char *));
|
||||
extern _IO_ssize_t _IO_old_file_write __P ((_IO_FILE *, const void *,
|
||||
_IO_ssize_t));
|
||||
extern int _IO_old_file_sync __P ((_IO_FILE *));
|
||||
extern int _IO_old_file_close_it __P ((_IO_FILE *));
|
||||
extern void _IO_old_file_finish __P ((_IO_FILE *, int));
|
||||
|
||||
extern int _IO_wfile_doallocate __P ((_IO_FILE *));
|
||||
extern _IO_size_t _IO_wfile_xsputn __P ((_IO_FILE *, const void *,
|
||||
_IO_size_t));
|
||||
extern _IO_FILE* _IO_wfile_setbuf __P ((_IO_FILE *, wchar_t *, _IO_ssize_t));
|
||||
extern wint_t _IO_wfile_sync __P ((_IO_FILE *));
|
||||
extern wint_t _IO_wfile_underflow __P ((_IO_FILE *));
|
||||
extern wint_t _IO_wfile_overflow __P ((_IO_FILE *, wint_t));
|
||||
extern _IO_off64_t _IO_wfile_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
|
||||
|
||||
/* Jumptable functions for proc_files. */
|
||||
extern _IO_FILE* _IO_proc_open __P ((_IO_FILE *, const char *, const char *));
|
||||
extern _IO_FILE* _IO_new_proc_open __P ((_IO_FILE *, const char *, const char *));
|
||||
extern _IO_FILE* _IO_old_proc_open __P ((_IO_FILE *, const char *, const char *));
|
||||
extern int _IO_proc_close __P ((_IO_FILE *));
|
||||
extern int _IO_new_proc_close __P ((_IO_FILE *));
|
||||
extern int _IO_old_proc_close __P ((_IO_FILE *));
|
||||
|
||||
/* Jumptable functions for strfiles. */
|
||||
extern int _IO_str_underflow __P ((_IO_FILE *));
|
||||
extern int _IO_str_overflow __P ((_IO_FILE *, int));
|
||||
extern int _IO_str_pbackfail __P ((_IO_FILE *, int));
|
||||
#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
||||
extern _IO_off64_t _IO_str_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
|
||||
#else
|
||||
extern _IO_off_t _IO_str_seekoff __P ((_IO_FILE *, _IO_off_t, int, int));
|
||||
#endif
|
||||
extern void _IO_str_finish __P ((_IO_FILE *, int));
|
||||
|
||||
/* Other strfile functions */
|
||||
extern void _IO_str_init_static __P ((_IO_FILE *, char *, int, char *));
|
||||
extern void _IO_str_init_readonly __P ((_IO_FILE *, const char *, int));
|
||||
struct _IO_strfile_;
|
||||
extern void _IO_str_init_static __P ((struct _IO_strfile_ *, char *, int, char *));
|
||||
extern void _IO_str_init_readonly __P ((struct _IO_strfile_ *, const char *, int));
|
||||
extern _IO_ssize_t _IO_str_count __P ((_IO_FILE *));
|
||||
|
||||
/* And the wide character versions. */
|
||||
extern void _IO_wstr_init_static __P ((_IO_FILE *, wchar_t *, int, wchar_t *));
|
||||
extern void _IO_wstr_init_readonly __P ((_IO_FILE *, const char *, int));
|
||||
extern _IO_ssize_t _IO_wstr_count __P ((_IO_FILE *));
|
||||
extern _IO_wint_t _IO_wstr_overflow __P ((_IO_FILE *, _IO_wint_t));
|
||||
extern _IO_wint_t _IO_wstr_underflow __P ((_IO_FILE *));
|
||||
extern _IO_off64_t _IO_wstr_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
|
||||
extern _IO_wint_t _IO_wstr_pbackfail __P ((_IO_FILE *, _IO_wint_t));
|
||||
extern void _IO_wstr_finish __P ((_IO_FILE *, int));
|
||||
|
||||
extern int _IO_vasprintf __P ((char **result_ptr, __const char *format,
|
||||
_IO_va_list args));
|
||||
extern int _IO_vdprintf __P ((int d, __const char *format, _IO_va_list arg));
|
||||
@ -446,6 +583,10 @@ extern _IO_size_t _IO_getline __P ((_IO_FILE *,char *, _IO_size_t, int, int));
|
||||
extern _IO_size_t _IO_getline_info __P ((_IO_FILE *,char *, _IO_size_t,
|
||||
int, int, int *));
|
||||
extern _IO_ssize_t _IO_getdelim __P ((char **, _IO_size_t *, int, _IO_FILE *));
|
||||
extern _IO_size_t _IO_getwline __P ((_IO_FILE *,wchar_t *, _IO_size_t, wint_t,
|
||||
int));
|
||||
extern _IO_size_t _IO_getwline_info __P ((_IO_FILE *,wchar_t *, _IO_size_t,
|
||||
wint_t, int, wint_t *));
|
||||
extern double _IO_strtod __P ((const char *, char **));
|
||||
extern char *_IO_dtoa __P ((double __d, int __mode, int __ndigits,
|
||||
int *__decpt, int *__sign, char **__rve));
|
||||
@ -453,7 +594,7 @@ extern int _IO_outfloat __P ((double __value, _IO_FILE *__sb, int __type,
|
||||
int __width, int __precision, int __flags,
|
||||
int __sign_mode, int __fill));
|
||||
|
||||
extern _IO_FILE *_IO_list_all;
|
||||
extern struct _IO_FILE_plus *_IO_list_all;
|
||||
extern void (*_IO_cleanup_registration_needed) __PMT ((void));
|
||||
|
||||
#ifndef EOF
|
||||
@ -496,6 +637,7 @@ extern void (*_IO_cleanup_registration_needed) __PMT ((void));
|
||||
/* When using this code in the GNU libc we must not pollute the name space. */
|
||||
# define mmap __mmap
|
||||
# define munmap __munmap
|
||||
# define ftruncate __ftruncate
|
||||
# endif
|
||||
|
||||
# define ROUND_TO_PAGE(_S) \
|
||||
@ -508,7 +650,15 @@ extern void (*_IO_cleanup_registration_needed) __PMT ((void));
|
||||
(_B) = (char *) mmap (0, ROUND_TO_PAGE (_S), \
|
||||
PROT_READ | PROT_WRITE, \
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
|
||||
if ((_B) == (char *) -1) \
|
||||
if ((_B) == (char *) MAP_FAILED) \
|
||||
return (_R); \
|
||||
} while (0)
|
||||
# define ALLOC_WBUF(_B, _S, _R) \
|
||||
do { \
|
||||
(_B) = (wchar_t *) mmap (0, ROUND_TO_PAGE (_S), \
|
||||
PROT_READ | PROT_WRITE, \
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
|
||||
if ((_B) == (wchar_t *) MAP_FAILED) \
|
||||
return (_R); \
|
||||
} while (0)
|
||||
|
||||
@ -522,6 +672,12 @@ extern void (*_IO_cleanup_registration_needed) __PMT ((void));
|
||||
if ((_B) == NULL) \
|
||||
return (_R); \
|
||||
} while (0)
|
||||
# define ALLOC_WBUF(_B, _S, _R) \
|
||||
do { \
|
||||
(_B) = (wchar_t *)malloc(_S); \
|
||||
if ((_B) == NULL) \
|
||||
return (_R); \
|
||||
} while (0)
|
||||
|
||||
#endif /* _G_HAVE_MMAP */
|
||||
|
||||
@ -531,43 +687,22 @@ extern void (*_IO_cleanup_registration_needed) __PMT ((void));
|
||||
struct stat;
|
||||
extern _IO_ssize_t _IO_read __P ((int, void *, _IO_size_t));
|
||||
extern _IO_ssize_t _IO_write __P ((int, const void *, _IO_size_t));
|
||||
extern _IO_off_t _IO_lseek __P ((int, _IO_off_t, int));
|
||||
extern _IO_off64_t _IO_lseek __P ((int, _IO_off64_t, int));
|
||||
extern int _IO_close __P ((int));
|
||||
extern int _IO_fstat __P ((int, struct stat *));
|
||||
extern int _IO_vscanf __P ((const char *, _IO_va_list));
|
||||
|
||||
/* Operations on _IO_fpos_t.
|
||||
Normally, these are trivial, but we provide hooks for configurations
|
||||
where an _IO_fpos_t is a struct.
|
||||
Note that _IO_off_t must be an integral type. */
|
||||
|
||||
/* _IO_pos_BAD is an _IO_off_t value indicating error, unknown, or EOF. */
|
||||
/* _IO_pos_BAD is an _IO_off64_t value indicating error, unknown, or EOF. */
|
||||
#ifndef _IO_pos_BAD
|
||||
# if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
||||
# define _IO_pos_BAD ((_IO_off64_t) -1)
|
||||
# else
|
||||
# define _IO_pos_BAD ((_IO_off_t) -1)
|
||||
# endif
|
||||
# define _IO_pos_BAD ((_IO_off64_t) -1)
|
||||
#endif
|
||||
/* _IO_pos_as_off converts an _IO_fpos_t value to an _IO_off_t value. */
|
||||
#ifndef _IO_pos_as_off
|
||||
# if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
||||
# define _IO_pos_as_off(__pos) ((_IO_off64_t) (__pos))
|
||||
# else
|
||||
# define _IO_pos_as_off(__pos) ((_IO_off_t) (__pos))
|
||||
# endif
|
||||
#endif
|
||||
/* _IO_pos_adjust adjust an _IO_fpos_t by some number of bytes. */
|
||||
/* _IO_pos_adjust adjust an _IO_off64_t by some number of bytes. */
|
||||
#ifndef _IO_pos_adjust
|
||||
# define _IO_pos_adjust(__pos, __delta) ((__pos) += (__delta))
|
||||
# define _IO_pos_adjust(pos, delta) ((pos) += (delta))
|
||||
#endif
|
||||
/* _IO_pos_0 is an _IO_fpos_t value indicating beginning of file. */
|
||||
/* _IO_pos_0 is an _IO_off64_t value indicating beginning of file. */
|
||||
#ifndef _IO_pos_0
|
||||
# if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
||||
# define _IO_pos_0 ((_IO_fpos64_t) 0)
|
||||
# else
|
||||
# define _IO_pos_0 ((_IO_fpos_t) 0)
|
||||
# endif
|
||||
# define _IO_pos_0 ((_IO_off64_t) 0)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -576,15 +711,46 @@ extern int _IO_vscanf __P ((const char *, _IO_va_list));
|
||||
|
||||
#ifdef _IO_MTSAFE_IO
|
||||
/* check following! */
|
||||
# define FILEBUF_LITERAL(CHAIN, FLAGS, FD) \
|
||||
# ifdef _IO_USE_OLD_IO_FILE
|
||||
# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
|
||||
{ _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, \
|
||||
0, 0, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
|
||||
#else
|
||||
/* check following! */
|
||||
# define FILEBUF_LITERAL(CHAIN, FLAGS, FD) \
|
||||
0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
|
||||
# else
|
||||
# if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
|
||||
# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
|
||||
{ _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD }
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, \
|
||||
0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
|
||||
NULL, WDP, 0 }
|
||||
# else
|
||||
# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
|
||||
{ _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, \
|
||||
0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
|
||||
0 }
|
||||
# endif
|
||||
# endif
|
||||
#else
|
||||
# ifdef _IO_USE_OLD_IO_FILE
|
||||
# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
|
||||
{ _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, 0, _IO_pos_BAD }
|
||||
# else
|
||||
# if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
|
||||
# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
|
||||
{ _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, \
|
||||
0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
|
||||
NULL, WDP, 0 }
|
||||
# else
|
||||
# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
|
||||
{ _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, \
|
||||
0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
|
||||
0 }
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* VTABLE_LABEL defines NAME as of the CLASS class.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 1993, 1994, 1996, 1997 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1993, 1994, 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
|
||||
This file is part of the GNU IO Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
@ -31,21 +31,44 @@
|
||||
hand, we don't need a C++ compiler to build this file.) */
|
||||
|
||||
#include "libioP.h"
|
||||
|
||||
#ifdef _IO_MTSAFE_IO
|
||||
#define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
|
||||
static _IO_lock_t _IO_stdfile_##FD##_lock = _IO_lock_initializer; \
|
||||
struct _IO_FILE_plus NAME \
|
||||
= {FILEBUF_LITERAL(CHAIN, FLAGS, FD), &_IO_file_jumps}
|
||||
#else
|
||||
#define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
|
||||
struct _IO_FILE_plus NAME \
|
||||
= {FILEBUF_LITERAL(CHAIN, FLAGS, FD), &_IO_file_jumps}
|
||||
#ifndef _LIBC
|
||||
# include <bits/c++config.h>
|
||||
#endif
|
||||
|
||||
DEF_STDFILE(_IO_stdin_, 0, 0, _IO_NO_WRITES);
|
||||
DEF_STDFILE(_IO_stdout_, 1, &_IO_stdin_.file, _IO_NO_READS);
|
||||
DEF_STDFILE(_IO_stderr_, 2, &_IO_stdout_.file,
|
||||
_IO_NO_READS+_IO_UNBUFFERED);
|
||||
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
|
||||
# ifdef _IO_MTSAFE_IO
|
||||
# define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
|
||||
static _IO_lock_t _IO_stdfile_##FD##_lock = _IO_lock_initializer; \
|
||||
static struct _IO_wide_data _IO_wide_data_##FD \
|
||||
= { ._wide_vtable = &_IO_wfile_jumps }; \
|
||||
struct _IO_FILE_plus NAME \
|
||||
= {FILEBUF_LITERAL(CHAIN, FLAGS, FD, &_IO_wide_data_##FD), \
|
||||
&_IO_file_jumps};
|
||||
# else
|
||||
# define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
|
||||
static struct _IO_wide_data _IO_wide_data_##FD \
|
||||
= { ._wide_vtable = &_IO_wfile_jumps }; \
|
||||
struct _IO_FILE_plus NAME \
|
||||
= {FILEBUF_LITERAL(CHAIN, FLAGS, FD, &_IO_wide_data_##FD), \
|
||||
&_IO_file_jumps};
|
||||
# endif
|
||||
#else
|
||||
# ifdef _IO_MTSAFE_IO
|
||||
# define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
|
||||
static _IO_lock_t _IO_stdfile_##FD##_lock = _IO_lock_initializer; \
|
||||
struct _IO_FILE_plus NAME \
|
||||
= {FILEBUF_LITERAL(CHAIN, FLAGS, FD, NULL), \
|
||||
&_IO_file_jumps};
|
||||
# else
|
||||
# define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
|
||||
struct _IO_FILE_plus NAME \
|
||||
= {FILEBUF_LITERAL(CHAIN, FLAGS, FD, NULL), \
|
||||
&_IO_file_jumps};
|
||||
# endif
|
||||
#endif
|
||||
|
||||
_IO_FILE *_IO_list_all = &_IO_stderr_.file;
|
||||
DEF_STDFILE(_IO_2_1_stdin_, 0, 0, _IO_NO_WRITES);
|
||||
DEF_STDFILE(_IO_2_1_stdout_, 1, &_IO_2_1_stdin_, _IO_NO_READS);
|
||||
DEF_STDFILE(_IO_2_1_stderr_, 2, &_IO_2_1_stdout_, _IO_NO_READS+_IO_UNBUFFERED);
|
||||
|
||||
struct _IO_FILE_plus *_IO_list_all = &_IO_2_1_stderr_;
|
||||
|
105
libstdc++-v3/libio/wfiledoalloc.c
Normal file
105
libstdc++-v3/libio/wfiledoalloc.c
Normal file
@ -0,0 +1,105 @@
|
||||
/* Copyright (C) 1993, 1997, 1999 Free Software Foundation, Inc.
|
||||
This file is part of the GNU IO Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2, or (at
|
||||
your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this library; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does
|
||||
not cause the resulting executable to be covered by the GNU General
|
||||
Public License. This exception does not however invalidate any
|
||||
other reasons why the executable file might be covered by the GNU
|
||||
General Public License. */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the University of California, Berkeley. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
/* Modified for GNU iostream by Per Bothner 1991, 1992. */
|
||||
|
||||
#ifndef _POSIX_SOURCE
|
||||
# define _POSIX_SOURCE
|
||||
#endif
|
||||
#include "libioP.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef __STDC__
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef _LIBC
|
||||
# undef isatty
|
||||
# define isatty(Fd) __isatty (Fd)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Allocate a file buffer, or switch to unbuffered I/O.
|
||||
* Per the ANSI C standard, ALL tty devices default to line buffered.
|
||||
*
|
||||
* As a side effect, we set __SOPT or __SNPT (en/dis-able fseek
|
||||
* optimisation) right after the _fstat() that finds the buffer size.
|
||||
*/
|
||||
|
||||
int
|
||||
_IO_wfile_doallocate (fp)
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
_IO_size_t size;
|
||||
int couldbetty;
|
||||
wchar_t *p;
|
||||
struct _G_stat64 st;
|
||||
|
||||
/* Allocate room for the external buffer. */
|
||||
_IO_file_doallocate (fp);
|
||||
|
||||
if (fp->_fileno < 0 || _IO_SYSSTAT (fp, &st) < 0)
|
||||
{
|
||||
couldbetty = 0;
|
||||
size = _IO_BUFSIZ * sizeof (wchar_t);
|
||||
#if 0
|
||||
/* do not try to optimise fseek() */
|
||||
fp->_flags |= __SNPT;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
couldbetty = S_ISCHR (st.st_mode);
|
||||
#if _IO_HAVE_ST_BLKSIZE
|
||||
size = ((st.st_blksize <= 0 ? _IO_BUFSIZ : st.st_blksize)
|
||||
* sizeof (wchar_t));
|
||||
#else
|
||||
size = _IO_BUFSIZ * sizeof (wchar_t);
|
||||
#endif
|
||||
}
|
||||
ALLOC_WBUF (p, size, EOF);
|
||||
_IO_wsetb (fp, p, p + size, 1);
|
||||
if (couldbetty && isatty (fp->_fileno))
|
||||
fp->_flags |= _IO_LINE_BUF;
|
||||
return 1;
|
||||
}
|
734
libstdc++-v3/libio/wfileops.c
Normal file
734
libstdc++-v3/libio/wfileops.c
Normal file
@ -0,0 +1,734 @@
|
||||
/* Copyright (C) 1993, 1995, 1997, 1998, 1999 Free Software Foundation, Inc.
|
||||
This file is part of the GNU IO Library.
|
||||
Written by Ulrich Drepper <drepper@cygnus.com>.
|
||||
Based on the single byte version by Per Bothner <bothner@cygnus.com>.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2, or (at
|
||||
your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this library; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does
|
||||
not cause the resulting executable to be covered by the GNU General
|
||||
Public License. This exception does not however invalidate any
|
||||
other reasons why the executable file might be covered by the GNU
|
||||
General Public License. */
|
||||
|
||||
#include <assert.h>
|
||||
#include <libioP.h>
|
||||
#include <wchar.h>
|
||||
#include <gconv.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#ifndef _LIBC
|
||||
# define _IO_new_do_write _IO_do_write
|
||||
# define _IO_new_file_attach _IO_file_attach
|
||||
# define _IO_new_file_close_it _IO_file_close_it
|
||||
# define _IO_new_file_finish _IO_file_finish
|
||||
# define _IO_new_file_fopen _IO_file_fopen
|
||||
# define _IO_new_file_init _IO_file_init
|
||||
# define _IO_new_file_setbuf _IO_file_setbuf
|
||||
# define _IO_new_file_sync _IO_file_sync
|
||||
# define _IO_new_file_overflow _IO_file_overflow
|
||||
# define _IO_new_file_seekoff _IO_file_seekoff
|
||||
# define _IO_new_file_underflow _IO_file_underflow
|
||||
# define _IO_new_file_write _IO_file_write
|
||||
# define _IO_new_file_xsputn _IO_file_xsputn
|
||||
#endif
|
||||
|
||||
|
||||
_IO_FILE *
|
||||
_IO_wfile_setbuf (fp, p, len)
|
||||
_IO_FILE *fp;
|
||||
wchar_t *p;
|
||||
_IO_ssize_t len;
|
||||
{
|
||||
if (_IO_wdefault_setbuf (fp, p, len) == NULL)
|
||||
return NULL;
|
||||
|
||||
fp->_wide_data->_IO_write_base = fp->_wide_data->_IO_write_ptr =
|
||||
fp->_wide_data->_IO_write_end = fp->_wide_data->_IO_buf_base;
|
||||
_IO_wsetg (fp, fp->_wide_data->_IO_buf_base, fp->_wide_data->_IO_buf_base,
|
||||
fp->_wide_data->_IO_buf_base);
|
||||
|
||||
return fp;
|
||||
}
|
||||
|
||||
|
||||
/* Convert TO_DO wide character from DATA to FP.
|
||||
Then mark FP as having empty buffers. */
|
||||
int
|
||||
_IO_wdo_write (fp, data, to_do)
|
||||
_IO_FILE *fp;
|
||||
const wchar_t *data;
|
||||
_IO_size_t to_do;
|
||||
{
|
||||
struct _IO_codecvt *cc = &fp->_wide_data->_codecvt;
|
||||
_IO_size_t count = 0;
|
||||
|
||||
while (to_do > 0)
|
||||
{
|
||||
enum __codecvt_result result;
|
||||
const wchar_t *new_data;
|
||||
|
||||
if (fp->_IO_write_end == fp->_IO_write_ptr)
|
||||
{
|
||||
_IO_new_file_overflow (fp, EOF);
|
||||
assert (fp->_IO_write_end > fp->_IO_write_ptr);
|
||||
}
|
||||
|
||||
/* Now convert from the internal format into the external buffer. */
|
||||
result = (*cc->__codecvt_do_out) (cc, &fp->_wide_data->_IO_state,
|
||||
data, data + to_do, &new_data,
|
||||
fp->_IO_write_ptr,
|
||||
fp->_IO_write_end,
|
||||
&fp->_IO_write_ptr);
|
||||
|
||||
/* Write out what we produced so far. */
|
||||
if (_IO_new_do_write (fp, fp->_IO_write_base,
|
||||
fp->_IO_write_ptr - fp->_IO_write_base) == EOF)
|
||||
/* Something went wrong. */
|
||||
return EOF;
|
||||
|
||||
count += new_data - data;
|
||||
to_do -= new_data - data;
|
||||
data = new_data;
|
||||
|
||||
/* Next see whether we had problems during the conversion. If yes,
|
||||
we cannot go on. */
|
||||
if (result != __codecvt_ok)
|
||||
break;
|
||||
}
|
||||
|
||||
_IO_wsetg (fp, fp->_wide_data->_IO_buf_base, fp->_wide_data->_IO_buf_base,
|
||||
fp->_wide_data->_IO_buf_base);
|
||||
fp->_wide_data->_IO_write_base = fp->_wide_data->_IO_write_ptr
|
||||
= fp->_wide_data->_IO_buf_base;
|
||||
fp->_wide_data->_IO_write_end = ((fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
|
||||
? fp->_wide_data->_IO_buf_base
|
||||
: fp->_wide_data->_IO_buf_end);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
wint_t
|
||||
_IO_wfile_underflow (fp)
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
struct _IO_codecvt *cd;
|
||||
enum __codecvt_result status;
|
||||
_IO_ssize_t count;
|
||||
int tries;
|
||||
const char *read_ptr_copy;
|
||||
|
||||
if (fp->_flags & _IO_NO_READS)
|
||||
{
|
||||
fp->_flags |= _IO_ERR_SEEN;
|
||||
__set_errno (EBADF);
|
||||
return WEOF;
|
||||
}
|
||||
if (fp->_wide_data->_IO_read_ptr < fp->_wide_data->_IO_read_end)
|
||||
return *fp->_wide_data->_IO_read_ptr;
|
||||
|
||||
cd = &fp->_wide_data->_codecvt;
|
||||
|
||||
/* Maybe there is something left in the external buffer. */
|
||||
if (fp->_IO_read_ptr < fp->_IO_read_end)
|
||||
{
|
||||
/* Convert it. */
|
||||
size_t avail_bytes = fp->_IO_read_end - fp->_IO_read_ptr;
|
||||
|
||||
if (avail_bytes >= (*cd->__codecvt_do_max_length) (cd))
|
||||
{
|
||||
/* There is more in the external. */
|
||||
const char *read_stop = (const char *) fp->_IO_read_ptr;
|
||||
|
||||
fp->_wide_data->_IO_last_state = fp->_wide_data->_IO_state;
|
||||
status = (*cd->__codecvt_do_in) (cd, &fp->_wide_data->_IO_state,
|
||||
fp->_IO_read_ptr, fp->_IO_read_end,
|
||||
&read_stop,
|
||||
fp->_wide_data->_IO_read_end,
|
||||
fp->_wide_data->_IO_buf_end,
|
||||
&fp->_wide_data->_IO_read_end);
|
||||
|
||||
fp->_IO_read_ptr = (char *) read_stop;
|
||||
|
||||
/* If we managed to generate some text return the next character. */
|
||||
if (fp->_wide_data->_IO_read_ptr < fp->_wide_data->_IO_read_end)
|
||||
return *fp->_wide_data->_IO_read_ptr;
|
||||
|
||||
if (status == __codecvt_error)
|
||||
{
|
||||
__set_errno (EILSEQ);
|
||||
fp->_flags |= _IO_ERR_SEEN;
|
||||
return WEOF;
|
||||
}
|
||||
}
|
||||
|
||||
/* Move the remaining content of the read buffer to the beginning. */
|
||||
memmove (fp->_IO_buf_base, fp->_IO_read_ptr,
|
||||
fp->_IO_read_end - fp->_IO_read_ptr);
|
||||
fp->_IO_read_end = (fp->_IO_buf_base
|
||||
+ (fp->_IO_read_end - fp->_IO_read_ptr));
|
||||
fp->_IO_read_base = fp->_IO_read_ptr = fp->_IO_buf_base;
|
||||
}
|
||||
else
|
||||
fp->_IO_read_base = fp->_IO_read_ptr = fp->_IO_read_end =
|
||||
fp->_IO_buf_base;
|
||||
|
||||
fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end =
|
||||
fp->_IO_buf_base;
|
||||
|
||||
if (fp->_IO_buf_base == NULL)
|
||||
{
|
||||
/* Maybe we already have a push back pointer. */
|
||||
if (fp->_IO_save_base != NULL)
|
||||
{
|
||||
free (fp->_IO_save_base);
|
||||
fp->_flags &= ~_IO_IN_BACKUP;
|
||||
}
|
||||
_IO_doallocbuf (fp);
|
||||
}
|
||||
|
||||
if (fp->_wide_data->_IO_buf_base == NULL)
|
||||
{
|
||||
/* Maybe we already have a push back pointer. */
|
||||
if (fp->_wide_data->_IO_save_base != NULL)
|
||||
{
|
||||
free (fp->_wide_data->_IO_save_base);
|
||||
fp->_flags &= ~_IO_IN_BACKUP;
|
||||
}
|
||||
_IO_wdoallocbuf (fp);
|
||||
}
|
||||
|
||||
/* Flush all line buffered files before reading. */
|
||||
/* FIXME This can/should be moved to genops ?? */
|
||||
if (fp->_flags & (_IO_LINE_BUF|_IO_UNBUFFERED))
|
||||
_IO_flush_all_linebuffered ();
|
||||
|
||||
_IO_switch_to_get_mode (fp);
|
||||
|
||||
fp->_IO_read_base = fp->_IO_read_ptr = fp->_IO_buf_base;
|
||||
fp->_IO_read_end = fp->_IO_buf_base;
|
||||
fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end
|
||||
= fp->_IO_buf_base;
|
||||
|
||||
fp->_wide_data->_IO_read_base = fp->_wide_data->_IO_read_ptr =
|
||||
fp->_wide_data->_IO_buf_base;
|
||||
fp->_wide_data->_IO_read_end = fp->_wide_data->_IO_buf_base;
|
||||
fp->_wide_data->_IO_write_base = fp->_wide_data->_IO_write_ptr =
|
||||
fp->_wide_data->_IO_write_end = fp->_wide_data->_IO_buf_base;
|
||||
|
||||
tries = 0;
|
||||
again:
|
||||
count = _IO_SYSREAD (fp, fp->_IO_read_end,
|
||||
fp->_IO_buf_end - fp->_IO_read_end);
|
||||
if (count <= 0)
|
||||
{
|
||||
if (count == 0 && tries == 0)
|
||||
fp->_flags |= _IO_EOF_SEEN;
|
||||
else
|
||||
fp->_flags |= _IO_ERR_SEEN, count = 0;
|
||||
}
|
||||
fp->_IO_read_end += count;
|
||||
if (count == 0)
|
||||
{
|
||||
if (tries != 0)
|
||||
/* There are some bytes in the external buffer but they don't
|
||||
convert to anything. */
|
||||
__set_errno (EILSEQ);
|
||||
return WEOF;
|
||||
}
|
||||
if (fp->_offset != _IO_pos_BAD)
|
||||
_IO_pos_adjust (fp->_offset, count);
|
||||
|
||||
/* Now convert the read input. */
|
||||
fp->_wide_data->_IO_last_state = fp->_wide_data->_IO_state;
|
||||
fp->_IO_read_base = fp->_IO_read_ptr;
|
||||
status = (*cd->__codecvt_do_in) (cd, &fp->_wide_data->_IO_state,
|
||||
fp->_IO_read_ptr, fp->_IO_read_end,
|
||||
&read_ptr_copy,
|
||||
fp->_wide_data->_IO_read_end,
|
||||
fp->_wide_data->_IO_buf_end,
|
||||
&fp->_wide_data->_IO_read_end);
|
||||
|
||||
fp->_IO_read_ptr = (char *) read_ptr_copy;
|
||||
if (fp->_wide_data->_IO_read_end == fp->_wide_data->_IO_buf_base)
|
||||
{
|
||||
if (status == __codecvt_error || fp->_IO_read_end == fp->_IO_buf_end)
|
||||
{
|
||||
__set_errno (EILSEQ);
|
||||
fp->_flags |= _IO_ERR_SEEN;
|
||||
return WEOF;
|
||||
}
|
||||
|
||||
/* The read bytes make no complete character. Try reading again. */
|
||||
assert (status == __codecvt_partial);
|
||||
++tries;
|
||||
goto again;
|
||||
}
|
||||
|
||||
return *fp->_wide_data->_IO_read_ptr;
|
||||
}
|
||||
|
||||
|
||||
wint_t
|
||||
_IO_wfile_overflow (f, wch)
|
||||
_IO_FILE *f;
|
||||
wint_t wch;
|
||||
{
|
||||
if (f->_flags & _IO_NO_WRITES) /* SET ERROR */
|
||||
{
|
||||
f->_flags |= _IO_ERR_SEEN;
|
||||
__set_errno (EBADF);
|
||||
return WEOF;
|
||||
}
|
||||
/* If currently reading or no buffer allocated. */
|
||||
if ((f->_flags & _IO_CURRENTLY_PUTTING) == 0)
|
||||
{
|
||||
/* Allocate a buffer if needed. */
|
||||
if (f->_wide_data->_IO_write_base == 0)
|
||||
{
|
||||
_IO_wdoallocbuf (f);
|
||||
_IO_wsetg (f, f->_wide_data->_IO_buf_base,
|
||||
f->_wide_data->_IO_buf_base, f->_wide_data->_IO_buf_base);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Otherwise must be currently reading. If _IO_read_ptr
|
||||
(and hence also _IO_read_end) is at the buffer end,
|
||||
logically slide the buffer forwards one block (by setting
|
||||
the read pointers to all point at the beginning of the
|
||||
block). This makes room for subsequent output.
|
||||
Otherwise, set the read pointers to _IO_read_end (leaving
|
||||
that alone, so it can continue to correspond to the
|
||||
external position). */
|
||||
if (f->_wide_data->_IO_read_ptr == f->_wide_data->_IO_buf_end)
|
||||
{
|
||||
f->_IO_read_end = f->_IO_read_ptr = f->_IO_buf_base;
|
||||
f->_wide_data->_IO_read_end = f->_wide_data->_IO_read_ptr =
|
||||
f->_wide_data->_IO_buf_base;
|
||||
}
|
||||
}
|
||||
f->_wide_data->_IO_write_ptr = f->_wide_data->_IO_read_ptr;
|
||||
f->_wide_data->_IO_write_base = f->_wide_data->_IO_write_ptr;
|
||||
f->_wide_data->_IO_write_end = f->_wide_data->_IO_buf_end;
|
||||
f->_wide_data->_IO_read_base = f->_wide_data->_IO_read_ptr =
|
||||
f->_wide_data->_IO_read_end;
|
||||
|
||||
f->_flags |= _IO_CURRENTLY_PUTTING;
|
||||
if (f->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
|
||||
f->_wide_data->_IO_write_end = f->_wide_data->_IO_write_ptr;
|
||||
}
|
||||
if (wch == WEOF)
|
||||
return _IO_do_flush (f);
|
||||
if (f->_wide_data->_IO_write_ptr == f->_wide_data->_IO_buf_end )
|
||||
/* Buffer is really full */
|
||||
if (_IO_do_flush (f) == WEOF)
|
||||
return WEOF;
|
||||
*f->_wide_data->_IO_write_ptr++ = wch;
|
||||
if ((f->_flags & _IO_UNBUFFERED)
|
||||
|| ((f->_flags & _IO_LINE_BUF) && wch == L'\n'))
|
||||
if (_IO_do_flush (f) == WEOF)
|
||||
return WEOF;
|
||||
return wch;
|
||||
}
|
||||
|
||||
wint_t
|
||||
_IO_wfile_sync (fp)
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
_IO_ssize_t delta;
|
||||
wint_t retval = 0;
|
||||
|
||||
/* char* ptr = cur_ptr(); */
|
||||
if (fp->_wide_data->_IO_write_ptr > fp->_wide_data->_IO_write_base)
|
||||
if (_IO_do_flush (fp))
|
||||
return WEOF;
|
||||
delta = fp->_wide_data->_IO_read_ptr - fp->_wide_data->_IO_read_end;
|
||||
if (delta != 0)
|
||||
{
|
||||
/* We have to find out how many bytes we have to go back in the
|
||||
external buffer. */
|
||||
struct _IO_codecvt *cv = &fp->_wide_data->_codecvt;
|
||||
_IO_off64_t new_pos;
|
||||
|
||||
int clen = (*cv->__codecvt_do_encoding) (cv);
|
||||
|
||||
if (clen > 0)
|
||||
/* It is easy, a fixed number of input bytes are used for each
|
||||
wide character. */
|
||||
delta *= clen;
|
||||
else
|
||||
{
|
||||
/* We have to find out the hard way how much to back off.
|
||||
To do this we determine how much input we needed to
|
||||
generate the wide characters up to the current reading
|
||||
position. */
|
||||
int nread;
|
||||
|
||||
fp->_wide_data->_IO_state = fp->_wide_data->_IO_last_state;
|
||||
nread = (*cv->__codecvt_do_length) (cv, &fp->_wide_data->_IO_state,
|
||||
fp->_IO_read_base,
|
||||
fp->_IO_read_end, delta);
|
||||
fp->_IO_read_ptr = fp->_IO_read_base + nread;
|
||||
delta = -(fp->_IO_read_end - fp->_IO_read_base - nread);
|
||||
}
|
||||
|
||||
new_pos = _IO_SYSSEEK (fp, delta, 1);
|
||||
if (new_pos != (_IO_off64_t) EOF)
|
||||
{
|
||||
fp->_wide_data->_IO_read_end = fp->_wide_data->_IO_read_ptr;
|
||||
fp->_IO_read_end = fp->_IO_read_ptr;
|
||||
}
|
||||
#ifdef ESPIPE
|
||||
else if (errno == ESPIPE)
|
||||
; /* Ignore error from unseekable devices. */
|
||||
#endif
|
||||
else
|
||||
retval = WEOF;
|
||||
}
|
||||
if (retval != WEOF)
|
||||
fp->_offset = _IO_pos_BAD;
|
||||
/* FIXME: Cleanup - can this be shared? */
|
||||
/* setg(base(), ptr, ptr); */
|
||||
return retval;
|
||||
}
|
||||
|
||||
_IO_off64_t
|
||||
_IO_wfile_seekoff (fp, offset, dir, mode)
|
||||
_IO_FILE *fp;
|
||||
_IO_off64_t offset;
|
||||
int dir;
|
||||
int mode;
|
||||
{
|
||||
_IO_off64_t result;
|
||||
_IO_off64_t delta, new_offset;
|
||||
long int count;
|
||||
/* POSIX.1 8.2.3.7 says that after a call the fflush() the file
|
||||
offset of the underlying file must be exact. */
|
||||
int must_be_exact = ((fp->_wide_data->_IO_read_base
|
||||
== fp->_wide_data->_IO_read_end)
|
||||
&& (fp->_wide_data->_IO_write_base
|
||||
== fp->_wide_data->_IO_write_ptr));
|
||||
|
||||
if (mode == 0)
|
||||
dir = _IO_seek_cur, offset = 0; /* Don't move any pointers. */
|
||||
|
||||
/* Flush unwritten characters.
|
||||
(This may do an unneeded write if we seek within the buffer.
|
||||
But to be able to switch to reading, we would need to set
|
||||
egptr to ptr. That can't be done in the current design,
|
||||
which assumes file_ptr() is eGptr. Anyway, since we probably
|
||||
end up flushing when we close(), it doesn't make much difference.)
|
||||
FIXME: simulate mem-papped files. */
|
||||
|
||||
if (fp->_wide_data->_IO_write_ptr > fp->_wide_data->_IO_write_base
|
||||
|| _IO_in_put_mode (fp))
|
||||
if (_IO_switch_to_wget_mode (fp))
|
||||
return WEOF;
|
||||
|
||||
if (fp->_wide_data->_IO_buf_base == NULL)
|
||||
{
|
||||
/* It could be that we already have a pushback buffer. */
|
||||
if (fp->_wide_data->_IO_read_base != NULL)
|
||||
{
|
||||
free (fp->_wide_data->_IO_read_base);
|
||||
fp->_flags &= ~_IO_IN_BACKUP;
|
||||
}
|
||||
_IO_doallocbuf (fp);
|
||||
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
|
||||
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
|
||||
_IO_wsetp (fp, fp->_wide_data->_IO_buf_base,
|
||||
fp->_wide_data->_IO_buf_base);
|
||||
_IO_wsetg (fp, fp->_wide_data->_IO_buf_base,
|
||||
fp->_wide_data->_IO_buf_base, fp->_wide_data->_IO_buf_base);
|
||||
}
|
||||
|
||||
switch (dir)
|
||||
{
|
||||
struct _IO_codecvt *cv;
|
||||
int clen;
|
||||
|
||||
case _IO_seek_cur:
|
||||
/* Adjust for read-ahead (bytes is buffer). To do this we must
|
||||
find out which position in the external buffer corresponds to
|
||||
the current position in the internal buffer. */
|
||||
cv = &fp->_wide_data->_codecvt;
|
||||
clen = (*cv->__codecvt_do_encoding) (cv);
|
||||
|
||||
if (clen > 0)
|
||||
offset -= (fp->_wide_data->_IO_read_end
|
||||
- fp->_wide_data->_IO_read_ptr) * clen;
|
||||
else
|
||||
{
|
||||
int nread;
|
||||
|
||||
delta = fp->_wide_data->_IO_read_ptr - fp->_wide_data->_IO_read_end;
|
||||
fp->_wide_data->_IO_state = fp->_wide_data->_IO_last_state;
|
||||
nread = (*cv->__codecvt_do_length) (cv, &fp->_wide_data->_IO_state,
|
||||
fp->_IO_read_base,
|
||||
fp->_IO_read_end, delta);
|
||||
fp->_IO_read_ptr = fp->_IO_read_base + nread;
|
||||
offset -= fp->_IO_read_end - fp->_IO_read_base - nread;
|
||||
}
|
||||
|
||||
if (fp->_offset == _IO_pos_BAD)
|
||||
goto dumb;
|
||||
/* Make offset absolute, assuming current pointer is file_ptr(). */
|
||||
offset += fp->_offset;
|
||||
|
||||
dir = _IO_seek_set;
|
||||
break;
|
||||
case _IO_seek_set:
|
||||
break;
|
||||
case _IO_seek_end:
|
||||
{
|
||||
struct _G_stat64 st;
|
||||
if (_IO_SYSSTAT (fp, &st) == 0 && S_ISREG (st.st_mode))
|
||||
{
|
||||
offset += st.st_size;
|
||||
dir = _IO_seek_set;
|
||||
}
|
||||
else
|
||||
goto dumb;
|
||||
}
|
||||
}
|
||||
/* At this point, dir==_IO_seek_set. */
|
||||
|
||||
/* If we are only interested in the current position we've found it now. */
|
||||
if (mode == 0)
|
||||
return offset;
|
||||
|
||||
/* If destination is within current buffer, optimize: */
|
||||
if (fp->_offset != _IO_pos_BAD && fp->_IO_read_base != NULL
|
||||
&& !_IO_in_backup (fp))
|
||||
{
|
||||
/* Offset relative to start of main get area. */
|
||||
_IO_off64_t rel_offset = (offset - fp->_offset
|
||||
+ (fp->_IO_read_end - fp->_IO_read_base));
|
||||
if (rel_offset >= 0)
|
||||
{
|
||||
#if 0
|
||||
if (_IO_in_backup (fp))
|
||||
_IO_switch_to_main_get_area (fp);
|
||||
#endif
|
||||
if (rel_offset <= fp->_IO_read_end - fp->_IO_read_base)
|
||||
{
|
||||
fp->_IO_read_ptr = fp->_IO_read_base + rel_offset;
|
||||
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
|
||||
|
||||
/* Now set the pointer for the internal buffer. This
|
||||
might be an iterative process. Though the read
|
||||
pointer is somewhere in the current external buffer
|
||||
this does not mean we can convert this whole buffer
|
||||
at once fitting in the internal buffer. */
|
||||
do
|
||||
{
|
||||
|
||||
}
|
||||
while (0);
|
||||
|
||||
_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
|
||||
goto resync;
|
||||
}
|
||||
#ifdef TODO
|
||||
/* If we have streammarkers, seek forward by reading ahead. */
|
||||
if (_IO_have_markers (fp))
|
||||
{
|
||||
int to_skip = rel_offset
|
||||
- (fp->_IO_read_ptr - fp->_IO_read_base);
|
||||
if (ignore (to_skip) != to_skip)
|
||||
goto dumb;
|
||||
_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
|
||||
goto resync;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef TODO
|
||||
if (rel_offset < 0 && rel_offset >= Bbase () - Bptr ())
|
||||
{
|
||||
if (!_IO_in_backup (fp))
|
||||
_IO_switch_to_backup_area (fp);
|
||||
gbump (fp->_IO_read_end + rel_offset - fp->_IO_read_ptr);
|
||||
_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
|
||||
goto resync;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef TODO
|
||||
_IO_unsave_markers (fp);
|
||||
#endif
|
||||
|
||||
if (fp->_flags & _IO_NO_READS)
|
||||
goto dumb;
|
||||
|
||||
/* Try to seek to a block boundary, to improve kernel page management. */
|
||||
new_offset = offset & ~(fp->_IO_buf_end - fp->_IO_buf_base - 1);
|
||||
delta = offset - new_offset;
|
||||
if (delta > fp->_IO_buf_end - fp->_IO_buf_base)
|
||||
{
|
||||
new_offset = offset;
|
||||
delta = 0;
|
||||
}
|
||||
result = _IO_SYSSEEK (fp, new_offset, 0);
|
||||
if (result < 0)
|
||||
return EOF;
|
||||
if (delta == 0)
|
||||
count = 0;
|
||||
else
|
||||
{
|
||||
count = _IO_SYSREAD (fp, fp->_IO_buf_base,
|
||||
(must_be_exact
|
||||
? delta : fp->_IO_buf_end - fp->_IO_buf_base));
|
||||
if (count < delta)
|
||||
{
|
||||
/* We weren't allowed to read, but try to seek the remainder. */
|
||||
offset = count == EOF ? delta : delta-count;
|
||||
dir = _IO_seek_cur;
|
||||
goto dumb;
|
||||
}
|
||||
}
|
||||
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base + delta,
|
||||
fp->_IO_buf_base + count);
|
||||
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
|
||||
fp->_offset = result + count;
|
||||
_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
|
||||
return offset;
|
||||
dumb:
|
||||
|
||||
_IO_unsave_markers (fp);
|
||||
result = _IO_SYSSEEK (fp, offset, dir);
|
||||
if (result != EOF)
|
||||
{
|
||||
_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
|
||||
fp->_offset = result;
|
||||
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
|
||||
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
|
||||
}
|
||||
return result;
|
||||
|
||||
resync:
|
||||
/* We need to do it since it is possible that the file offset in
|
||||
the kernel may be changed behind our back. It may happen when
|
||||
we fopen a file and then do a fork. One process may access the
|
||||
the file and the kernel file offset will be changed. */
|
||||
if (fp->_offset >= 0)
|
||||
_IO_SYSSEEK (fp, fp->_offset, 0);
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
_IO_size_t
|
||||
_IO_wfile_xsputn (f, data, n)
|
||||
_IO_FILE *f;
|
||||
const void *data;
|
||||
_IO_size_t n;
|
||||
{
|
||||
register const wchar_t *s = (const wchar_t *) data;
|
||||
_IO_size_t to_do = n;
|
||||
int must_flush = 0;
|
||||
_IO_size_t count;
|
||||
|
||||
if (n <= 0)
|
||||
return 0;
|
||||
/* This is an optimized implementation.
|
||||
If the amount to be written straddles a block boundary
|
||||
(or the filebuf is unbuffered), use sys_write directly. */
|
||||
|
||||
/* First figure out how much space is available in the buffer. */
|
||||
count = f->_wide_data->_IO_write_end - f->_wide_data->_IO_write_ptr;
|
||||
if ((f->_flags & _IO_LINE_BUF) && (f->_flags & _IO_CURRENTLY_PUTTING))
|
||||
{
|
||||
count = f->_wide_data->_IO_buf_end - f->_wide_data->_IO_write_ptr;
|
||||
if (count >= n)
|
||||
{
|
||||
register const wchar_t *p;
|
||||
for (p = s + n; p > s; )
|
||||
{
|
||||
if (*--p == L'\n')
|
||||
{
|
||||
count = p - s + 1;
|
||||
must_flush = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Then fill the buffer. */
|
||||
if (count > 0)
|
||||
{
|
||||
if (count > to_do)
|
||||
count = to_do;
|
||||
if (count > 20)
|
||||
{
|
||||
#ifdef _LIBC
|
||||
f->_wide_data->_IO_write_ptr =
|
||||
__wmempcpy (f->_wide_data->_IO_write_ptr, s, count);
|
||||
#else
|
||||
wmemcpy (f->_wide_data->_IO_write_ptr, s, count);
|
||||
f->_wide_data->_IO_write_ptr += count;
|
||||
#endif
|
||||
s += count;
|
||||
}
|
||||
else
|
||||
{
|
||||
register wchar_t *p = f->_wide_data->_IO_write_ptr;
|
||||
register int i = (int) count;
|
||||
while (--i >= 0)
|
||||
*p++ = *s++;
|
||||
f->_wide_data->_IO_write_ptr = p;
|
||||
}
|
||||
to_do -= count;
|
||||
}
|
||||
if (to_do > 0)
|
||||
to_do -= _IO_wdefault_xsputn (f, s, to_do);
|
||||
if (must_flush
|
||||
&& f->_wide_data->_IO_write_ptr != f->_wide_data->_IO_write_base)
|
||||
_IO_wdo_write (f, f->_wide_data->_IO_write_base,
|
||||
f->_wide_data->_IO_write_ptr
|
||||
- f->_wide_data->_IO_write_base);
|
||||
|
||||
return n - to_do;
|
||||
}
|
||||
|
||||
|
||||
struct _IO_jump_t _IO_wfile_jumps =
|
||||
{
|
||||
JUMP_INIT_DUMMY,
|
||||
JUMP_INIT(finish, _IO_new_file_finish),
|
||||
JUMP_INIT(overflow, (_IO_overflow_t) _IO_wfile_overflow),
|
||||
JUMP_INIT(underflow, (_IO_underflow_t) _IO_wfile_underflow),
|
||||
JUMP_INIT(uflow, (_IO_underflow_t) _IO_wdefault_uflow),
|
||||
JUMP_INIT(pbackfail, (_IO_pbackfail_t) _IO_wdefault_pbackfail),
|
||||
JUMP_INIT(xsputn, _IO_wfile_xsputn),
|
||||
JUMP_INIT(xsgetn, _IO_file_xsgetn),
|
||||
JUMP_INIT(seekoff, _IO_wfile_seekoff),
|
||||
JUMP_INIT(seekpos, _IO_default_seekpos),
|
||||
JUMP_INIT(setbuf, _IO_new_file_setbuf),
|
||||
JUMP_INIT(sync, (_IO_sync_t) _IO_wfile_sync),
|
||||
JUMP_INIT(doallocate, _IO_wfile_doallocate),
|
||||
JUMP_INIT(read, _IO_file_read),
|
||||
JUMP_INIT(write, _IO_new_file_write),
|
||||
JUMP_INIT(seek, _IO_file_seek),
|
||||
JUMP_INIT(close, _IO_file_close),
|
||||
JUMP_INIT(stat, _IO_file_stat),
|
||||
JUMP_INIT(showmanyc, _IO_default_showmanyc),
|
||||
JUMP_INIT(imbue, _IO_default_imbue)
|
||||
};
|
750
libstdc++-v3/libio/wgenops.c
Normal file
750
libstdc++-v3/libio/wgenops.c
Normal file
@ -0,0 +1,750 @@
|
||||
/* Copyright (C) 1993, 1995, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
|
||||
This file is part of the GNU IO Library.
|
||||
Written by Ulrich Drepper <drepper@cygnus.com>.
|
||||
Based on the single byte version by Per Bothner <bothner@cygnus.com>.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2, or (at
|
||||
your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this library; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does
|
||||
not cause the resulting executable to be covered by the GNU General
|
||||
Public License. This exception does not however invalidate any
|
||||
other reasons why the executable file might be covered by the GNU
|
||||
General Public License. */
|
||||
|
||||
/* Generic or default I/O operations. */
|
||||
|
||||
#include "libioP.h"
|
||||
#ifdef __STDC__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
|
||||
#ifndef _LIBC
|
||||
# define __wmemcpy(dst, src, n) wmemcpy (dst, src, n)
|
||||
#endif
|
||||
|
||||
static int save_for_wbackup __P ((_IO_FILE *fp, wchar_t *end_p))
|
||||
#ifdef _LIBC
|
||||
internal_function
|
||||
#endif
|
||||
;
|
||||
|
||||
/* Return minimum _pos markers
|
||||
Assumes the current get area is the main get area. */
|
||||
_IO_ssize_t _IO_least_wmarker __P ((_IO_FILE *fp, wchar_t *end_p));
|
||||
|
||||
_IO_ssize_t
|
||||
_IO_least_wmarker (fp, end_p)
|
||||
_IO_FILE *fp;
|
||||
wchar_t *end_p;
|
||||
{
|
||||
_IO_ssize_t least_so_far = end_p - fp->_wide_data->_IO_read_base;
|
||||
struct _IO_marker *mark;
|
||||
for (mark = fp->_markers; mark != NULL; mark = mark->_next)
|
||||
if (mark->_pos < least_so_far)
|
||||
least_so_far = mark->_pos;
|
||||
return least_so_far;
|
||||
}
|
||||
|
||||
/* Switch current get area from backup buffer to (start of) main get area. */
|
||||
void
|
||||
_IO_switch_to_main_wget_area (fp)
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
wchar_t *tmp;
|
||||
fp->_flags &= ~_IO_IN_BACKUP;
|
||||
/* Swap _IO_read_end and _IO_save_end. */
|
||||
tmp = fp->_wide_data->_IO_read_end;
|
||||
fp->_wide_data->_IO_read_end = fp->_wide_data->_IO_save_end;
|
||||
fp->_wide_data->_IO_save_end= tmp;
|
||||
/* Swap _IO_read_base and _IO_save_base. */
|
||||
tmp = fp->_wide_data->_IO_read_base;
|
||||
fp->_wide_data->_IO_read_base = fp->_wide_data->_IO_save_base;
|
||||
fp->_wide_data->_IO_save_base = tmp;
|
||||
/* Set _IO_read_ptr. */
|
||||
fp->_wide_data->_IO_read_ptr = fp->_wide_data->_IO_read_base;
|
||||
}
|
||||
|
||||
|
||||
/* Switch current get area from main get area to (end of) backup area. */
|
||||
void
|
||||
_IO_switch_to_wbackup_area (fp)
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
wchar_t *tmp;
|
||||
fp->_flags |= _IO_IN_BACKUP;
|
||||
/* Swap _IO_read_end and _IO_save_end. */
|
||||
tmp = fp->_wide_data->_IO_read_end;
|
||||
fp->_wide_data->_IO_read_end = fp->_wide_data->_IO_save_end;
|
||||
fp->_wide_data->_IO_save_end = tmp;
|
||||
/* Swap _IO_read_base and _IO_save_base. */
|
||||
tmp = fp->_wide_data->_IO_read_base;
|
||||
fp->_wide_data->_IO_read_base = fp->_wide_data->_IO_save_base;
|
||||
fp->_wide_data->_IO_save_base = tmp;
|
||||
/* Set _IO_read_ptr. */
|
||||
fp->_wide_data->_IO_read_ptr = fp->_wide_data->_IO_read_end;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_IO_wsetb (f, b, eb, a)
|
||||
_IO_FILE *f;
|
||||
wchar_t *b;
|
||||
wchar_t *eb;
|
||||
int a;
|
||||
{
|
||||
if (f->_wide_data->_IO_buf_base && !(f->_flags & _IO_USER_BUF))
|
||||
FREE_BUF (f->_wide_data->_IO_buf_base, _IO_wblen (f));
|
||||
f->_wide_data->_IO_buf_base = b;
|
||||
f->_wide_data->_IO_buf_end = eb;
|
||||
if (a)
|
||||
f->_flags &= ~_IO_USER_BUF;
|
||||
else
|
||||
f->_flags |= _IO_USER_BUF;
|
||||
}
|
||||
|
||||
|
||||
wint_t
|
||||
_IO_wdefault_pbackfail (fp, c)
|
||||
_IO_FILE *fp;
|
||||
wint_t c;
|
||||
{
|
||||
if (fp->_wide_data->_IO_read_ptr > fp->_wide_data->_IO_read_base
|
||||
&& !_IO_in_backup (fp)
|
||||
&& (wint_t) fp->_IO_read_ptr[-1] == c)
|
||||
--fp->_IO_read_ptr;
|
||||
else
|
||||
{
|
||||
/* Need to handle a filebuf in write mode (switch to read mode). FIXME!*/
|
||||
if (!_IO_in_backup (fp))
|
||||
{
|
||||
/* We need to keep the invariant that the main get area
|
||||
logically follows the backup area. */
|
||||
if (fp->_wide_data->_IO_read_ptr > fp->_wide_data->_IO_read_base
|
||||
&& _IO_have_wbackup (fp))
|
||||
{
|
||||
if (save_for_wbackup (fp, fp->_wide_data->_IO_read_ptr))
|
||||
return WEOF;
|
||||
}
|
||||
else if (!_IO_have_wbackup (fp))
|
||||
{
|
||||
/* No backup buffer: allocate one. */
|
||||
/* Use nshort buffer, if unused? (probably not) FIXME */
|
||||
int backup_size = 128;
|
||||
wchar_t *bbuf = (wchar_t *) malloc (backup_size
|
||||
* sizeof (wchar_t));
|
||||
if (bbuf == NULL)
|
||||
return WEOF;
|
||||
fp->_wide_data->_IO_save_base = bbuf;
|
||||
fp->_wide_data->_IO_save_end = (fp->_wide_data->_IO_save_base
|
||||
+ backup_size);
|
||||
fp->_wide_data->_IO_backup_base = fp->_wide_data->_IO_save_end;
|
||||
}
|
||||
fp->_wide_data->_IO_read_base = fp->_wide_data->_IO_read_ptr;
|
||||
_IO_switch_to_wbackup_area (fp);
|
||||
}
|
||||
else if (fp->_wide_data->_IO_read_ptr <= fp->_wide_data->_IO_read_base)
|
||||
{
|
||||
/* Increase size of existing backup buffer. */
|
||||
_IO_size_t new_size;
|
||||
_IO_size_t old_size = (fp->_wide_data->_IO_read_end
|
||||
- fp->_wide_data->_IO_read_base);
|
||||
wchar_t *new_buf;
|
||||
new_size = 2 * old_size;
|
||||
new_buf = (wchar_t *) malloc (new_size * sizeof (wchar_t));
|
||||
if (new_buf == NULL)
|
||||
return WEOF;
|
||||
__wmemcpy (new_buf + (new_size - old_size),
|
||||
fp->_wide_data->_IO_read_base, old_size);
|
||||
free (fp->_wide_data->_IO_read_base);
|
||||
_IO_wsetg (fp, new_buf, new_buf + (new_size - old_size),
|
||||
new_buf + new_size);
|
||||
fp->_wide_data->_IO_backup_base = fp->_wide_data->_IO_read_ptr;
|
||||
}
|
||||
|
||||
*--fp->_wide_data->_IO_read_ptr = c;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_IO_wdefault_finish (fp, dummy)
|
||||
_IO_FILE *fp;
|
||||
int dummy;
|
||||
{
|
||||
struct _IO_marker *mark;
|
||||
if (fp->_wide_data->_IO_buf_base && !(fp->_flags & _IO_USER_BUF))
|
||||
{
|
||||
FREE_BUF (fp->_wide_data->_IO_buf_base,
|
||||
_IO_wblen (fp) * sizeof (wchar_t));
|
||||
fp->_wide_data->_IO_buf_base = fp->_wide_data->_IO_buf_end = NULL;
|
||||
}
|
||||
|
||||
for (mark = fp->_markers; mark != NULL; mark = mark->_next)
|
||||
mark->_sbuf = NULL;
|
||||
|
||||
if (fp->_IO_save_base)
|
||||
{
|
||||
free (fp->_wide_data->_IO_save_base);
|
||||
fp->_IO_save_base = NULL;
|
||||
}
|
||||
|
||||
#ifdef _IO_MTSAFE_IO
|
||||
_IO_lock_fini (*fp->_lock);
|
||||
#endif
|
||||
|
||||
_IO_un_link ((struct _IO_FILE_plus *) fp);
|
||||
}
|
||||
|
||||
|
||||
wint_t
|
||||
_IO_wdefault_uflow (fp)
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
wint_t wch;
|
||||
wch = _IO_UNDERFLOW (fp);
|
||||
if (wch == WEOF)
|
||||
return WEOF;
|
||||
return *fp->_wide_data->_IO_read_ptr++;
|
||||
}
|
||||
|
||||
|
||||
wint_t
|
||||
__woverflow (f, wch)
|
||||
_IO_FILE *f;
|
||||
wint_t wch;
|
||||
{
|
||||
if (f->_mode == 0)
|
||||
_IO_fwide (f, 1);
|
||||
return _IO_OVERFLOW (f, wch);
|
||||
}
|
||||
|
||||
|
||||
wint_t
|
||||
__wuflow (fp)
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
if (fp->_mode < 0 || (fp->_mode == 0 && _IO_fwide (fp, 1) != 1))
|
||||
return WEOF;
|
||||
|
||||
if (fp->_mode == 0)
|
||||
_IO_fwide (fp, 1);
|
||||
if (_IO_in_put_mode (fp))
|
||||
if (_IO_switch_to_wget_mode (fp) == EOF)
|
||||
return WEOF;
|
||||
if (fp->_wide_data->_IO_read_ptr < fp->_wide_data->_IO_read_end)
|
||||
return *fp->_wide_data->_IO_read_ptr++;
|
||||
if (_IO_in_backup (fp))
|
||||
{
|
||||
_IO_switch_to_main_wget_area (fp);
|
||||
if (fp->_wide_data->_IO_read_ptr < fp->_wide_data->_IO_read_end)
|
||||
return *fp->_wide_data->_IO_read_ptr++;
|
||||
}
|
||||
if (_IO_have_markers (fp))
|
||||
{
|
||||
if (save_for_wbackup (fp, fp->_wide_data->_IO_read_end))
|
||||
return WEOF;
|
||||
}
|
||||
else if (_IO_have_wbackup (fp))
|
||||
_IO_free_wbackup_area (fp);
|
||||
return _IO_UFLOW (fp);
|
||||
}
|
||||
|
||||
|
||||
wint_t
|
||||
__wunderflow (fp)
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
if (fp->_mode < 0 || (fp->_mode == 0 && _IO_fwide (fp, 1) != 1))
|
||||
return WEOF;
|
||||
|
||||
if (_IO_in_put_mode (fp))
|
||||
if (_IO_switch_to_wget_mode (fp) == EOF)
|
||||
return WEOF;
|
||||
if (fp->_wide_data->_IO_read_ptr < fp->_wide_data->_IO_read_end)
|
||||
return *fp->_wide_data->_IO_read_ptr;
|
||||
if (_IO_in_backup (fp))
|
||||
{
|
||||
_IO_switch_to_main_wget_area (fp);
|
||||
if (fp->_wide_data->_IO_read_ptr < fp->_wide_data->_IO_read_end)
|
||||
return *fp->_wide_data->_IO_read_ptr;
|
||||
}
|
||||
if (_IO_have_markers (fp))
|
||||
{
|
||||
if (save_for_wbackup (fp, fp->_wide_data->_IO_read_end))
|
||||
return WEOF;
|
||||
}
|
||||
else if (_IO_have_backup (fp))
|
||||
_IO_free_wbackup_area (fp);
|
||||
return _IO_UNDERFLOW (fp);
|
||||
}
|
||||
|
||||
|
||||
_IO_size_t
|
||||
_IO_wdefault_xsputn (f, data, n)
|
||||
_IO_FILE *f;
|
||||
const void *data;
|
||||
_IO_size_t n;
|
||||
{
|
||||
const wchar_t *s = (const wchar_t *) data;
|
||||
_IO_size_t more = n;
|
||||
if (more <= 0)
|
||||
return 0;
|
||||
for (;;)
|
||||
{
|
||||
/* Space available. */
|
||||
_IO_ssize_t count = (f->_wide_data->_IO_write_end
|
||||
- f->_wide_data->_IO_write_ptr);
|
||||
if (count > 0)
|
||||
{
|
||||
if ((_IO_size_t) count > more)
|
||||
count = more;
|
||||
if (count > 20)
|
||||
{
|
||||
#ifdef _LIBC
|
||||
f->_wide_data->_IO_write_ptr =
|
||||
__wmempcpy (f->_wide_data->_IO_write_ptr, s, count);
|
||||
#else
|
||||
memcpy (f->_wide_data->_IO_write_ptr, s, count);
|
||||
f->_wide_data->_IO_write_ptr += count;
|
||||
#endif
|
||||
s += count;
|
||||
}
|
||||
else if (count <= 0)
|
||||
count = 0;
|
||||
else
|
||||
{
|
||||
wchar_t *p = f->_wide_data->_IO_write_ptr;
|
||||
_IO_ssize_t i;
|
||||
for (i = count; --i >= 0; )
|
||||
*p++ = *s++;
|
||||
f->_wide_data->_IO_write_ptr = p;
|
||||
}
|
||||
more -= count;
|
||||
}
|
||||
if (more == 0 || __woverflow (f, *s++) == WEOF)
|
||||
break;
|
||||
more--;
|
||||
}
|
||||
return n - more;
|
||||
}
|
||||
|
||||
|
||||
_IO_size_t
|
||||
_IO_wdefault_xsgetn (fp, data, n)
|
||||
_IO_FILE *fp;
|
||||
void *data;
|
||||
_IO_size_t n;
|
||||
{
|
||||
_IO_size_t more = n;
|
||||
wchar_t *s = (wchar_t*) data;
|
||||
for (;;)
|
||||
{
|
||||
/* Data available. */
|
||||
_IO_ssize_t count = (fp->_wide_data->_IO_read_end
|
||||
- fp->_wide_data->_IO_read_ptr);
|
||||
if (count > 0)
|
||||
{
|
||||
if ((_IO_size_t) count > more)
|
||||
count = more;
|
||||
if (count > 20)
|
||||
{
|
||||
#ifdef _LIBC
|
||||
s = __wmempcpy (s, fp->_wide_data->_IO_read_ptr, count);
|
||||
#else
|
||||
memcpy (s, fp->_wide_data->_IO_read_ptr, count);
|
||||
s += count;
|
||||
#endif
|
||||
fp->_wide_data->_IO_read_ptr += count;
|
||||
}
|
||||
else if (count <= 0)
|
||||
count = 0;
|
||||
else
|
||||
{
|
||||
wchar_t *p = fp->_wide_data->_IO_read_ptr;
|
||||
int i = (int) count;
|
||||
while (--i >= 0)
|
||||
*s++ = *p++;
|
||||
fp->_wide_data->_IO_read_ptr = p;
|
||||
}
|
||||
more -= count;
|
||||
}
|
||||
if (more == 0 || __wunderflow (fp) == WEOF)
|
||||
break;
|
||||
}
|
||||
return n - more;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_IO_wdoallocbuf (fp)
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
if (fp->_wide_data->_IO_buf_base)
|
||||
return;
|
||||
if (!(fp->_flags & _IO_UNBUFFERED))
|
||||
if (_IO_DOALLOCATE (fp) != WEOF)
|
||||
return;
|
||||
_IO_wsetb (fp, fp->_wide_data->_shortbuf, fp->_wide_data->_shortbuf + 1, 0);
|
||||
}
|
||||
|
||||
|
||||
_IO_FILE *
|
||||
_IO_wdefault_setbuf (fp, p, len)
|
||||
_IO_FILE *fp;
|
||||
wchar_t *p;
|
||||
_IO_ssize_t len;
|
||||
{
|
||||
if (_IO_SYNC (fp) == EOF)
|
||||
return NULL;
|
||||
if (p == NULL || len == 0)
|
||||
{
|
||||
fp->_flags |= _IO_UNBUFFERED;
|
||||
_IO_wsetb (fp, fp->_wide_data->_shortbuf, fp->_wide_data->_shortbuf + 1,
|
||||
0);
|
||||
}
|
||||
else
|
||||
{
|
||||
fp->_flags &= ~_IO_UNBUFFERED;
|
||||
_IO_wsetb (fp, p, p + len, 0);
|
||||
}
|
||||
fp->_wide_data->_IO_write_base = fp->_wide_data->_IO_write_ptr
|
||||
= fp->_wide_data->_IO_write_end = 0;
|
||||
fp->_wide_data->_IO_read_base = fp->_wide_data->_IO_read_ptr
|
||||
= fp->_wide_data->_IO_read_end = 0;
|
||||
return fp;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
_IO_wdefault_doallocate (fp)
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
wchar_t *buf;
|
||||
|
||||
ALLOC_WBUF (buf, _IO_BUFSIZ, EOF);
|
||||
_IO_wsetb (fp, buf, buf + _IO_BUFSIZ, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
_IO_switch_to_wget_mode (fp)
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
if (fp->_wide_data->_IO_write_ptr > fp->_wide_data->_IO_write_base)
|
||||
if (_IO_OVERFLOW (fp, WEOF) == WEOF)
|
||||
return EOF;
|
||||
if (_IO_in_backup (fp))
|
||||
fp->_wide_data->_IO_read_base = fp->_wide_data->_IO_backup_base;
|
||||
else
|
||||
{
|
||||
fp->_wide_data->_IO_read_base = fp->_wide_data->_IO_buf_base;
|
||||
if (fp->_wide_data->_IO_write_ptr > fp->_wide_data->_IO_read_end)
|
||||
fp->_wide_data->_IO_read_end = fp->_wide_data->_IO_write_ptr;
|
||||
}
|
||||
fp->_wide_data->_IO_read_ptr = fp->_wide_data->_IO_write_ptr;
|
||||
|
||||
fp->_wide_data->_IO_write_base = fp->_wide_data->_IO_write_ptr
|
||||
= fp->_wide_data->_IO_write_end = fp->_wide_data->_IO_read_ptr;
|
||||
|
||||
fp->_flags &= ~_IO_CURRENTLY_PUTTING;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
_IO_free_wbackup_area (fp)
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
if (_IO_in_backup (fp))
|
||||
_IO_switch_to_main_wget_area (fp); /* Just in case. */
|
||||
free (fp->_wide_data->_IO_save_base);
|
||||
fp->_wide_data->_IO_save_base = NULL;
|
||||
fp->_wide_data->_IO_save_end = NULL;
|
||||
fp->_wide_data->_IO_backup_base = NULL;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int
|
||||
_IO_switch_to_wput_mode (fp)
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
fp->_wide_data->_IO_write_base = fp->_wide_data->_IO_read_ptr;
|
||||
fp->_wide_data->_IO_write_ptr = fp->_wide_data->_IO_read_ptr;
|
||||
/* Following is wrong if line- or un-buffered? */
|
||||
fp->_wide_data->_IO_write_end = (fp->_flags & _IO_IN_BACKUP
|
||||
? fp->_wide_data->_IO_read_end
|
||||
: fp->_wide_data->_IO_buf_end);
|
||||
|
||||
fp->_wide_data->_IO_read_ptr = fp->_wide_data->_IO_read_end;
|
||||
fp->_wide_data->_IO_read_base = fp->_wide_data->_IO_read_end;
|
||||
|
||||
fp->_flags |= _IO_CURRENTLY_PUTTING;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static int
|
||||
#ifdef _LIBC
|
||||
internal_function
|
||||
#endif
|
||||
save_for_wbackup (fp, end_p)
|
||||
_IO_FILE *fp;
|
||||
wchar_t *end_p;
|
||||
{
|
||||
/* Append [_IO_read_base..end_p] to backup area. */
|
||||
_IO_ssize_t least_mark = _IO_least_wmarker (fp, end_p);
|
||||
/* needed_size is how much space we need in the backup area. */
|
||||
_IO_size_t needed_size = ((end_p - fp->_wide_data->_IO_read_base)
|
||||
- least_mark);
|
||||
/* FIXME: Dubious arithmetic if pointers are NULL */
|
||||
_IO_size_t current_Bsize = (fp->_wide_data->_IO_save_end
|
||||
- fp->_wide_data->_IO_save_base);
|
||||
_IO_size_t avail; /* Extra space available for future expansion. */
|
||||
_IO_ssize_t delta;
|
||||
struct _IO_marker *mark;
|
||||
if (needed_size > current_Bsize)
|
||||
{
|
||||
wchar_t *new_buffer;
|
||||
avail = 100;
|
||||
new_buffer = (wchar_t *) malloc ((avail + needed_size)
|
||||
* sizeof (wchar_t));
|
||||
if (new_buffer == NULL)
|
||||
return EOF; /* FIXME */
|
||||
if (least_mark < 0)
|
||||
{
|
||||
#ifdef _LIBC
|
||||
__wmempcpy (__wmempcpy (new_buffer + avail,
|
||||
fp->_wide_data->_IO_save_end + least_mark,
|
||||
-least_mark),
|
||||
fp->_wide_data->_IO_read_base,
|
||||
end_p - fp->_wide_data->_IO_read_base);
|
||||
#else
|
||||
memcpy (new_buffer + avail,
|
||||
fp->_wide_data->_IO_save_end + least_mark,
|
||||
-least_mark * sizeof (wchar_t));
|
||||
memcpy (new_buffer + avail - least_mark,
|
||||
fp->_wide_data->_IO_read_base,
|
||||
(end_p - fp->_wide_data->_IO_read_base) * sizeof (wchar_t));
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef _LIBC
|
||||
__wmemcpy (new_buffer + avail,
|
||||
fp->_wide_data->_IO_read_base + least_mark,
|
||||
needed_size);
|
||||
#else
|
||||
memcpy (new_buffer + avail,
|
||||
fp->_wide_data->_IO_read_base + least_mark,
|
||||
needed_size * sizeof (wchar_t));
|
||||
#endif
|
||||
}
|
||||
if (fp->_wide_data->_IO_save_base)
|
||||
free (fp->_wide_data->_IO_save_base);
|
||||
fp->_wide_data->_IO_save_base = new_buffer;
|
||||
fp->_wide_data->_IO_save_end = new_buffer + avail + needed_size;
|
||||
}
|
||||
else
|
||||
{
|
||||
avail = current_Bsize - needed_size;
|
||||
if (least_mark < 0)
|
||||
{
|
||||
#ifdef _LIBC
|
||||
__wmemmove (fp->_wide_data->_IO_save_base + avail,
|
||||
fp->_wide_data->_IO_save_end + least_mark,
|
||||
-least_mark);
|
||||
__wmemcpy (fp->_wide_data->_IO_save_base + avail - least_mark,
|
||||
fp->_wide_data->_IO_read_base,
|
||||
end_p - fp->_wide_data->_IO_read_base);
|
||||
#else
|
||||
memmove (fp->_wide_data->_IO_save_base + avail,
|
||||
fp->_wide_data->_IO_save_end + least_mark,
|
||||
-least_mark * sizeof (wchar_t));
|
||||
memcpy (fp->_wide_data->_IO_save_base + avail - least_mark,
|
||||
fp->_wide_data->_IO_read_base,
|
||||
(end_p - fp->_wide_data->_IO_read_base) * sizeof (wchar_t));
|
||||
#endif
|
||||
}
|
||||
else if (needed_size > 0)
|
||||
#ifdef _LIBC
|
||||
__wmemcpy (fp->_wide_data->_IO_save_base + avail,
|
||||
fp->_wide_data->_IO_read_base + least_mark,
|
||||
needed_size);
|
||||
#else
|
||||
memcpy (fp->_wide_data->_IO_save_base + avail,
|
||||
fp->_wide_data->_IO_read_base + least_mark,
|
||||
needed_size * sizeof (wchar_t));
|
||||
#endif
|
||||
}
|
||||
fp->_wide_data->_IO_backup_base = fp->_wide_data->_IO_save_base + avail;
|
||||
/* Adjust all the streammarkers. */
|
||||
delta = end_p - fp->_wide_data->_IO_read_base;
|
||||
for (mark = fp->_markers; mark != NULL; mark = mark->_next)
|
||||
mark->_pos -= delta;
|
||||
return 0;
|
||||
}
|
||||
|
||||
wint_t
|
||||
_IO_sputbackwc (fp, c)
|
||||
_IO_FILE *fp;
|
||||
wint_t c;
|
||||
{
|
||||
wint_t result;
|
||||
|
||||
if (fp->_wide_data->_IO_read_ptr > fp->_wide_data->_IO_read_base
|
||||
&& (wchar_t)fp->_wide_data->_IO_read_ptr[-1] == (wchar_t) c)
|
||||
{
|
||||
fp->_wide_data->_IO_read_ptr--;
|
||||
result = c;
|
||||
}
|
||||
else
|
||||
result = _IO_PBACKFAIL (fp, c);
|
||||
|
||||
if (result != EOF)
|
||||
fp->_flags &= ~_IO_EOF_SEEN;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
wint_t
|
||||
_IO_sungetwc (fp)
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
int result;
|
||||
|
||||
if (fp->_wide_data->_IO_read_ptr > fp->_wide_data->_IO_read_base)
|
||||
{
|
||||
fp->_wide_data->_IO_read_ptr--;
|
||||
result = *fp->_wide_data->_IO_read_ptr;
|
||||
}
|
||||
else
|
||||
result = _IO_PBACKFAIL (fp, EOF);
|
||||
|
||||
if (result != WEOF)
|
||||
fp->_flags &= ~_IO_EOF_SEEN;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
unsigned
|
||||
_IO_adjust_wcolumn (start, line, count)
|
||||
unsigned start;
|
||||
const wchar_t *line;
|
||||
int count;
|
||||
{
|
||||
const wchar_t *ptr = line + count;
|
||||
while (ptr > line)
|
||||
if (*--ptr == L'\n')
|
||||
return line + count - ptr - 1;
|
||||
return start + count;
|
||||
}
|
||||
|
||||
void
|
||||
_IO_init_wmarker (marker, fp)
|
||||
struct _IO_marker *marker;
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
marker->_sbuf = fp;
|
||||
if (_IO_in_put_mode (fp))
|
||||
_IO_switch_to_wget_mode (fp);
|
||||
if (_IO_in_backup (fp))
|
||||
marker->_pos = fp->_wide_data->_IO_read_ptr - fp->_wide_data->_IO_read_end;
|
||||
else
|
||||
marker->_pos = (fp->_wide_data->_IO_read_ptr
|
||||
- fp->_wide_data->_IO_read_base);
|
||||
|
||||
/* Should perhaps sort the chain? */
|
||||
marker->_next = fp->_markers;
|
||||
fp->_markers = marker;
|
||||
}
|
||||
|
||||
#define BAD_DELTA EOF
|
||||
|
||||
/* Return difference between MARK and current position of MARK's stream. */
|
||||
int
|
||||
_IO_wmarker_delta (mark)
|
||||
struct _IO_marker *mark;
|
||||
{
|
||||
int cur_pos;
|
||||
if (mark->_sbuf == NULL)
|
||||
return BAD_DELTA;
|
||||
if (_IO_in_backup (mark->_sbuf))
|
||||
cur_pos = (mark->_sbuf->_wide_data->_IO_read_ptr
|
||||
- mark->_sbuf->_wide_data->_IO_read_end);
|
||||
else
|
||||
cur_pos = (mark->_sbuf->_wide_data->_IO_read_ptr
|
||||
- mark->_sbuf->_wide_data->_IO_read_base);
|
||||
return mark->_pos - cur_pos;
|
||||
}
|
||||
|
||||
int
|
||||
_IO_seekwmark (fp, mark, delta)
|
||||
_IO_FILE *fp;
|
||||
struct _IO_marker *mark;
|
||||
int delta;
|
||||
{
|
||||
if (mark->_sbuf != fp)
|
||||
return EOF;
|
||||
if (mark->_pos >= 0)
|
||||
{
|
||||
if (_IO_in_backup (fp))
|
||||
_IO_switch_to_main_wget_area (fp);
|
||||
fp->_wide_data->_IO_read_ptr = (fp->_wide_data->_IO_read_base
|
||||
+ mark->_pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!_IO_in_backup (fp))
|
||||
_IO_switch_to_wbackup_area (fp);
|
||||
fp->_wide_data->_IO_read_ptr = fp->_wide_data->_IO_read_end + mark->_pos;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
_IO_unsave_wmarkers (fp)
|
||||
_IO_FILE *fp;
|
||||
{
|
||||
struct _IO_marker *mark = fp->_markers;
|
||||
if (mark)
|
||||
{
|
||||
#ifdef TODO
|
||||
streampos offset = seekoff (0, ios::cur, ios::in);
|
||||
if (offset != EOF)
|
||||
{
|
||||
offset += eGptr () - Gbase ();
|
||||
for ( ; mark != NULL; mark = mark->_next)
|
||||
mark->set_streampos (mark->_pos + offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( ; mark != NULL; mark = mark->_next)
|
||||
mark->set_streampos (EOF);
|
||||
}
|
||||
#endif
|
||||
fp->_markers = 0;
|
||||
}
|
||||
|
||||
if (_IO_have_backup (fp))
|
||||
_IO_free_wbackup_area (fp);
|
||||
}
|
@ -34,5 +34,5 @@
|
||||
long double
|
||||
cargl (__complex__ long double x)
|
||||
{
|
||||
return __atan2l (__imag__ x, __real__ x);
|
||||
return atan2l (__imag__ x, __real__ x);
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ AC_CXXFLAGS = \
|
||||
# the end of the compile line so that -O2 can be overridden as the
|
||||
# occasion call for it. (ie, --enable-debug)
|
||||
AM_CXXFLAGS = \
|
||||
-fno-implicit-templates $(OPTIMIZE_CXXFLAGS) \
|
||||
-D_GNU_SOURCE -fno-implicit-templates $(OPTIMIZE_CXXFLAGS) \
|
||||
-Wall -Wno-format -W -Wwrite-strings -Winline \
|
||||
$(AC_CXXFLAGS)
|
||||
|
||||
|
@ -130,7 +130,7 @@ AC_CXXFLAGS = \
|
||||
# the end of the compile line so that -O2 can be overridden as the
|
||||
# occasion call for it. (ie, --enable-debug)
|
||||
AM_CXXFLAGS = \
|
||||
-fno-implicit-templates $(OPTIMIZE_CXXFLAGS) \
|
||||
-D_GNU_SOURCE -fno-implicit-templates $(OPTIMIZE_CXXFLAGS) \
|
||||
-Wall -Wno-format -W -Wwrite-strings -Winline \
|
||||
$(AC_CXXFLAGS)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user