#!/bin/sh
#*=====================================================================*/
#*    serrano/prgm/project/bigloo/bigloo/autoconf/posixfileops         */
#*    -------------------------------------------------------------    */
#*    Author      :  Christian Loitsch                                 */
#*    Creation    :  Wed Apr 16 12:07:23 2003                          */
#*    Last change :  Mon Jul 10 13:55:09 2023 (serrano)                */
#*    -------------------------------------------------------------    */
#*    Check if fileno and read exist.                                  */
#*=====================================================================*/

#*---------------------------------------------------------------------*/
#*    flags                                                            */
#*---------------------------------------------------------------------*/
cflags=

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

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

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

file=$TMP/pftest$USER
aout=$TMP/PFtest$USER

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

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

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

int main( int argc, char *argv[] ) {
   char buffer [50];
   FILE *f;
   f = fopen( "/etc/passwd", "r" );
   return (read( fileno( f ), buffer, 50 ) >= 0);
}
EOF

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