# $Id: Head.U,v 3.0.1.9 1997/02/28 15:02:09 ram Exp $
#
-# Generated on Wed May 12 14:07:09 EET DST 1999 [metaconfig 3.0 PL70]
+# Generated on Thu May 13 15:54:16 EET DST 1999 [metaconfig 3.0 PL70]
# (with additional metaconfig patches by perlbug@perl.com)
cat >/tmp/c1$$ <<EOF
doublesize=''
ebcdic=''
fflushNULL=''
+fflushall=''
fpostype=''
gidtype=''
groupstype=''
d_ftell64=''
d_ftello64=''
d_tmpfile64=''
+stdio_stream_array=''
sysman=''
trnl=''
uidtype=''
set ebcdic
eval $setvar
-: check for fflush NULL behaviour
-case "$fflushNULL" in
-'') $cat <<EOM
+$cat >&4 <<EOM
+Checking how to access stdio streams by file descriptor number...
+EOM
+case "$stdio_stream_array" in
+'') $cat >try.c <<EOCP
+#include <stdio.h>
+int main() {
+ if (&STDIO_STREAM_ARRAY[fileno(stdin)] == stdin)
+ printf("yes\n");
+}
+EOCP
+ for s in _iob __iob __sF
+ do
+ set try -DSTDIO_STREAM_ARRAY=$s
+ if eval $compile_ok; then
+ case "`./try$exe_ext`" in
+ yes) stdio_stream_array=$s; break ;;
+ esac
+ fi
+ done
+ $rm -f try.* try$exe_ext
+esac
+case "$stdio_stream_array" in
+'') $cat >&4 <<EOM
+I can't figure out how to access stdio streams by file descriptor number.
+EOM
+ ;;
+*) $cat >&4 <<EOM
+You can access stdio streams by file descriptor number by using $stdio_stream_array.
+EOM
+ ;;
+esac
-Checking to see whether fflush(NULL) flushes all pending stdio output...
+$cat >&4 <<EOM
+Checking how to flush all pending stdio output...
EOM
- $cat >try.c <<EOCP
+$cat >try.c <<EOCP
#include <stdio.h>
+#$i_unistd I_UNISTD
+#ifdef I_UNISTD
+#include <unistd.h>
+#endif
+#$d_sysconf HAS_SYSCONF
int main() {
FILE* p = fopen("try.out", "w");
fputc('x', p);
+#ifdef TRY_FFLUSH_NULL
fflush(NULL);
- _exit(0);
+#endif
+#ifdef TRY_FFLUSH_ALL
+ {
+ long open_max = -1;
+# if defined(HAS_SYSCONF) && defined(_SC_OPEN_MAX)
+ open_max = sysconf(_SC_OPEN_MAX);
+# else
+# ifdef FOPEN_MAX
+# open_max = FOPEN_MAX;
+# else
+# ifdef OPEN_MAX
+# open_max = OPEN_MAX;
+# else
+# ifdef _NFILE
+# open_max = _NFILE;
+# endif
+# endif
+# endif
+# endif
+ if (open_max > 0) {
+ long i;
+ for (i = 0; i < open_max; i++)
+ fflush(&$stdio_stream_array[i]);
+ }
+ }
+#endif
+ _exit(42);
}
EOCP
- set try
+: check for fflush NULL behaviour
+case "$fflushNULL" in
+'') set try -DTRY_FFLUSH_NULL
$rm -f try.out
if eval $compile_ok; then
./try$exe_ext 2>/dev/null
- $rm -f core try.core core.try.*
- if $test -s try.out; then
+ if $test -s try.out -a "X$?" = X42; then
fflushNULL="`$cat try.out`"
fi
+ $rm -f core try.core core.try.*
fi
case "$fflushNULL" in
x) cat >&4 <<EOM
fflushNULL=undef
;;
esac
- $rm -f try.* try
;;
$define|true|[yY]*)
fflushNULL=define
fflushNULL=undef
;;
esac
+: check for fflush all behaviour
+case "$fflushall" in
+'') set try -DTRY_FFLUSH_ALL
+ $rm -f try.out
+ if eval $compile_ok; then
+ ./try$exe_ext 2>/dev/null
+ if $test -s try.out -a "X$?" = X42; then
+ fflushall="`$cat try.out`"
+ fi
+ $rm -f core try.core core.try.*
+ fi
+ case "$fflushall" in
+ x) cat >&4 <<EOM
+Flushing explicitly all the stdio streams works.
+EOM
+ fflushall=define
+ ;;
+ '') cat >&4 <<EOM
+Flushing explicitly all the stdio streams doesn't work.
+EOM
+ fflushall=undef
+ ;;
+ *) cat >&4 <<EOM
+Cannot figure out whether flushing stdio stream explicitly works or not.
+I'm assuming it doesn't.
+EOM
+ fflushall=undef
+ ;;
+ esac
+ ;;
+$define|true|[yY]*)
+ fflushall=define
+ ;;
+*)
+ fflushall=undef
+ ;;
+esac
+case "$fflushNULL$fflushall" in
+undefundef)
+ cat <<EOM
+I cannot figure out how to flush pending stdio output.
+EOM
+ ;;
+esac
+$rm -f try.* try$exe_ext
: see what type file positions are declared as in the library
rp="What is the type for file position used by fsetpos()?"
expr='$expr'
extensions='$extensions'
fflushNULL='$fflushNULL'
+fflushall='$fflushall'
find='$find'
firstmakefile='$firstmakefile'
flex='$flex'
stdio_cnt='$stdio_cnt'
stdio_filbuf='$stdio_filbuf'
stdio_ptr='$stdio_ptr'
+stdio_stream_array='$stdio_stream_array'
strings='$strings'
submit='$submit'
subversion='$subversion'
* This symbol, if defined, tells that fflush(NULL) does flush
* all pending stdio output.
*/
-#$fflushNULL FFLUSH_NULL /**/
+/* FFLUSH_ALL:
+ * This symbol, if defined, tells that to flush
+ * all pending stdio output one must loop through all
+ * the stdio file handles and fflush them.
+ */
+#$fflushNULL FFLUSH_NULL /**/
+#$fflushall FFLUSH_ALL /**/
/* DB_Prefix_t:
* This symbol contains the type of the prefix structure element
#$d_ftello64 HAS_FTELLO64 /**/
#$d_tmpfile64 HAS_TMPFILE64 /**/
+/* STDIO_STREAM_ARRAY:
+ * This symbol tells the name of the array holding the stdio stream_array,
+ * if any. Usual values include _iob, __iob, and __sF.
+ */
+#define STDIO_STREAM_ARRAY $stdio_stream_array
+
/* USE_64_BITS:
* This symbol, if defined, indicates that 64-bit interfaces should
* be used when available. If not defined, the native default interfaces
#define my_chsize Perl_my_chsize
#define my_exit Perl_my_exit
#define my_failure_exit Perl_my_failure_exit
+#define my_fflush_all Perl_my_fflush_all
#define my_htonl Perl_my_htonl
#define my_lstat Perl_my_lstat
#define my_memcmp Perl_my_memcmp
#define my_exit CPerlObj::Perl_my_exit
#define my_exit_jump CPerlObj::Perl_my_exit_jump
#define my_failure_exit CPerlObj::Perl_my_failure_exit
+#define my_fflush_all CPerlObj::Perl_my_fflush_all
#define my_htonl CPerlObj::Perl_my_htonl
#define my_lstat CPerlObj::Perl_my_lstat
#define my_memcmp CPerlObj::Perl_my_memcmp
my_chsize
my_exit
my_failure_exit
+my_fflush_all
my_htonl
my_lstat
my_memcmp
#define my_exit_jump pPerl->Perl_my_exit_jump
#undef my_failure_exit
#define my_failure_exit pPerl->Perl_my_failure_exit
+#undef my_fflush_all
+#define my_fflush_all pPerl->Perl_my_fflush_all
#undef my_htonl
#define my_htonl pPerl->Perl_my_htonl
#undef my_lstat
* XXX the default needs a Configure test, as it may not work everywhere.
*/
#ifndef PERL_FLUSHALL_FOR_CHILD
-# if (defined(USE_STDIO) && defined(FFLUSH_NULL)) || defined(USE_SFIO)
+# if defined(FFLUSH_NULL) || defined(USE_SFIO)
# define PERL_FLUSHALL_FOR_CHILD PerlIO_flush((PerlIO*)NULL)
+# else
+# ifdef FFLUSH_ALL
+# define PERL_FLUSHALL_FOR_CHILD my_fflush_all()
+# endif
# endif
#endif
#endif
VIRTUAL void my_exit _((U32 status)) __attribute__((noreturn));
VIRTUAL void my_failure_exit _((void)) __attribute__((noreturn));
+VIRTUAL I32 my_fflush_all _((void));
VIRTUAL I32 my_lstat _((ARGSproto));
#if !defined(HAS_MEMCMP) || !defined(HAS_SANE_MEMCMP)
VIRTUAL I32 my_memcmp _((const char* s1, const char* s2, I32 len));
return result;
}
+I32
+my_fflush_all(void)
+{
+#ifdef FFLUSH_NULL
+ return fflush(NULL);
+#else
+ long open_max = -1;
+# if defined(FFLUSH_ALL) && defined(STDIO_STREAM_ARRAY)
+# if defined(HAS_SYSCONF) && defined(_SC_OPEN_MAX)
+ open_max = sysconf(_SC_OPEN_MAX);
+# else
+# ifdef FOPEN_MAX
+# open_max = FOPEN_MAX;
+# else
+# ifdef OPEN_MAX
+# open_max = OPEN_MAX;
+# else
+# ifdef _NFILE
+# open_max = _NFILE;
+# endif
+# endif
+# endif
+# endif
+ if (open_max > 0) {
+ long i;
+ for (i = 0; i < open_max; i++)
+ fflush(&STDIO_STREAM_ARRAY[i]);
+ return 0;
+ }
+# endif
+ SETERRNO(EBADF,RMS$_IFI);
+ return EOF;
+#endif
+}