This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Spelling - megapatch
[metaconfig.git] / U / compline / nblock_io.U
index b2de1ff..71b9158 100644 (file)
@@ -1,11 +1,11 @@
 ?RCS: $Id: nblock_io.U,v 3.0.1.2 1997/02/28 16:17:14 ram Exp $
 ?RCS:
 ?RCS: Copyright (c) 1991-1993, Raphael Manfredi
-?RCS: 
-?RCS: You may redistribute only under the terms of the Artistic Licence,
+?RCS:
+?RCS: You may redistribute only under the terms of the Artistic License,
 ?RCS: as specified in the README file that comes with the distribution.
 ?RCS: You may reuse parts of this distribution only within the terms of
-?RCS: that same Artistic Licence; a copy of which may be found at the root
+?RCS: that same Artistic License; a copy of which may be found at the root
 ?RCS: of the source tree for dist 3.0.
 ?RCS:
 ?RCS: $Log: nblock_io.U,v $
@@ -21,8 +21,9 @@
 ?X: Simplify here document for shells that can't handle them well.
 ?X: (Problem reported on FreeBSD; it's unclear if this helps.)  --AD
 ?X:
-?MAKE:o_nonblock eagain rd_nodata d_eofnblk: cat rm Compile \
-       d_open3 h_sysfile h_fcntl signal_t hint Oldconfig Setvar startsh
+?MAKE:o_nonblock eagain rd_nodata d_eofnblk: cat rm_try Compile run \
+       d_open3 h_sysfile h_fcntl signal_t hint Oldconfig Setvar \
+       startsh i_unistd i_string i_fcntl i_stdlib d_fork d_pipe
 ?MAKE: -pick add $@ %<
 ?S:o_nonblock:
 ?S:    This variable bears the symbol value to be used during open() or fcntl()
 ?H:#define RD_NODATA $rd_nodata
 ?H:#$d_eofnblk EOF_NONBLOCK
 ?H:.
-?F:!try !try.out !try.ret !try.err
 ?T:status
+?F:!try.out !try.ret !try.err !try !mtry
 ?LINT:use d_open3
 : check for non-blocking I/O stuff
 case "$h_sysfile" in
 true) echo "#include <sys/file.h>" > head.c;;
 *)
-       case "$h_fcntl" in
-       true) echo "#include <fcntl.h>" > head.c;;
-       *) echo "#include <sys/fcntl.h>" > head.c;;
-       esac
-       ;;
+       case "$h_fcntl" in
+       true) echo "#include <fcntl.h>" > head.c;;
+       *) echo "#include <sys/fcntl.h>" > head.c;;
+       esac
+       ;;
 esac
 echo " "
 echo "Figuring out the flag used by open() for non-blocking I/O..." >&4
 case "$o_nonblock" in
 '')
        $cat head.c > try.c
-       $cat >>try.c <<'EOCP'
+       $cat >>try.c <<EOCP
+#include <stdio.h>
+#$i_stdlib I_STDLIB
+#ifdef I_STDLIB
+#include <stdlib.h>
+#endif
+#$i_fcntl I_FCNTL
+#ifdef I_FCNTL
+#include <fcntl.h>
+#endif
 int main() {
 #ifdef O_NONBLOCK
        printf("O_NONBLOCK\n");
@@ -101,7 +111,7 @@ int main() {
        exit(0);
 #endif
 ?X: Stevens "Advanced Programming in the UNIX Environment" page 364 mentions
-?X: the FNDELAY symbol, used in 4.33BSD (source: Paul Marquess).
+?X: the FNDELAY symbol, used in 4.3BSD (source: Paul Marquess).
 #ifdef FNDELAY
        printf("FNDELAY\n");
        exit(0);
@@ -111,7 +121,7 @@ int main() {
 EOCP
        set try
        if eval $compile_ok; then
-               o_nonblock=`./try`
+               o_nonblock=`$run ./try`
                case "$o_nonblock" in
                '') echo "I can't figure it out, assuming O_NONBLOCK will do.";;
                *) echo "Seems like we can use $o_nonblock.";;
@@ -122,22 +132,43 @@ EOCP
        ;;
 *) echo "Using $hint value $o_nonblock.";;
 esac
-$rm -f try try.* .out core
+$rm_try
 
 echo " "
 echo "Let's see what value errno gets from read() on a $o_nonblock file..." >&4
 case "$eagain" in
 '')
+       case "$d_fork:$d_pipe" in
+       define:define)
        $cat head.c > try.c
        $cat >>try.c <<EOCP
 #include <errno.h>
 #include <sys/types.h>
 #include <signal.h>
+#include <stdio.h>
+#$i_stdlib I_STDLIB
+#ifdef I_STDLIB
+#include <stdlib.h>
+#endif
+#$i_fcntl I_FCNTL
+#ifdef I_FCNTL
+#include <fcntl.h>
+#endif
 #define MY_O_NONBLOCK $o_nonblock
 #ifndef errno  /* XXX need better Configure test */
 extern int errno;
 #endif
-$signal_t blech(x) int x; { exit(3); }
+#$i_unistd I_UNISTD
+#ifdef I_UNISTD
+#include <unistd.h>
+#endif
+#$i_string I_STRING
+#ifdef I_STRING
+#include <string.h>
+#else
+#include <strings.h>
+#endif
+$signal_t blech(int x) { exit(3); }
 EOCP
        $cat >> try.c <<'EOCP'
 int main()
@@ -153,8 +184,12 @@ int main()
                int ret;
                close(pd[1]);   /* Parent reads from pd[0] */
                close(pu[0]);   /* Parent writes (blocking) to pu[1] */
+#ifdef F_SETFL
                if (-1 == fcntl(pd[0], F_SETFL, MY_O_NONBLOCK))
                        exit(1);
+#else
+               exit(4);
+#endif
                signal(SIGALRM, blech);
                alarm(5);
                if ((ret = read(pd[0], buf, 1)) > 0)    /* Nothing to read! */
@@ -179,7 +214,7 @@ int main()
                ret = read(pd[0], buf, 1);      /* Should read EOF */
                alarm(0);
                sprintf(string, "%d\n", ret);
-               write(3, string, strlen(string));
+               write(4, string, strlen(string));
                exit(0);
        }
 
@@ -194,7 +229,7 @@ EOCP
        if eval $compile_ok; then
 ?X: Use script to avoid the possible 'alarm call' message
                echo "$startsh" >mtry
-               echo "./try >try.out 2>try.ret 3>try.err || exit 4" >>mtry
+               echo "$run ./try >try.out 2>try.ret 4>try.err || exit 4" >>mtry
                chmod +x mtry
                ./mtry >/dev/null 2>&1
                case $? in
@@ -202,6 +237,7 @@ EOCP
                1) echo "Could not perform non-blocking setting!";;
                2) echo "I did a successful read() for something that was not there!";;
                3) echo "Hmm... non-blocking I/O does not seem to be working!";;
+               4) echo "Could not find F_SETFL!";;
                *) echo "Something terribly wrong happened during testing.";;
                esac
                rd_nodata=`$cat try.ret`
@@ -237,6 +273,12 @@ EOCP
                echo "I can't compile the test program--assuming errno EAGAIN will do."
                eagain=EAGAIN
        fi
+       ;;
+       *)      echo "Can't figure out how to test this--assuming errno EAGAIN will do."
+               eagain=EAGAIN
+               val="$define"
+               ;;
+       esac
        set d_eofnblk
        eval $setvar
        ;;
@@ -254,5 +296,5 @@ EOCP
        esac
        ;;
 esac
-$rm -f try try.* .out core head.c mtry
+$rm_try head.c mtry