3 ?RCS: Copyright (c) 1999, Jarkko Hietaniemi
5 ?RCS: You may redistribute only under the terms of the Artistic Licence,
6 ?RCS: as specified in the README file that comes with the distribution.
7 ?RCS: You may reuse parts of this distribution only within the terms of
8 ?RCS: that same Artistic Licence; a copy of which may be found at the root
9 ?RCS: of the source tree for dist 3.0.
11 ?MAKE:fflushNULL fflushall: Compile cat rm rm_try test osname run to from \
12 Oldconfig Myread Setvar echo \
13 d_sysconf i_unistd d_stdio_stream_array stdio_stream_array i_stdlib
14 ?MAKE: -pick add $@ %<
16 ?S: This symbol, if defined, tells that fflush(NULL) does flush
17 ?S: all pending stdio output.
20 ?S: This symbol, if defined, tells that to flush
21 ?S: all pending stdio output one must loop through all
22 ?S: the stdio file handles stored in an array and fflush them.
23 ?S: Note that if fflushNULL is defined, fflushall will not
24 ?S: even be probed for and will be left undefined.
27 ?C: This symbol, if defined, tells that fflush(NULL) does flush
28 ?C: all pending stdio output.
31 ?C: This symbol, if defined, tells that to flush
32 ?C: all pending stdio output one must loop through all
33 ?C: the stdio file handles stored in an array and fflush them.
34 ?C: Note that if fflushNULL is defined, fflushall will not
35 ?C: even be probed for and will be left undefined.
37 ?H:#$fflushNULL FFLUSH_NULL /**/
38 ?H:#$fflushall FFLUSH_ALL /**/
45 Checking how to flush all pending stdio output...
47 # I only know how to find the first 32 possibly open files on SunOS.
48 # See also hints/sunos_4_1.sh and util.c --AD
50 sunos) $echo '#define PERL_FFLUSH_ALL_FOPEN_MAX 32' > try.c ;;
62 #$d_sysconf HAS_SYSCONF
63 #$d_stdio_stream_array HAS_STDIO_STREAM_ARRAY
64 #ifdef HAS_STDIO_STREAM_ARRAY
65 # define STDIO_STREAM_ARRAY $stdio_stream_array
70 p = fopen("try.out", "w");
78 #ifdef TRY_FFLUSH_NULL
84 # ifdef PERL_FFLUSH_ALL_FOPEN_MAX
85 open_max = PERL_FFLUSH_ALL_FOPEN_MAX;
87 # if defined(HAS_SYSCONF) && defined(_SC_OPEN_MAX)
88 open_max = sysconf(_SC_OPEN_MAX);
103 # ifdef HAS_STDIO_STREAM_ARRAY
106 for (i = 0; i < open_max; i++)
107 if (STDIO_STREAM_ARRAY[i]._file >= 0 &&
108 STDIO_STREAM_ARRAY[i]._file < open_max &&
109 STDIO_STREAM_ARRAY[i]._flag)
110 fflush(&STDIO_STREAM_ARRAY[i]);
118 : first we have to find out how _not_ to flush
120 if $test "X$fflushNULL" = X -o "X$fflushall" = X; then
123 if eval $compile; then
124 $run ./try 2>/dev/null
127 if $test ! -s try.out -a "X$code" = X42; then
133 set try -DTRY_FPRINTF
134 if eval $compile; then
135 $run ./try 2>/dev/null
138 if $test ! -s try.out -a "X$code" = X42; then
145 : check for fflush NULL behaviour
146 case "$fflushNULL" in
147 '') set try -DTRY_FFLUSH_NULL $output
148 if eval $compile; then
149 $run ./try 2>/dev/null
152 if $test -s try.out -a "X$code" = X42; then
153 fflushNULL="`$cat try.out`"
155 if $test "X$code" != X42; then
157 (If this test failed, don't worry, we'll try another method shortly.)
163 case "$fflushNULL" in
165 Your fflush(NULL) works okay for output streams.
166 Let's see if it clobbers input pipes...
168 # As of mid-March 2000 all versions of Solaris appear to have a stdio
169 # bug that improperly flushes the input end of pipes. So we avoid the
170 # autoflush on fork/system/exec support for now. :-(
174 main(int argc, char **argv)
180 while ((i = getc(stdin)) != -1
181 && (*bp++ = i) != '\n'
185 fprintf(stdout, "%s", buf);
195 if eval $compile; then
197 $cat tryp.c | $run ./tryp 2>/dev/null > tryp.out
198 if cmp tryp.c tryp.out >/dev/null 2>&1; then
200 fflush(NULL) seems to behave okay with input streams.
205 Ouch, fflush(NULL) clobbers input pipes! We will not use it.
210 $rm -f core tryp.c tryp.core core.tryp.*
213 Your fflush(NULL) isn't working (contrary to ANSI C).
218 Cannot figure out whether your fflush(NULL) works or not.
219 I'm assuming it doesn't (contrary to ANSI C).
232 : check explicit looping only if NULL did not work, and if the pipe
233 : bug does not show up on an explicit flush too
234 case "$fflushNULL" in
239 main(int argc, char **argv)
245 while ((i = getc(stdin)) != -1
246 && (*bp++ = i) != '\n'
250 fprintf(stdout, "%s", buf);
259 if eval $compile; then
261 $cat tryp.c | $run ./tryp 2>/dev/null > tryp.out
262 if cmp tryp.c tryp.out >/dev/null 2>&1; then
264 Good, at least fflush(stdin) seems to behave okay when stdin is a pipe.
266 : now check for fflushall behaviour
268 '') set try -DTRY_FFLUSH_ALL $output
269 if eval $compile; then
271 (Now testing the other method--but note that this also may fail.)
273 $run ./try 2>/dev/null
276 if $test -s try.out -a "X$code" = X42; then
277 fflushall="`$cat try.out`"
283 Whew. Flushing explicitly all the stdio streams works.
288 Sigh. Flushing explicitly all the stdio streams doesn't work.
293 Cannot figure out whether flushing stdio streams explicitly works or not.
294 I'm assuming it doesn't.
300 "$define"|true|[yY]*)
309 All is futile. Even fflush(stdin) clobbers input pipes!
316 $rm -f core tryp.c tryp.core core.tryp.*
318 *) fflushall="$undef"
322 case "$fflushNULL$fflushall" in
325 OK, I give up. I cannot figure out how to flush pending stdio output.
326 We won't be flushing handles at all before fork/exec/popen.