#!/bin/sh
#*=====================================================================*/
#*    serrano/prgm/project/bigloo/autoconf/select                      */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Wed Aug  9 13:27:23 1995                          */
#*    Last change :  Thu Jan  3 10:03:16 2002 (serrano)                */
#*    -------------------------------------------------------------    */
#*    Check if select exits. Returns 0 if it exists, 1 otherwise.      */
#*=====================================================================*/

#*---------------------------------------------------------------------*/
#*    flags                                                            */
#*---------------------------------------------------------------------*/
cc=gcc
cflags=
tmp=/tmp
user=bigloo

#*---------------------------------------------------------------------*/
#*    We parse the arguments                                           */
#*---------------------------------------------------------------------*/
while : ; do
  case $1 in
    "")
      break;;

    --user=*)
      user="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --cc=*|-cc=*)
      cc="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --cflags=*|-cflags=*)
      cflags="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --tmp=*|-tmp=*)
      tmp="`echo $1 | sed 's/^[-a-z]*=//'`";;

    -*)
      echo "Unknown option \"$1\", ignored" >&2;;
  esac
  shift
done

file=$tmp/actest$user
aout=$tmp/Xactest$user

#*---------------------------------------------------------------------*/
#*    compile                                                          */
#*---------------------------------------------------------------------*/
compile="$cc $cflags $file.c -o $aout >/dev/null 2> /dev/null"

#*---------------------------------------------------------------------*/
#*    The test C file                                                  */
#*---------------------------------------------------------------------*/
if( test -f $file.c ); then
   rm -f $file.c || exit $?
fi

#*---------------------------------------------------------------------*/
#*    Test                                                             */
#*---------------------------------------------------------------------*/
cat > $file.c <<EOF
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
#include <stdio.h>

main( argc, argv )
int   argc;
char *argv[];
{
   fd_set readfds;
   struct timeval timeout;
   int fno = fileno( stdin ) + 1;

   FD_ZERO( &readfds );
   FD_SET( fno, &readfds );
   timeout.tv_sec = 0; timeout.tv_usec = 0;
   
   return select( fno, &readfds, NULL, NULL, &timeout );
}
EOF

#*---------------------------------------------------------------------*/
#*    Compilation test                                                 */
#*---------------------------------------------------------------------*/
if eval $compile; then
   \rm -f $file.*
   rm -f $aout
   rm -f $aout*
   echo 1
else
   echo 0
fi

exit 0

   



