#!/bin/sh
#*=====================================================================*/
#*    serrano/prgm/project/bigloo/bigloo/autoconf/localtime_r          */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Wed Aug  9 13:27:23 1995                          */
#*    Last change :  Tue Mar 28 14:03:21 2023 (serrano)                */
#*    -------------------------------------------------------------    */
#*    Check if localtime_r exists                                      */
#*=====================================================================*/

#*---------------------------------------------------------------------*/
#*    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/actest$USER
aout=$TMP/Xactest$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

#*---------------------------------------------------------------------*/
#*    Test1                                                            */
#*---------------------------------------------------------------------*/
cat > $file.c <<EOF
#include <time.h>
#include <ctype.h>
#include <sys/time.h>

int main(int argc, char *argv[]) {
   time_t sec = 1445367545;
   struct tm res;

   localtime_r(&sec, &res);

   return (res.tm_hour == 20) ? 0 : 1;
}
EOF

if eval "$BUILDSH $compile"; then
   \rm -f $file.*
   if eval "$HOSTSH $aout" > /dev/null; then
      rm -f $aout
      echo "1";
      exit 0;
   fi
fi

#*---------------------------------------------------------------------*/
#*    default                                                          */
#*---------------------------------------------------------------------*/
\rm -f $file.*

echo "0"
exit 0;
