From f275da24545d51247049a288787ffa1ed6343dfd Mon Sep 17 00:00:00 2001 From: jjgarcia Date: Mon, 3 Nov 2003 12:53:32 +0000 Subject: [PATCH] Check whether the FILE structure has a field from which we can guess the number of characters in the buffer. --- src/aclocal.m4 | 38 +++++++++++++ src/c/file.d | 2 + src/configure | 137 +++++++++++++++++++++++++++++++++++++++++++++- src/configure.in | 3 +- src/h/config.h.in | 11 ++-- 5 files changed, 185 insertions(+), 6 deletions(-) diff --git a/src/aclocal.m4 b/src/aclocal.m4 index 2b0c009b0..d522f4795 100644 --- a/src/aclocal.m4 +++ b/src/aclocal.m4 @@ -39,6 +39,14 @@ ECL_BIGENDIAN=no ### CR (Carriage return or \\r), and CRLF (CR followed by LF). ECL_NEWLINE=LF +### 1.5) Can we guess how many characters are available for reading from +### the FILE structure? +### 0 = no +### 1 = (f)->_IO_read_end - (f)->_IO_read_ptr +### 2 = (f)->_r +### 3 = (f)->_cnt +ECL_FILE_CNT=0 + ### 2) To cross-compile ECL so that it runs on the system ### ${host} ### you need to first compile ECL on the system in which you are building @@ -181,6 +189,36 @@ AC_MSG_CHECKING(for software type) AC_MSG_RESULT([${SOFTWARE_TYPE}]) ]) +dnl +dnl -------------------------------------------------------------- +dnl Check whether the FILE structure has a field with the number of +dnl characters left in the buffer. +dnl +AC_DEFUN(ECL_FILE_STRUCTURE,[ +AC_SUBST(ECL_FILE_CNT) +if test -z "${ECL_FILE_CNT}"; then +ECL_FILE_CNT=0 +AC_TRY_COMPILE([#include ],[ +int main() { + FILE *f = fopen("conftestval","w"); + if ((f)->_IO_read_end - (f)->_IO_read_ptr) + return 1; +}],ECL_FILE_CNT=1) +AC_TRY_COMPILE([#include ],[ +int main() { + FILE *f = fopen("conftestval","w"); + if ((f)->_r) + return 1; +}],ECL_FILE_CNT=2) +AC_TRY_COMPILE([#include ],[ +int main() { + FILE *f = fopen("conftestval","w"); + if ((f)->_cnt) + return 1; +}],ECL_FILE_CNT=3) +fi +]) + dnl dnl -------------------------------------------------------------- dnl Check the direction to which the stack grows (for garbage diff --git a/src/c/file.d b/src/c/file.d index 5e8c9d990..854acbe58 100644 --- a/src/c/file.d +++ b/src/c/file.d @@ -1127,8 +1127,10 @@ flisten(FILE *fp) #endif if (feof(fp)) return(FALSE); +#ifdef FILE_CNT if (FILE_CNT(fp) > 0) return(TRUE); +#endif #if defined(HAVE_SELECT) fd = fileno(fp); FD_ZERO(&fds); diff --git a/src/configure b/src/configure index 6e1b9f942..2da2827d1 100755 --- a/src/configure +++ b/src/configure @@ -308,7 +308,7 @@ ac_includes_default="\ # include #endif" -ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS ECL_VERSION build build_cpu build_vendor build_os host host_cpu host_vendor host_os builddir top_srcdir CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CXX CXXFLAGS ac_ct_CXX CPP RANLIB ac_ct_RANLIB INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA LN_S ECL_CC LSPCFLAGS CLIBS SHARED_LDFLAGS SHORT_SITE_NAME LONG_SITE_NAME EXTRA_OBJS TARGETS TKLIBS SUBDIR LIBRARIES LSP_LIBRARIES BOEHM_HEADERS EGREP CP RM MV EXE_SUFFIX ARCHITECTURE SOFTWARE_TYPE SOFTWARE_VERSION MACHINE_INSTANCE MACHINE_VERSION LDRPATH LIBPREFIX LIBEXT SHAREDEXT SHAREDPREFIX ECL_SETJMP ECL_LONGJMP CL_FIXNUM_TYPE CL_FIXNUM_BITS CL_FIXNUM_MAX CL_FIXNUM_MIN X_CFLAGS X_PRE_LIBS X_LIBS X_EXTRA_LIBS XINCLUDES XLIBS LIBOBJS LTLIBOBJS' +ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS ECL_VERSION build build_cpu build_vendor build_os host host_cpu host_vendor host_os builddir top_srcdir CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CXX CXXFLAGS ac_ct_CXX CPP RANLIB ac_ct_RANLIB INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA LN_S ECL_CC LSPCFLAGS CLIBS SHARED_LDFLAGS SHORT_SITE_NAME LONG_SITE_NAME EXTRA_OBJS TARGETS TKLIBS SUBDIR LIBRARIES LSP_LIBRARIES BOEHM_HEADERS EGREP CP RM MV EXE_SUFFIX ARCHITECTURE SOFTWARE_TYPE SOFTWARE_VERSION MACHINE_INSTANCE MACHINE_VERSION LDRPATH LIBPREFIX LIBEXT SHAREDEXT SHAREDPREFIX ECL_SETJMP ECL_LONGJMP ECL_FILE_CNT CL_FIXNUM_TYPE CL_FIXNUM_BITS CL_FIXNUM_MAX CL_FIXNUM_MIN X_CFLAGS X_PRE_LIBS X_LIBS X_EXTRA_LIBS XINCLUDES XLIBS LIBOBJS LTLIBOBJS' ac_subst_files='' # Initialize some variables set by options. @@ -3775,6 +3775,14 @@ ECL_BIGENDIAN=no ### CR (Carriage return or \\r), and CRLF (CR followed by LF). ECL_NEWLINE=LF +### 1.5) Can we guess how many characters are available for reading from +### the FILE structure? +### 0 = no +### 1 = (f)->_IO_read_end - (f)->_IO_read_ptr +### 2 = (f)->_r +### 3 = (f)->_cnt +ECL_FILE_CNT=0 + ### 2) To cross-compile ECL so that it runs on the system ### ${host} ### you need to first compile ECL on the system in which you are building @@ -4081,6 +4089,132 @@ else fi + +if test -z "${ECL_FILE_CNT}"; then +ECL_FILE_CNT=0 +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +int +main () +{ + +int main() { + FILE *f = fopen("conftestval","w"); + if ((f)->_IO_read_end - (f)->_IO_read_ptr) + return 1; +} + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ECL_FILE_CNT=1 +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.$ac_objext conftest.$ac_ext +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +int +main () +{ + +int main() { + FILE *f = fopen("conftestval","w"); + if ((f)->_r) + return 1; +} + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ECL_FILE_CNT=2 +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.$ac_objext conftest.$ac_ext +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +int +main () +{ + +int main() { + FILE *f = fopen("conftestval","w"); + if ((f)->_cnt) + return 1; +} + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ECL_FILE_CNT=3 +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi + + if test "x$prefix" = "xNONE"; then prefix=${ac_default_prefix}; fi if test "x$exec_prefix" = "xNONE"; then exec_prefix=${prefix}; fi bindir="${exec_prefix}/bin" @@ -6530,6 +6664,7 @@ s,@SHAREDEXT@,$SHAREDEXT,;t t s,@SHAREDPREFIX@,$SHAREDPREFIX,;t t s,@ECL_SETJMP@,$ECL_SETJMP,;t t s,@ECL_LONGJMP@,$ECL_LONGJMP,;t t +s,@ECL_FILE_CNT@,$ECL_FILE_CNT,;t t s,@CL_FIXNUM_TYPE@,$CL_FIXNUM_TYPE,;t t s,@CL_FIXNUM_BITS@,$CL_FIXNUM_BITS,;t t s,@CL_FIXNUM_MAX@,$CL_FIXNUM_MAX,;t t diff --git a/src/configure.in b/src/configure.in index e553e7346..75af637b7 100644 --- a/src/configure.in +++ b/src/configure.in @@ -143,13 +143,14 @@ AC_CHECK_FUNCS(nanosleep alarm times isnanf select setenv putenv\ AC_ISC_POSIX dnl ---------------------------------------------------------------------- -dnl Establish some default values +dnl Checks which do not come with autoconf dnl ECL_CROSS_CONFIG() ECL_MAKE_ABSOLUTE_SRCDIR() ECL_GUESS_HOST_OS() ECL_LINEFEED_MODE() ECL_FIND_SETJMP() +ECL_FILE_STRUCTURE() dnl ---------------------------------------------------------------------- dnl Set options diff --git a/src/h/config.h.in b/src/h/config.h.in index 3a38a2e51..f9a1d93e4 100644 --- a/src/h/config.h.in +++ b/src/h/config.h.in @@ -215,12 +215,15 @@ typedef unsigned @CL_FIXNUM_TYPE@ cl_hashkey; # define stack_align(n) (((n) + 03) & ~03) #endif -#ifdef __linux__ +#undef FILE_CNT +#if @ECL_FILE_CNT@ == 1 # define FILE_CNT(fp) ((fp)->_IO_read_end - (fp)->_IO_read_ptr) -#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(cygwin) || defined(darwin) +#endif +#if @ECL_FILE_CNT@ == 2 # define FILE_CNT(fp) ((fp)->_r) -#else -# define FILE_CNT(fp) (fp)->_cnt +#endif +#if @ECL_FILE_CNT@ == 3 +# define FILE_CNT(fp) ((fp)->_cnt) #endif #if defined(MSDOS) || defined(cygwin) || defined(mingw32)