better daylight/tm_isdst etc. detection.

This commit is contained in:
Christos Zoulas 2001-08-07 16:01:25 +00:00
parent d6450d1a7c
commit a9b475ecaa
8 changed files with 328 additions and 29 deletions

View File

@ -122,7 +122,7 @@ missing mkinstalldirs
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = tar
TAR = gtar
GZIP_ENV = --best
SOURCES = $(file_SOURCES)
OBJECTS = $(file_OBJECTS)

View File

@ -21,6 +21,51 @@ dnl From: eggert@twinsun.com (Paul Eggert)
dnl Subject: autoconf 2.13 AC_CHECK_TYPE doesn't allow shell vars
dnl Newsgroups: gnu.utils.bug
dnl from autoconf 2.13 acspecific.m4, with changes to check for daylight
AC_DEFUN(AC_STRUCT_TIMEZONE_DAYLIGHT,
[AC_REQUIRE([AC_STRUCT_TM])dnl
AC_CACHE_CHECK([for tm_zone in struct tm], ac_cv_struct_tm_zone,
[AC_TRY_COMPILE([#include <sys/types.h>
#include <$ac_cv_struct_tm>], [struct tm tm; tm.tm_zone;],
ac_cv_struct_tm_zone=yes, ac_cv_struct_tm_zone=no)])
if test "$ac_cv_struct_tm_zone" = yes; then
AC_DEFINE(HAVE_TM_ZONE)
fi
AC_CACHE_CHECK(for tzname, ac_cv_var_tzname,
[AC_TRY_LINK(
changequote(<<, >>)dnl
<<#include <time.h>
#ifndef tzname /* For SGI. */
extern char *tzname[]; /* RS6000 and others reject char **tzname. */
#endif>>,
changequote([, ])dnl
[atoi(*tzname);], ac_cv_var_tzname=yes, ac_cv_var_tzname=no)])
if test $ac_cv_var_tzname = yes; then
AC_DEFINE(HAVE_TZNAME)
fi
AC_CACHE_CHECK([for tm_isdst in struct tm], ac_cv_struct_tm_isdst,
[AC_TRY_COMPILE([#include <sys/types.h>
#include <$ac_cv_struct_tm>], [struct tm tm; tm.tm_isdst;],
ac_cv_struct_tm_isdst=yes, ac_cv_struct_tm_isdst=no)])
if test "$ac_cv_struct_tm_isdst" = yes; then
AC_DEFINE(HAVE_TM_ISDST)
fi
AC_CACHE_CHECK(for daylight, ac_cv_var_daylight,
[AC_TRY_LINK(
changequote(<<, >>)dnl
<<#include <time.h>
#ifndef daylight /* In case IRIX #defines this, too */
extern int daylight;
#endif>>,
changequote([, ])dnl
[atoi(daylight);], ac_cv_var_daylight=yes, ac_cv_var_daylight=no)])
if test $ac_cv_var_daylight = yes; then
AC_DEFINE(HAVE_DAYLIGHT)
fi
])
dnl AC_CHECK_TYPE2(TYPE, DEFAULT)
AC_DEFUN(AC_CHECK_TYPE2,
[AC_REQUIRE([AC_HEADER_STDC])dnl

45
aclocal.m4 vendored
View File

@ -33,6 +33,51 @@ dnl From: eggert@twinsun.com (Paul Eggert)
dnl Subject: autoconf 2.13 AC_CHECK_TYPE doesn't allow shell vars
dnl Newsgroups: gnu.utils.bug
dnl from autoconf 2.13 acspecific.m4, with changes to check for daylight
AC_DEFUN(AC_STRUCT_TIMEZONE_DAYLIGHT,
[AC_REQUIRE([AC_STRUCT_TM])dnl
AC_CACHE_CHECK([for tm_zone in struct tm], ac_cv_struct_tm_zone,
[AC_TRY_COMPILE([#include <sys/types.h>
#include <$ac_cv_struct_tm>], [struct tm tm; tm.tm_zone;],
ac_cv_struct_tm_zone=yes, ac_cv_struct_tm_zone=no)])
if test "$ac_cv_struct_tm_zone" = yes; then
AC_DEFINE(HAVE_TM_ZONE)
fi
AC_CACHE_CHECK(for tzname, ac_cv_var_tzname,
[AC_TRY_LINK(
changequote(<<, >>)dnl
<<#include <time.h>
#ifndef tzname /* For SGI. */
extern char *tzname[]; /* RS6000 and others reject char **tzname. */
#endif>>,
changequote([, ])dnl
[atoi(*tzname);], ac_cv_var_tzname=yes, ac_cv_var_tzname=no)])
if test $ac_cv_var_tzname = yes; then
AC_DEFINE(HAVE_TZNAME)
fi
AC_CACHE_CHECK([for tm_isdst in struct tm], ac_cv_struct_tm_isdst,
[AC_TRY_COMPILE([#include <sys/types.h>
#include <$ac_cv_struct_tm>], [struct tm tm; tm.tm_isdst;],
ac_cv_struct_tm_isdst=yes, ac_cv_struct_tm_isdst=no)])
if test "$ac_cv_struct_tm_isdst" = yes; then
AC_DEFINE(HAVE_TM_ISDST)
fi
AC_CACHE_CHECK(for daylight, ac_cv_var_daylight,
[AC_TRY_LINK(
changequote(<<, >>)dnl
<<#include <time.h>
#ifndef daylight /* In case IRIX #defines this, too */
extern int daylight;
#endif>>,
changequote([, ])dnl
[atoi(daylight);], ac_cv_var_daylight=yes, ac_cv_var_daylight=no)])
if test $ac_cv_var_daylight = yes; then
AC_DEFINE(HAVE_DAYLIGHT)
fi
])
dnl AC_CHECK_TYPE2(TYPE, DEFAULT)
AC_DEFUN(AC_CHECK_TYPE2,
[AC_REQUIRE([AC_HEADER_STDC])dnl

View File

@ -9,6 +9,13 @@
/* Define if you have <sys/wait.h> that is POSIX.1 compatible. */
#undef HAVE_SYS_WAIT_H
/* Define if your struct tm has tm_zone. */
#undef HAVE_TM_ZONE
/* Define if you don't have tm_zone but do have the external array
tzname. */
#undef HAVE_TZNAME
/* Define if major, minor, and makedev are declared in <mkdev.h>. */
#undef MAJOR_IN_MKDEV
@ -24,6 +31,9 @@
/* Define if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Define if your <sys/time.h> declares struct tm. */
#undef TM_IN_SYS_TIME
/* Define if builtin ELF support is enabled. */
#undef BUILTIN_ELF
@ -33,6 +43,12 @@
/* Define if the `long long' type works. */
#undef HAVE_LONG_LONG
/* Define if we have "tm_isdst" in "struct tm". */
#undef HAVE_TM_ISDST
/* Define if we have a global "int" variable "daylight". */
#undef HAVE_DAYLIGHT
/* Define to `unsigned char' if standard headers don't define. */
#undef uint8_t

224
configure vendored
View File

@ -1802,14 +1802,186 @@ EOF
fi
echo $ac_n "checking whether struct tm is in sys/time.h or time.h""... $ac_c" 1>&6
echo "configure:1807: checking whether struct tm is in sys/time.h or time.h" >&5
if eval "test \"`echo '$''{'ac_cv_struct_tm'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 1812 "configure"
#include "confdefs.h"
#include <sys/types.h>
#include <time.h>
int main() {
struct tm *tp; tp->tm_sec;
; return 0; }
EOF
if { (eval echo configure:1820: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
ac_cv_struct_tm=time.h
else
echo "configure: failed program was:" >&5
cat conftest.$ac_ext >&5
rm -rf conftest*
ac_cv_struct_tm=sys/time.h
fi
rm -f conftest*
fi
echo "$ac_t""$ac_cv_struct_tm" 1>&6
if test $ac_cv_struct_tm = sys/time.h; then
cat >> confdefs.h <<\EOF
#define TM_IN_SYS_TIME 1
EOF
fi
echo $ac_n "checking for tm_zone in struct tm""... $ac_c" 1>&6
echo "configure:1841: checking for tm_zone in struct tm" >&5
if eval "test \"`echo '$''{'ac_cv_struct_tm_zone'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 1846 "configure"
#include "confdefs.h"
#include <sys/types.h>
#include <$ac_cv_struct_tm>
int main() {
struct tm tm; tm.tm_zone;
; return 0; }
EOF
if { (eval echo configure:1854: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
ac_cv_struct_tm_zone=yes
else
echo "configure: failed program was:" >&5
cat conftest.$ac_ext >&5
rm -rf conftest*
ac_cv_struct_tm_zone=no
fi
rm -f conftest*
fi
echo "$ac_t""$ac_cv_struct_tm_zone" 1>&6
if test "$ac_cv_struct_tm_zone" = yes; then
cat >> confdefs.h <<\EOF
#define HAVE_TM_ZONE 1
EOF
fi
echo $ac_n "checking for tzname""... $ac_c" 1>&6
echo "configure:1874: checking for tzname" >&5
if eval "test \"`echo '$''{'ac_cv_var_tzname'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 1879 "configure"
#include "confdefs.h"
#include <time.h>
#ifndef tzname /* For SGI. */
extern char *tzname[]; /* RS6000 and others reject char **tzname. */
#endif
int main() {
atoi(*tzname);
; return 0; }
EOF
if { (eval echo configure:1889: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
ac_cv_var_tzname=yes
else
echo "configure: failed program was:" >&5
cat conftest.$ac_ext >&5
rm -rf conftest*
ac_cv_var_tzname=no
fi
rm -f conftest*
fi
echo "$ac_t""$ac_cv_var_tzname" 1>&6
if test $ac_cv_var_tzname = yes; then
cat >> confdefs.h <<\EOF
#define HAVE_TZNAME 1
EOF
fi
echo $ac_n "checking for tm_isdst in struct tm""... $ac_c" 1>&6
echo "configure:1910: checking for tm_isdst in struct tm" >&5
if eval "test \"`echo '$''{'ac_cv_struct_tm_isdst'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 1915 "configure"
#include "confdefs.h"
#include <sys/types.h>
#include <$ac_cv_struct_tm>
int main() {
struct tm tm; tm.tm_isdst;
; return 0; }
EOF
if { (eval echo configure:1923: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
ac_cv_struct_tm_isdst=yes
else
echo "configure: failed program was:" >&5
cat conftest.$ac_ext >&5
rm -rf conftest*
ac_cv_struct_tm_isdst=no
fi
rm -f conftest*
fi
echo "$ac_t""$ac_cv_struct_tm_isdst" 1>&6
if test "$ac_cv_struct_tm_isdst" = yes; then
cat >> confdefs.h <<\EOF
#define HAVE_TM_ISDST 1
EOF
fi
echo $ac_n "checking for daylight""... $ac_c" 1>&6
echo "configure:1943: checking for daylight" >&5
if eval "test \"`echo '$''{'ac_cv_var_daylight'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 1948 "configure"
#include "confdefs.h"
#include <time.h>
#ifndef daylight /* In case IRIX #defines this, too */
extern int daylight;
#endif
int main() {
atoi(daylight);
; return 0; }
EOF
if { (eval echo configure:1958: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
ac_cv_var_daylight=yes
else
echo "configure: failed program was:" >&5
cat conftest.$ac_ext >&5
rm -rf conftest*
ac_cv_var_daylight=no
fi
rm -f conftest*
fi
echo "$ac_t""$ac_cv_var_daylight" 1>&6
if test $ac_cv_var_daylight = yes; then
cat >> confdefs.h <<\EOF
#define HAVE_DAYLIGHT 1
EOF
fi
echo $ac_n "checking for uint8_t""... $ac_c" 1>&6
echo "configure:1808: checking for uint8_t" >&5
echo "configure:1980: checking for uint8_t" >&5
if eval "test \"`echo '$''{'ac_cv_type_uint8_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 1813 "configure"
#line 1985 "configure"
#include "confdefs.h"
#include <sys/types.h>
#if STDC_HEADERS
@ -1837,12 +2009,12 @@ EOF
fi
echo $ac_n "checking for uint16_t""... $ac_c" 1>&6
echo "configure:1841: checking for uint16_t" >&5
echo "configure:2013: checking for uint16_t" >&5
if eval "test \"`echo '$''{'ac_cv_type_uint16_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 1846 "configure"
#line 2018 "configure"
#include "confdefs.h"
#include <sys/types.h>
#if STDC_HEADERS
@ -1870,12 +2042,12 @@ EOF
fi
echo $ac_n "checking for uint32_t""... $ac_c" 1>&6
echo "configure:1874: checking for uint32_t" >&5
echo "configure:2046: checking for uint32_t" >&5
if eval "test \"`echo '$''{'ac_cv_type_uint32_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 1879 "configure"
#line 2051 "configure"
#include "confdefs.h"
#include <sys/types.h>
#if STDC_HEADERS
@ -1904,7 +2076,7 @@ fi
echo $ac_n "checking for long long""... $ac_c" 1>&6
echo "configure:1908: checking for long long" >&5
echo "configure:2080: checking for long long" >&5
if eval "test \"`echo '$''{'ac_cv_c_long_long'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@ -1915,13 +2087,13 @@ if test "$cross_compiling" = yes; then
{ echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
else
cat > conftest.$ac_ext <<EOF
#line 1919 "configure"
#line 2091 "configure"
#include "confdefs.h"
int main() {
long long foo = 0;
exit(sizeof(long long) < sizeof(long)); }
EOF
if { (eval echo configure:1925: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
if { (eval echo configure:2097: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_c_long_long=yes
else
@ -1950,12 +2122,12 @@ else
long64='unsigned long';
fi
echo $ac_n "checking for uint64_t""... $ac_c" 1>&6
echo "configure:1954: checking for uint64_t" >&5
echo "configure:2126: checking for uint64_t" >&5
if eval "test \"`echo '$''{'ac_cv_type_uint64_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 1959 "configure"
#line 2131 "configure"
#include "confdefs.h"
#include <sys/types.h>
#if STDC_HEADERS
@ -1986,7 +2158,7 @@ fi
echo $ac_n "checking size of uint8_t""... $ac_c" 1>&6
echo "configure:1990: checking size of uint8_t" >&5
echo "configure:2162: checking size of uint8_t" >&5
if eval "test \"`echo '$''{'ac_cv_sizeof_uint8_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@ -1994,7 +2166,7 @@ else
ac_cv_sizeof_uint8_t=0
else
cat > conftest.$ac_ext <<EOF
#line 1998 "configure"
#line 2170 "configure"
#include "confdefs.h"
#include <sys/types.h>
#ifdef STDC_HEADERS
@ -2010,7 +2182,7 @@ main()
exit(0);
}
EOF
if { (eval echo configure:2014: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
if { (eval echo configure:2186: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_sizeof_uint8_t=`cat conftestval`
else
@ -2031,7 +2203,7 @@ EOF
echo $ac_n "checking size of uint16_t""... $ac_c" 1>&6
echo "configure:2035: checking size of uint16_t" >&5
echo "configure:2207: checking size of uint16_t" >&5
if eval "test \"`echo '$''{'ac_cv_sizeof_uint16_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@ -2039,7 +2211,7 @@ else
ac_cv_sizeof_uint16_t=0
else
cat > conftest.$ac_ext <<EOF
#line 2043 "configure"
#line 2215 "configure"
#include "confdefs.h"
#include <sys/types.h>
#ifdef STDC_HEADERS
@ -2055,7 +2227,7 @@ main()
exit(0);
}
EOF
if { (eval echo configure:2059: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
if { (eval echo configure:2231: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_sizeof_uint16_t=`cat conftestval`
else
@ -2076,7 +2248,7 @@ EOF
echo $ac_n "checking size of uint32_t""... $ac_c" 1>&6
echo "configure:2080: checking size of uint32_t" >&5
echo "configure:2252: checking size of uint32_t" >&5
if eval "test \"`echo '$''{'ac_cv_sizeof_uint32_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@ -2084,7 +2256,7 @@ else
ac_cv_sizeof_uint32_t=0
else
cat > conftest.$ac_ext <<EOF
#line 2088 "configure"
#line 2260 "configure"
#include "confdefs.h"
#include <sys/types.h>
#ifdef STDC_HEADERS
@ -2100,7 +2272,7 @@ main()
exit(0);
}
EOF
if { (eval echo configure:2104: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
if { (eval echo configure:2276: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_sizeof_uint32_t=`cat conftestval`
else
@ -2121,7 +2293,7 @@ EOF
echo $ac_n "checking size of uint64_t""... $ac_c" 1>&6
echo "configure:2125: checking size of uint64_t" >&5
echo "configure:2297: checking size of uint64_t" >&5
if eval "test \"`echo '$''{'ac_cv_sizeof_uint64_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@ -2129,7 +2301,7 @@ else
ac_cv_sizeof_uint64_t=0
else
cat > conftest.$ac_ext <<EOF
#line 2133 "configure"
#line 2305 "configure"
#include "confdefs.h"
#include <sys/types.h>
#ifdef STDC_HEADERS
@ -2145,7 +2317,7 @@ main()
exit(0);
}
EOF
if { (eval echo configure:2149: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
if { (eval echo configure:2321: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_sizeof_uint64_t=`cat conftestval`
else
@ -2169,12 +2341,12 @@ EOF
for ac_func in mmap strerror strtoul
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:2173: checking for $ac_func" >&5
echo "configure:2345: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 2178 "configure"
#line 2350 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@ -2197,7 +2369,7 @@ $ac_func();
; return 0; }
EOF
if { (eval echo configure:2201: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
if { (eval echo configure:2373: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else

View File

@ -66,6 +66,7 @@ AC_C_CONST
AC_TYPE_OFF_T
AC_TYPE_SIZE_T
AC_STRUCT_ST_RDEV
AC_STRUCT_TIMEZONE_DAYLIGHT
dnl FIXME: only found in standard headers!
AC_CHECK_TYPE(uint8_t, unsigned char)

View File

@ -13,6 +13,12 @@
/* Define if the `long long' type works. */
#undef HAVE_LONG_LONG
/* Define if we have "tm_isdst" in "struct tm". */
#undef HAVE_TM_ISDST
/* Define if we have a global "int" variable "daylight". */
#undef HAVE_DAYLIGHT
/* Define to `unsigned char' if standard headers don't define. */
#undef uint8_t

View File

@ -41,7 +41,7 @@
#include <time.h>
#ifndef lint
FILE_RCSID("@(#)$Id: print.c,v 1.33 2001/07/22 21:04:15 christos Exp $")
FILE_RCSID("@(#)$Id: print.c,v 1.34 2001/08/07 16:01:26 christos Exp $")
#endif /* lint */
#define SZOF(a) (sizeof(a) / sizeof(a[0]))
@ -234,10 +234,24 @@ fmttime(v, local)
{
char *pp, *rt;
time_t t = (time_t)v;
struct tm *tm;
if (local) {
pp = ctime(&t);
} else {
struct tm *tm;
#ifndef HAVE_DAYLIGHT
static int daylight = 0;
#ifdef HAVE_TM_ISDST
static time_t now = (time_t)0;
if (now == (time_t)0) {
struct tm *tm1;
(void)time(&now);
tm1 = localtime(&now);
daylight = tm1->tm_isdst;
}
#endif /* HAVE_TM_ISDST */
#endif /* HAVE_DAYLIGHT */
if (daylight)
t += 3600;
tm = gmtime(&t);