From: Christos Zoulas Date: Tue, 7 Aug 2001 16:01:25 +0000 (+0000) Subject: better daylight/tm_isdst etc. detection. X-Git-Tag: FILE3_37~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a9b475ecaa8640ce889a6c2a7c14dd3dd707d9de;p=file better daylight/tm_isdst etc. detection. --- diff --git a/Makefile.in b/Makefile.in index 5fa1cd73..183b6ae0 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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) diff --git a/acinclude.m4 b/acinclude.m4 index 3da5afb7..95990e52 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -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 +#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 +#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 +#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 +#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 diff --git a/aclocal.m4 b/aclocal.m4 index 39c1ebc6..b8a49559 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -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 +#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 +#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 +#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 +#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 diff --git a/config.h.in b/config.h.in index 60dfc564..a1b6f374 100644 --- a/config.h.in +++ b/config.h.in @@ -9,6 +9,13 @@ /* Define if you have 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 . */ #undef MAJOR_IN_MKDEV @@ -24,6 +31,9 @@ /* Define if you have the ANSI C header files. */ #undef STDC_HEADERS +/* Define if your 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 diff --git a/configure b/configure index 6488d5fa..3fcf2719 100755 --- a/configure +++ b/configure @@ -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 < +#include +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 < +#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 < +#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 < +#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 < +#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 < #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 < #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 < #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 <&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 < #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 < #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 < #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 < #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 < #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 <&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 diff --git a/configure.in b/configure.in index 4699f75e..d8bee8f5 100644 --- a/configure.in +++ b/configure.in @@ -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) diff --git a/src/acconfig.h b/src/acconfig.h index ef6e0cb6..b2d201df 100644 --- a/src/acconfig.h +++ b/src/acconfig.h @@ -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 diff --git a/src/print.c b/src/print.c index bf2c6679..b6803994 100644 --- a/src/print.c +++ b/src/print.c @@ -41,7 +41,7 @@ #include #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);