diff options
| author | Paul Eggert | 2011-01-08 22:57:07 -0800 |
|---|---|---|
| committer | Paul Eggert | 2011-01-08 22:57:07 -0800 |
| commit | 1fd182f01815629114a83d6987568dce72cc6bf5 (patch) | |
| tree | 17148e38af034214416d362909d5a3ec8c4e6c4a /lib | |
| parent | e84aba69759680c3d2461570168aabf52c5e12aa (diff) | |
| download | emacs-1fd182f01815629114a83d6987568dce72cc6bf5.tar.gz emacs-1fd182f01815629114a83d6987568dce72cc6bf5.zip | |
Regenerate.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Makefile.in | 138 | ||||
| -rw-r--r-- | lib/gnulib.mk | 152 | ||||
| -rw-r--r-- | lib/mktime-internal.h | 4 | ||||
| -rw-r--r-- | lib/mktime.c | 669 | ||||
| -rw-r--r-- | lib/stddef.in.h | 87 | ||||
| -rw-r--r-- | lib/time.h | 555 | ||||
| -rw-r--r-- | lib/time.in.h | 243 | ||||
| -rw-r--r-- | lib/time_r.c | 45 |
8 files changed, 1885 insertions, 8 deletions
diff --git a/lib/Makefile.in b/lib/Makefile.in index d1d6e4f8417..40254045808 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in | |||
| @@ -24,7 +24,7 @@ | |||
| 24 | # the same distribution terms as the rest of that program. | 24 | # the same distribution terms as the rest of that program. |
| 25 | # | 25 | # |
| 26 | # Generated by gnulib-tool. | 26 | # Generated by gnulib-tool. |
| 27 | # Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --no-libtool --macro-prefix=gl --no-vc-files ftoastr | 27 | # Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --no-libtool --macro-prefix=gl --no-vc-files ftoastr mktime |
| 28 | 28 | ||
| 29 | VPATH = @srcdir@ | 29 | VPATH = @srcdir@ |
| 30 | pkgdatadir = $(datadir)/@PACKAGE@ | 30 | pkgdatadir = $(datadir)/@PACKAGE@ |
| @@ -50,8 +50,13 @@ DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ | |||
| 50 | subdir = lib | 50 | subdir = lib |
| 51 | ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 | 51 | ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 |
| 52 | am__aclocal_m4_deps = $(top_srcdir)/m4/00gnulib.m4 \ | 52 | am__aclocal_m4_deps = $(top_srcdir)/m4/00gnulib.m4 \ |
| 53 | $(top_srcdir)/m4/c-strtod.m4 $(top_srcdir)/m4/gnulib-common.m4 \ | 53 | $(top_srcdir)/m4/c-strtod.m4 $(top_srcdir)/m4/extensions.m4 \ |
| 54 | $(top_srcdir)/m4/gnulib-comp.m4 $(top_srcdir)/m4/getopt.m4 \ | 54 | $(top_srcdir)/m4/gnulib-common.m4 \ |
| 55 | $(top_srcdir)/m4/gnulib-comp.m4 \ | ||
| 56 | $(top_srcdir)/m4/include_next.m4 $(top_srcdir)/m4/mktime.m4 \ | ||
| 57 | $(top_srcdir)/m4/multiarch.m4 $(top_srcdir)/m4/stddef_h.m4 \ | ||
| 58 | $(top_srcdir)/m4/time_h.m4 $(top_srcdir)/m4/time_r.m4 \ | ||
| 59 | $(top_srcdir)/m4/wchar_t.m4 $(top_srcdir)/m4/getopt.m4 \ | ||
| 55 | $(top_srcdir)/configure.in | 60 | $(top_srcdir)/configure.in |
| 56 | am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ | 61 | am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ |
| 57 | $(ACLOCAL_M4) | 62 | $(ACLOCAL_M4) |
| @@ -84,6 +89,7 @@ ALLOCA = @ALLOCA@ | |||
| 84 | ALSA_CFLAGS = @ALSA_CFLAGS@ | 89 | ALSA_CFLAGS = @ALSA_CFLAGS@ |
| 85 | ALSA_LIBS = @ALSA_LIBS@ | 90 | ALSA_LIBS = @ALSA_LIBS@ |
| 86 | AMTAR = @AMTAR@ | 91 | AMTAR = @AMTAR@ |
| 92 | APPLE_UNIVERSAL_BUILD = @APPLE_UNIVERSAL_BUILD@ | ||
| 87 | AUTOCONF = @AUTOCONF@ | 93 | AUTOCONF = @AUTOCONF@ |
| 88 | AUTOHEADER = @AUTOHEADER@ | 94 | AUTOHEADER = @AUTOHEADER@ |
| 89 | AUTOMAKE = @AUTOMAKE@ | 95 | AUTOMAKE = @AUTOMAKE@ |
| @@ -129,6 +135,11 @@ GETLOADAVG_LIBS = @GETLOADAVG_LIBS@ | |||
| 129 | GETOPTOBJS = @GETOPTOBJS@ | 135 | GETOPTOBJS = @GETOPTOBJS@ |
| 130 | GETOPT_H = @GETOPT_H@ | 136 | GETOPT_H = @GETOPT_H@ |
| 131 | GMALLOC_OBJ = @GMALLOC_OBJ@ | 137 | GMALLOC_OBJ = @GMALLOC_OBJ@ |
| 138 | GNULIB_MKTIME = @GNULIB_MKTIME@ | ||
| 139 | GNULIB_NANOSLEEP = @GNULIB_NANOSLEEP@ | ||
| 140 | GNULIB_STRPTIME = @GNULIB_STRPTIME@ | ||
| 141 | GNULIB_TIMEGM = @GNULIB_TIMEGM@ | ||
| 142 | GNULIB_TIME_R = @GNULIB_TIME_R@ | ||
| 132 | GNU_OBJC_CFLAGS = @GNU_OBJC_CFLAGS@ | 143 | GNU_OBJC_CFLAGS = @GNU_OBJC_CFLAGS@ |
| 133 | GREP = @GREP@ | 144 | GREP = @GREP@ |
| 134 | GTK_CFLAGS = @GTK_CFLAGS@ | 145 | GTK_CFLAGS = @GTK_CFLAGS@ |
| @@ -136,10 +147,17 @@ GTK_LIBS = @GTK_LIBS@ | |||
| 136 | GTK_OBJ = @GTK_OBJ@ | 147 | GTK_OBJ = @GTK_OBJ@ |
| 137 | GZIP_INFO = @GZIP_INFO@ | 148 | GZIP_INFO = @GZIP_INFO@ |
| 138 | GZIP_PROG = @GZIP_PROG@ | 149 | GZIP_PROG = @GZIP_PROG@ |
| 150 | HAVE_DECL_LOCALTIME_R = @HAVE_DECL_LOCALTIME_R@ | ||
| 139 | HAVE_MAKEINFO = @HAVE_MAKEINFO@ | 151 | HAVE_MAKEINFO = @HAVE_MAKEINFO@ |
| 152 | HAVE_NANOSLEEP = @HAVE_NANOSLEEP@ | ||
| 153 | HAVE_STRPTIME = @HAVE_STRPTIME@ | ||
| 154 | HAVE_TIMEGM = @HAVE_TIMEGM@ | ||
| 155 | HAVE_WCHAR_T = @HAVE_WCHAR_T@ | ||
| 140 | HAVE_XSERVER = @HAVE_XSERVER@ | 156 | HAVE_XSERVER = @HAVE_XSERVER@ |
| 141 | IMAGEMAGICK_CFLAGS = @IMAGEMAGICK_CFLAGS@ | 157 | IMAGEMAGICK_CFLAGS = @IMAGEMAGICK_CFLAGS@ |
| 142 | IMAGEMAGICK_LIBS = @IMAGEMAGICK_LIBS@ | 158 | IMAGEMAGICK_LIBS = @IMAGEMAGICK_LIBS@ |
| 159 | INCLUDE_NEXT = @INCLUDE_NEXT@ | ||
| 160 | INCLUDE_NEXT_AS_FIRST_DIRECTIVE = @INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ | ||
| 143 | INSTALL = @INSTALL@ | 161 | INSTALL = @INSTALL@ |
| 144 | INSTALL_DATA = @INSTALL_DATA@ | 162 | INSTALL_DATA = @INSTALL_DATA@ |
| 145 | INSTALL_INFO = @INSTALL_INFO@ | 163 | INSTALL_INFO = @INSTALL_INFO@ |
| @@ -198,6 +216,10 @@ MKDIR_P = @MKDIR_P@ | |||
| 198 | MOUSE_SUPPORT = @MOUSE_SUPPORT@ | 216 | MOUSE_SUPPORT = @MOUSE_SUPPORT@ |
| 199 | M_FILE = @M_FILE@ | 217 | M_FILE = @M_FILE@ |
| 200 | NEED_SETGID = @NEED_SETGID@ | 218 | NEED_SETGID = @NEED_SETGID@ |
| 219 | NEXT_AS_FIRST_DIRECTIVE_STDDEF_H = @NEXT_AS_FIRST_DIRECTIVE_STDDEF_H@ | ||
| 220 | NEXT_AS_FIRST_DIRECTIVE_TIME_H = @NEXT_AS_FIRST_DIRECTIVE_TIME_H@ | ||
| 221 | NEXT_STDDEF_H = @NEXT_STDDEF_H@ | ||
| 222 | NEXT_TIME_H = @NEXT_TIME_H@ | ||
| 201 | NS_OBJ = @NS_OBJ@ | 223 | NS_OBJ = @NS_OBJ@ |
| 202 | NS_SUPPORT = @NS_SUPPORT@ | 224 | NS_SUPPORT = @NS_SUPPORT@ |
| 203 | OBJEXT = @OBJEXT@ | 225 | OBJEXT = @OBJEXT@ |
| @@ -215,19 +237,30 @@ PACKAGE_VERSION = @PACKAGE_VERSION@ | |||
| 215 | PATH_SEPARATOR = @PATH_SEPARATOR@ | 237 | PATH_SEPARATOR = @PATH_SEPARATOR@ |
| 216 | PKG_CONFIG = @PKG_CONFIG@ | 238 | PKG_CONFIG = @PKG_CONFIG@ |
| 217 | POST_ALLOC_OBJ = @POST_ALLOC_OBJ@ | 239 | POST_ALLOC_OBJ = @POST_ALLOC_OBJ@ |
| 240 | PRAGMA_COLUMNS = @PRAGMA_COLUMNS@ | ||
| 241 | PRAGMA_SYSTEM_HEADER = @PRAGMA_SYSTEM_HEADER@ | ||
| 218 | PRE_ALLOC_OBJ = @PRE_ALLOC_OBJ@ | 242 | PRE_ALLOC_OBJ = @PRE_ALLOC_OBJ@ |
| 219 | PROFILING_CFLAGS = @PROFILING_CFLAGS@ | 243 | PROFILING_CFLAGS = @PROFILING_CFLAGS@ |
| 244 | PTHREAD_H_DEFINES_STRUCT_TIMESPEC = @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@ | ||
| 220 | RALLOC_OBJ = @RALLOC_OBJ@ | 245 | RALLOC_OBJ = @RALLOC_OBJ@ |
| 221 | RANLIB = @RANLIB@ | 246 | RANLIB = @RANLIB@ |
| 247 | REPLACE_LOCALTIME_R = @REPLACE_LOCALTIME_R@ | ||
| 248 | REPLACE_MKTIME = @REPLACE_MKTIME@ | ||
| 249 | REPLACE_NANOSLEEP = @REPLACE_NANOSLEEP@ | ||
| 250 | REPLACE_NULL = @REPLACE_NULL@ | ||
| 251 | REPLACE_TIMEGM = @REPLACE_TIMEGM@ | ||
| 222 | RSVG_CFLAGS = @RSVG_CFLAGS@ | 252 | RSVG_CFLAGS = @RSVG_CFLAGS@ |
| 223 | RSVG_LIBS = @RSVG_LIBS@ | 253 | RSVG_LIBS = @RSVG_LIBS@ |
| 224 | SET_MAKE = @SET_MAKE@ | 254 | SET_MAKE = @SET_MAKE@ |
| 225 | SHELL = @SHELL@ | 255 | SHELL = @SHELL@ |
| 226 | START_FILES = @START_FILES@ | 256 | START_FILES = @START_FILES@ |
| 257 | STDDEF_H = @STDDEF_H@ | ||
| 227 | STRIP = @STRIP@ | 258 | STRIP = @STRIP@ |
| 259 | SYS_TIME_H_DEFINES_STRUCT_TIMESPEC = @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@ | ||
| 228 | S_FILE = @S_FILE@ | 260 | S_FILE = @S_FILE@ |
| 229 | TEMACS_LDFLAGS2 = @TEMACS_LDFLAGS2@ | 261 | TEMACS_LDFLAGS2 = @TEMACS_LDFLAGS2@ |
| 230 | TERMCAP_OBJ = @TERMCAP_OBJ@ | 262 | TERMCAP_OBJ = @TERMCAP_OBJ@ |
| 263 | TIME_H_DEFINES_STRUCT_TIMESPEC = @TIME_H_DEFINES_STRUCT_TIMESPEC@ | ||
| 231 | TOOLKIT_LIBW = @TOOLKIT_LIBW@ | 264 | TOOLKIT_LIBW = @TOOLKIT_LIBW@ |
| 232 | TOOLTIP_SUPPORT = @TOOLTIP_SUPPORT@ | 265 | TOOLTIP_SUPPORT = @TOOLTIP_SUPPORT@ |
| 233 | UNEXEC_OBJ = @UNEXEC_OBJ@ | 266 | UNEXEC_OBJ = @UNEXEC_OBJ@ |
| @@ -313,15 +346,33 @@ top_builddir = @top_builddir@ | |||
| 313 | top_srcdir = @top_srcdir@ | 346 | top_srcdir = @top_srcdir@ |
| 314 | version = @version@ | 347 | version = @version@ |
| 315 | x_default_search_path = @x_default_search_path@ | 348 | x_default_search_path = @x_default_search_path@ |
| 316 | BUILT_SOURCES = | 349 | |
| 317 | EXTRA_DIST = intprops.h | 350 | # The BUILT_SOURCES created by this Makefile snippet are not used via #include |
| 318 | MOSTLYCLEANFILES = core *.stackdump | 351 | # statements but through direct file reference. Therefore this snippet must be |
| 352 | # present in all Makefile.am that need it. This is ensured by the applicability | ||
| 353 | # 'all' defined above. | ||
| 354 | |||
| 355 | # The BUILT_SOURCES created by this Makefile snippet are not used via #include | ||
| 356 | # statements but through direct file reference. Therefore this snippet must be | ||
| 357 | # present in all Makefile.am that need it. This is ensured by the applicability | ||
| 358 | # 'all' defined above. | ||
| 359 | BUILT_SOURCES = arg-nonnull.h c++defs.h $(STDDEF_H) time.h \ | ||
| 360 | warn-on-use.h | ||
| 361 | EXTRA_DIST = $(top_srcdir)/./arg-nonnull.h $(top_srcdir)/./c++defs.h \ | ||
| 362 | intprops.h mktime-internal.h mktime.c stddef.in.h time.in.h \ | ||
| 363 | time_r.c $(top_srcdir)/./warn-on-use.h | ||
| 364 | MOSTLYCLEANFILES = core *.stackdump arg-nonnull.h arg-nonnull.h-t \ | ||
| 365 | c++defs.h c++defs.h-t stddef.h stddef.h-t time.h time.h-t \ | ||
| 366 | warn-on-use.h warn-on-use.h-t | ||
| 319 | noinst_LIBRARIES = libgnu.a | 367 | noinst_LIBRARIES = libgnu.a |
| 320 | DEFAULT_INCLUDES = -I. -I../src -I$(top_srcdir)/src | 368 | DEFAULT_INCLUDES = -I. -I../src -I$(top_srcdir)/src |
| 321 | libgnu_a_SOURCES = ftoastr.h ftoastr.c dtoastr.c ldtoastr.c | 369 | libgnu_a_SOURCES = ftoastr.h ftoastr.c dtoastr.c ldtoastr.c |
| 322 | libgnu_a_LIBADD = $(gl_LIBOBJS) | 370 | libgnu_a_LIBADD = $(gl_LIBOBJS) |
| 323 | libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) | 371 | libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) |
| 324 | EXTRA_libgnu_a_SOURCES = | 372 | EXTRA_libgnu_a_SOURCES = mktime.c time_r.c |
| 373 | ARG_NONNULL_H = arg-nonnull.h | ||
| 374 | CXXDEFS_H = c++defs.h | ||
| 375 | WARN_ON_USE_H = warn-on-use.h | ||
| 325 | all: $(BUILT_SOURCES) | 376 | all: $(BUILT_SOURCES) |
| 326 | $(MAKE) $(AM_MAKEFLAGS) all-am | 377 | $(MAKE) $(AM_MAKEFLAGS) all-am |
| 327 | 378 | ||
| @@ -374,6 +425,8 @@ distclean-compile: | |||
| 374 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dtoastr.Po@am__quote@ | 425 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dtoastr.Po@am__quote@ |
| 375 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ftoastr.Po@am__quote@ | 426 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ftoastr.Po@am__quote@ |
| 376 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldtoastr.Po@am__quote@ | 427 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldtoastr.Po@am__quote@ |
| 428 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mktime.Po@am__quote@ | ||
| 429 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time_r.Po@am__quote@ | ||
| 377 | 430 | ||
| 378 | .c.o: | 431 | .c.o: |
| 379 | @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< | 432 | @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< |
| @@ -589,6 +642,77 @@ uninstall-am: | |||
| 589 | mostlyclean-generic mostlyclean-local pdf pdf-am ps ps-am tags \ | 642 | mostlyclean-generic mostlyclean-local pdf pdf-am ps ps-am tags \ |
| 590 | uninstall uninstall-am | 643 | uninstall uninstall-am |
| 591 | 644 | ||
| 645 | # The arg-nonnull.h that gets inserted into generated .h files is the same as | ||
| 646 | # build-aux/arg-nonnull.h, except that it has the copyright header cut off. | ||
| 647 | arg-nonnull.h: $(top_srcdir)/./arg-nonnull.h | ||
| 648 | $(AM_V_GEN)rm -f $@-t $@ && \ | ||
| 649 | sed -n -e '/GL_ARG_NONNULL/,$$p' \ | ||
| 650 | < $(top_srcdir)/./arg-nonnull.h \ | ||
| 651 | > $@-t && \ | ||
| 652 | mv $@-t $@ | ||
| 653 | # The c++defs.h that gets inserted into generated .h files is the same as | ||
| 654 | # build-aux/c++defs.h, except that it has the copyright header cut off. | ||
| 655 | c++defs.h: $(top_srcdir)/./c++defs.h | ||
| 656 | $(AM_V_GEN)rm -f $@-t $@ && \ | ||
| 657 | sed -n -e '/_GL_CXXDEFS/,$$p' \ | ||
| 658 | < $(top_srcdir)/./c++defs.h \ | ||
| 659 | > $@-t && \ | ||
| 660 | mv $@-t $@ | ||
| 661 | |||
| 662 | # We need the following in order to create <stddef.h> when the system | ||
| 663 | # doesn't have one that works with the given compiler. | ||
| 664 | stddef.h: stddef.in.h | ||
| 665 | $(AM_V_GEN)rm -f $@-t $@ && \ | ||
| 666 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ | ||
| 667 | sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ | ||
| 668 | -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ | ||
| 669 | -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ | ||
| 670 | -e 's|@''NEXT_STDDEF_H''@|$(NEXT_STDDEF_H)|g' \ | ||
| 671 | -e 's|@''HAVE_WCHAR_T''@|$(HAVE_WCHAR_T)|g' \ | ||
| 672 | -e 's|@''REPLACE_NULL''@|$(REPLACE_NULL)|g' \ | ||
| 673 | < $(srcdir)/stddef.in.h; \ | ||
| 674 | } > $@-t && \ | ||
| 675 | mv $@-t $@ | ||
| 676 | |||
| 677 | # We need the following in order to create <time.h> when the system | ||
| 678 | # doesn't have one that works with the given compiler. | ||
| 679 | time.h: time.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) | ||
| 680 | $(AM_V_GEN)rm -f $@-t $@ && \ | ||
| 681 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ | ||
| 682 | sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ | ||
| 683 | -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ | ||
| 684 | -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ | ||
| 685 | -e 's|@''NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \ | ||
| 686 | -e 's|@''GNULIB_MKTIME''@|$(GNULIB_MKTIME)|g' \ | ||
| 687 | -e 's|@''GNULIB_NANOSLEEP''@|$(GNULIB_NANOSLEEP)|g' \ | ||
| 688 | -e 's|@''GNULIB_STRPTIME''@|$(GNULIB_STRPTIME)|g' \ | ||
| 689 | -e 's|@''GNULIB_TIMEGM''@|$(GNULIB_TIMEGM)|g' \ | ||
| 690 | -e 's|@''GNULIB_TIME_R''@|$(GNULIB_TIME_R)|g' \ | ||
| 691 | -e 's|@''HAVE_DECL_LOCALTIME_R''@|$(HAVE_DECL_LOCALTIME_R)|g' \ | ||
| 692 | -e 's|@''HAVE_NANOSLEEP''@|$(HAVE_NANOSLEEP)|g' \ | ||
| 693 | -e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \ | ||
| 694 | -e 's|@''HAVE_TIMEGM''@|$(HAVE_TIMEGM)|g' \ | ||
| 695 | -e 's|@''REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \ | ||
| 696 | -e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \ | ||
| 697 | -e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \ | ||
| 698 | -e 's|@''REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \ | ||
| 699 | -e 's|@''PTHREAD_H_DEFINES_STRUCT_TIMESPEC''@|$(PTHREAD_H_DEFINES_STRUCT_TIMESPEC)|g' \ | ||
| 700 | -e 's|@''SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ | ||
| 701 | -e 's|@''TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ | ||
| 702 | -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ | ||
| 703 | -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ | ||
| 704 | -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ | ||
| 705 | < $(srcdir)/time.in.h; \ | ||
| 706 | } > $@-t && \ | ||
| 707 | mv $@-t $@ | ||
| 708 | # The warn-on-use.h that gets inserted into generated .h files is the same as | ||
| 709 | # build-aux/warn-on-use.h, except that it has the copyright header cut off. | ||
| 710 | warn-on-use.h: $(top_srcdir)/./warn-on-use.h | ||
| 711 | $(AM_V_GEN)rm -f $@-t $@ && \ | ||
| 712 | sed -n -e '/^.ifndef/,$$p' \ | ||
| 713 | < $(top_srcdir)/./warn-on-use.h \ | ||
| 714 | > $@-t && \ | ||
| 715 | mv $@-t $@ | ||
| 592 | 716 | ||
| 593 | mostlyclean-local: mostlyclean-generic | 717 | mostlyclean-local: mostlyclean-generic |
| 594 | @for dir in '' $(MOSTLYCLEANDIRS); do \ | 718 | @for dir in '' $(MOSTLYCLEANDIRS); do \ |
diff --git a/lib/gnulib.mk b/lib/gnulib.mk index 78d89d99281..a091e399be1 100644 --- a/lib/gnulib.mk +++ b/lib/gnulib.mk | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | # the same distribution terms as the rest of that program. | 9 | # the same distribution terms as the rest of that program. |
| 10 | # | 10 | # |
| 11 | # Generated by gnulib-tool. | 11 | # Generated by gnulib-tool. |
| 12 | # Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --no-libtool --macro-prefix=gl --no-vc-files ftoastr | 12 | # Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --no-libtool --macro-prefix=gl --no-vc-files ftoastr mktime |
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | MOSTLYCLEANFILES += core *.stackdump | 15 | MOSTLYCLEANFILES += core *.stackdump |
| @@ -21,6 +21,54 @@ libgnu_a_LIBADD = $(gl_LIBOBJS) | |||
| 21 | libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) | 21 | libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) |
| 22 | EXTRA_libgnu_a_SOURCES = | 22 | EXTRA_libgnu_a_SOURCES = |
| 23 | 23 | ||
| 24 | ## begin gnulib module arg-nonnull | ||
| 25 | |||
| 26 | # The BUILT_SOURCES created by this Makefile snippet are not used via #include | ||
| 27 | # statements but through direct file reference. Therefore this snippet must be | ||
| 28 | # present in all Makefile.am that need it. This is ensured by the applicability | ||
| 29 | # 'all' defined above. | ||
| 30 | |||
| 31 | BUILT_SOURCES += arg-nonnull.h | ||
| 32 | # The arg-nonnull.h that gets inserted into generated .h files is the same as | ||
| 33 | # build-aux/arg-nonnull.h, except that it has the copyright header cut off. | ||
| 34 | arg-nonnull.h: $(top_srcdir)/./arg-nonnull.h | ||
| 35 | $(AM_V_GEN)rm -f $@-t $@ && \ | ||
| 36 | sed -n -e '/GL_ARG_NONNULL/,$$p' \ | ||
| 37 | < $(top_srcdir)/./arg-nonnull.h \ | ||
| 38 | > $@-t && \ | ||
| 39 | mv $@-t $@ | ||
| 40 | MOSTLYCLEANFILES += arg-nonnull.h arg-nonnull.h-t | ||
| 41 | |||
| 42 | ARG_NONNULL_H=arg-nonnull.h | ||
| 43 | |||
| 44 | EXTRA_DIST += $(top_srcdir)/./arg-nonnull.h | ||
| 45 | |||
| 46 | ## end gnulib module arg-nonnull | ||
| 47 | |||
| 48 | ## begin gnulib module c++defs | ||
| 49 | |||
| 50 | # The BUILT_SOURCES created by this Makefile snippet are not used via #include | ||
| 51 | # statements but through direct file reference. Therefore this snippet must be | ||
| 52 | # present in all Makefile.am that need it. This is ensured by the applicability | ||
| 53 | # 'all' defined above. | ||
| 54 | |||
| 55 | BUILT_SOURCES += c++defs.h | ||
| 56 | # The c++defs.h that gets inserted into generated .h files is the same as | ||
| 57 | # build-aux/c++defs.h, except that it has the copyright header cut off. | ||
| 58 | c++defs.h: $(top_srcdir)/./c++defs.h | ||
| 59 | $(AM_V_GEN)rm -f $@-t $@ && \ | ||
| 60 | sed -n -e '/_GL_CXXDEFS/,$$p' \ | ||
| 61 | < $(top_srcdir)/./c++defs.h \ | ||
| 62 | > $@-t && \ | ||
| 63 | mv $@-t $@ | ||
| 64 | MOSTLYCLEANFILES += c++defs.h c++defs.h-t | ||
| 65 | |||
| 66 | CXXDEFS_H=c++defs.h | ||
| 67 | |||
| 68 | EXTRA_DIST += $(top_srcdir)/./c++defs.h | ||
| 69 | |||
| 70 | ## end gnulib module c++defs | ||
| 71 | |||
| 24 | ## begin gnulib module ftoastr | 72 | ## begin gnulib module ftoastr |
| 25 | 73 | ||
| 26 | libgnu_a_SOURCES += ftoastr.h ftoastr.c dtoastr.c ldtoastr.c | 74 | libgnu_a_SOURCES += ftoastr.h ftoastr.c dtoastr.c ldtoastr.c |
| @@ -34,6 +82,108 @@ EXTRA_DIST += intprops.h | |||
| 34 | 82 | ||
| 35 | ## end gnulib module intprops | 83 | ## end gnulib module intprops |
| 36 | 84 | ||
| 85 | ## begin gnulib module mktime | ||
| 86 | |||
| 87 | |||
| 88 | EXTRA_DIST += mktime-internal.h mktime.c | ||
| 89 | |||
| 90 | EXTRA_libgnu_a_SOURCES += mktime.c | ||
| 91 | |||
| 92 | ## end gnulib module mktime | ||
| 93 | |||
| 94 | ## begin gnulib module stddef | ||
| 95 | |||
| 96 | BUILT_SOURCES += $(STDDEF_H) | ||
| 97 | |||
| 98 | # We need the following in order to create <stddef.h> when the system | ||
| 99 | # doesn't have one that works with the given compiler. | ||
| 100 | stddef.h: stddef.in.h | ||
| 101 | $(AM_V_GEN)rm -f $@-t $@ && \ | ||
| 102 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ | ||
| 103 | sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ | ||
| 104 | -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ | ||
| 105 | -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ | ||
| 106 | -e 's|@''NEXT_STDDEF_H''@|$(NEXT_STDDEF_H)|g' \ | ||
| 107 | -e 's|@''HAVE_WCHAR_T''@|$(HAVE_WCHAR_T)|g' \ | ||
| 108 | -e 's|@''REPLACE_NULL''@|$(REPLACE_NULL)|g' \ | ||
| 109 | < $(srcdir)/stddef.in.h; \ | ||
| 110 | } > $@-t && \ | ||
| 111 | mv $@-t $@ | ||
| 112 | MOSTLYCLEANFILES += stddef.h stddef.h-t | ||
| 113 | |||
| 114 | EXTRA_DIST += stddef.in.h | ||
| 115 | |||
| 116 | ## end gnulib module stddef | ||
| 117 | |||
| 118 | ## begin gnulib module time | ||
| 119 | |||
| 120 | BUILT_SOURCES += time.h | ||
| 121 | |||
| 122 | # We need the following in order to create <time.h> when the system | ||
| 123 | # doesn't have one that works with the given compiler. | ||
| 124 | time.h: time.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) | ||
| 125 | $(AM_V_GEN)rm -f $@-t $@ && \ | ||
| 126 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ | ||
| 127 | sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ | ||
| 128 | -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ | ||
| 129 | -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ | ||
| 130 | -e 's|@''NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \ | ||
| 131 | -e 's|@''GNULIB_MKTIME''@|$(GNULIB_MKTIME)|g' \ | ||
| 132 | -e 's|@''GNULIB_NANOSLEEP''@|$(GNULIB_NANOSLEEP)|g' \ | ||
| 133 | -e 's|@''GNULIB_STRPTIME''@|$(GNULIB_STRPTIME)|g' \ | ||
| 134 | -e 's|@''GNULIB_TIMEGM''@|$(GNULIB_TIMEGM)|g' \ | ||
| 135 | -e 's|@''GNULIB_TIME_R''@|$(GNULIB_TIME_R)|g' \ | ||
| 136 | -e 's|@''HAVE_DECL_LOCALTIME_R''@|$(HAVE_DECL_LOCALTIME_R)|g' \ | ||
| 137 | -e 's|@''HAVE_NANOSLEEP''@|$(HAVE_NANOSLEEP)|g' \ | ||
| 138 | -e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \ | ||
| 139 | -e 's|@''HAVE_TIMEGM''@|$(HAVE_TIMEGM)|g' \ | ||
| 140 | -e 's|@''REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \ | ||
| 141 | -e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \ | ||
| 142 | -e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \ | ||
| 143 | -e 's|@''REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \ | ||
| 144 | -e 's|@''PTHREAD_H_DEFINES_STRUCT_TIMESPEC''@|$(PTHREAD_H_DEFINES_STRUCT_TIMESPEC)|g' \ | ||
| 145 | -e 's|@''SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ | ||
| 146 | -e 's|@''TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ | ||
| 147 | -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ | ||
| 148 | -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ | ||
| 149 | -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ | ||
| 150 | < $(srcdir)/time.in.h; \ | ||
| 151 | } > $@-t && \ | ||
| 152 | mv $@-t $@ | ||
| 153 | MOSTLYCLEANFILES += time.h time.h-t | ||
| 154 | |||
| 155 | EXTRA_DIST += time.in.h | ||
| 156 | |||
| 157 | ## end gnulib module time | ||
| 158 | |||
| 159 | ## begin gnulib module time_r | ||
| 160 | |||
| 161 | |||
| 162 | EXTRA_DIST += time_r.c | ||
| 163 | |||
| 164 | EXTRA_libgnu_a_SOURCES += time_r.c | ||
| 165 | |||
| 166 | ## end gnulib module time_r | ||
| 167 | |||
| 168 | ## begin gnulib module warn-on-use | ||
| 169 | |||
| 170 | BUILT_SOURCES += warn-on-use.h | ||
| 171 | # The warn-on-use.h that gets inserted into generated .h files is the same as | ||
| 172 | # build-aux/warn-on-use.h, except that it has the copyright header cut off. | ||
| 173 | warn-on-use.h: $(top_srcdir)/./warn-on-use.h | ||
| 174 | $(AM_V_GEN)rm -f $@-t $@ && \ | ||
| 175 | sed -n -e '/^.ifndef/,$$p' \ | ||
| 176 | < $(top_srcdir)/./warn-on-use.h \ | ||
| 177 | > $@-t && \ | ||
| 178 | mv $@-t $@ | ||
| 179 | MOSTLYCLEANFILES += warn-on-use.h warn-on-use.h-t | ||
| 180 | |||
| 181 | WARN_ON_USE_H=warn-on-use.h | ||
| 182 | |||
| 183 | EXTRA_DIST += $(top_srcdir)/./warn-on-use.h | ||
| 184 | |||
| 185 | ## end gnulib module warn-on-use | ||
| 186 | |||
| 37 | 187 | ||
| 38 | mostlyclean-local: mostlyclean-generic | 188 | mostlyclean-local: mostlyclean-generic |
| 39 | @for dir in '' $(MOSTLYCLEANDIRS); do \ | 189 | @for dir in '' $(MOSTLYCLEANDIRS); do \ |
diff --git a/lib/mktime-internal.h b/lib/mktime-internal.h new file mode 100644 index 00000000000..4287acf4aca --- /dev/null +++ b/lib/mktime-internal.h | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | #include <time.h> | ||
| 2 | time_t mktime_internal (struct tm *, | ||
| 3 | struct tm * (*) (time_t const *, struct tm *), | ||
| 4 | time_t *); | ||
diff --git a/lib/mktime.c b/lib/mktime.c new file mode 100644 index 00000000000..f77330564fc --- /dev/null +++ b/lib/mktime.c | |||
| @@ -0,0 +1,669 @@ | |||
| 1 | /* Convert a `struct tm' to a time_t value. | ||
| 2 | Copyright (C) 1993-1999, 2002-2007, 2009-2011 Free Software Foundation, Inc. | ||
| 3 | This file is part of the GNU C Library. | ||
| 4 | Contributed by Paul Eggert <eggert@twinsun.com>. | ||
| 5 | |||
| 6 | This program is free software; you can redistribute it and/or modify | ||
| 7 | it under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation; either version 3, or (at your option) | ||
| 9 | any later version. | ||
| 10 | |||
| 11 | This program is distributed in the hope that it will be useful, | ||
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License along | ||
| 17 | with this program; if not, write to the Free Software Foundation, | ||
| 18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
| 19 | |||
| 20 | /* Define this to have a standalone program to test this implementation of | ||
| 21 | mktime. */ | ||
| 22 | /* #define DEBUG 1 */ | ||
| 23 | |||
| 24 | #ifndef _LIBC | ||
| 25 | # include <config.h> | ||
| 26 | #endif | ||
| 27 | |||
| 28 | /* Assume that leap seconds are possible, unless told otherwise. | ||
| 29 | If the host has a `zic' command with a `-L leapsecondfilename' option, | ||
| 30 | then it supports leap seconds; otherwise it probably doesn't. */ | ||
| 31 | #ifndef LEAP_SECONDS_POSSIBLE | ||
| 32 | # define LEAP_SECONDS_POSSIBLE 1 | ||
| 33 | #endif | ||
| 34 | |||
| 35 | #include <time.h> | ||
| 36 | |||
| 37 | #include <limits.h> | ||
| 38 | |||
| 39 | #include <string.h> /* For the real memcpy prototype. */ | ||
| 40 | |||
| 41 | #if DEBUG | ||
| 42 | # include <stdio.h> | ||
| 43 | # include <stdlib.h> | ||
| 44 | /* Make it work even if the system's libc has its own mktime routine. */ | ||
| 45 | # define mktime my_mktime | ||
| 46 | #endif /* DEBUG */ | ||
| 47 | |||
| 48 | /* Shift A right by B bits portably, by dividing A by 2**B and | ||
| 49 | truncating towards minus infinity. A and B should be free of side | ||
| 50 | effects, and B should be in the range 0 <= B <= INT_BITS - 2, where | ||
| 51 | INT_BITS is the number of useful bits in an int. GNU code can | ||
| 52 | assume that INT_BITS is at least 32. | ||
| 53 | |||
| 54 | ISO C99 says that A >> B is implementation-defined if A < 0. Some | ||
| 55 | implementations (e.g., UNICOS 9.0 on a Cray Y-MP EL) don't shift | ||
| 56 | right in the usual way when A < 0, so SHR falls back on division if | ||
| 57 | ordinary A >> B doesn't seem to be the usual signed shift. */ | ||
| 58 | #define SHR(a, b) \ | ||
| 59 | (-1 >> 1 == -1 \ | ||
| 60 | ? (a) >> (b) \ | ||
| 61 | : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0)) | ||
| 62 | |||
| 63 | /* The extra casts in the following macros work around compiler bugs, | ||
| 64 | e.g., in Cray C 5.0.3.0. */ | ||
| 65 | |||
| 66 | /* True if the arithmetic type T is an integer type. bool counts as | ||
| 67 | an integer. */ | ||
| 68 | #define TYPE_IS_INTEGER(t) ((t) 1.5 == 1) | ||
| 69 | |||
| 70 | /* True if negative values of the signed integer type T use two's | ||
| 71 | complement, ones' complement, or signed magnitude representation, | ||
| 72 | respectively. Much GNU code assumes two's complement, but some | ||
| 73 | people like to be portable to all possible C hosts. */ | ||
| 74 | #define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1) | ||
| 75 | #define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0) | ||
| 76 | #define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1) | ||
| 77 | |||
| 78 | /* True if the arithmetic type T is signed. */ | ||
| 79 | #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) | ||
| 80 | |||
| 81 | /* The maximum and minimum values for the integer type T. These | ||
| 82 | macros have undefined behavior if T is signed and has padding bits. | ||
| 83 | If this is a problem for you, please let us know how to fix it for | ||
| 84 | your host. */ | ||
| 85 | #define TYPE_MINIMUM(t) \ | ||
| 86 | ((t) (! TYPE_SIGNED (t) \ | ||
| 87 | ? (t) 0 \ | ||
| 88 | : TYPE_SIGNED_MAGNITUDE (t) \ | ||
| 89 | ? ~ (t) 0 \ | ||
| 90 | : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))) | ||
| 91 | #define TYPE_MAXIMUM(t) \ | ||
| 92 | ((t) (! TYPE_SIGNED (t) \ | ||
| 93 | ? (t) -1 \ | ||
| 94 | : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) | ||
| 95 | |||
| 96 | #ifndef TIME_T_MIN | ||
| 97 | # define TIME_T_MIN TYPE_MINIMUM (time_t) | ||
| 98 | #endif | ||
| 99 | #ifndef TIME_T_MAX | ||
| 100 | # define TIME_T_MAX TYPE_MAXIMUM (time_t) | ||
| 101 | #endif | ||
| 102 | #define TIME_T_MIDPOINT (SHR (TIME_T_MIN + TIME_T_MAX, 1) + 1) | ||
| 103 | |||
| 104 | /* Verify a requirement at compile-time (unlike assert, which is runtime). */ | ||
| 105 | #define verify(name, assertion) struct name { char a[(assertion) ? 1 : -1]; } | ||
| 106 | |||
| 107 | verify (time_t_is_integer, TYPE_IS_INTEGER (time_t)); | ||
| 108 | verify (twos_complement_arithmetic, TYPE_TWOS_COMPLEMENT (int)); | ||
| 109 | /* The code also assumes that signed integer overflow silently wraps | ||
| 110 | around, but this assumption can't be stated without causing a | ||
| 111 | diagnostic on some hosts. */ | ||
| 112 | |||
| 113 | #define EPOCH_YEAR 1970 | ||
| 114 | #define TM_YEAR_BASE 1900 | ||
| 115 | verify (base_year_is_a_multiple_of_100, TM_YEAR_BASE % 100 == 0); | ||
| 116 | |||
| 117 | /* Return 1 if YEAR + TM_YEAR_BASE is a leap year. */ | ||
| 118 | static inline int | ||
| 119 | leapyear (long int year) | ||
| 120 | { | ||
| 121 | /* Don't add YEAR to TM_YEAR_BASE, as that might overflow. | ||
| 122 | Also, work even if YEAR is negative. */ | ||
| 123 | return | ||
| 124 | ((year & 3) == 0 | ||
| 125 | && (year % 100 != 0 | ||
| 126 | || ((year / 100) & 3) == (- (TM_YEAR_BASE / 100) & 3))); | ||
| 127 | } | ||
| 128 | |||
| 129 | /* How many days come before each month (0-12). */ | ||
| 130 | #ifndef _LIBC | ||
| 131 | static | ||
| 132 | #endif | ||
| 133 | const unsigned short int __mon_yday[2][13] = | ||
| 134 | { | ||
| 135 | /* Normal years. */ | ||
| 136 | { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, | ||
| 137 | /* Leap years. */ | ||
| 138 | { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } | ||
| 139 | }; | ||
| 140 | |||
| 141 | |||
| 142 | #ifndef _LIBC | ||
| 143 | /* Portable standalone applications should supply a <time.h> that | ||
| 144 | declares a POSIX-compliant localtime_r, for the benefit of older | ||
| 145 | implementations that lack localtime_r or have a nonstandard one. | ||
| 146 | See the gnulib time_r module for one way to implement this. */ | ||
| 147 | # undef __localtime_r | ||
| 148 | # define __localtime_r localtime_r | ||
| 149 | # define __mktime_internal mktime_internal | ||
| 150 | # include "mktime-internal.h" | ||
| 151 | #endif | ||
| 152 | |||
| 153 | /* Return an integer value measuring (YEAR1-YDAY1 HOUR1:MIN1:SEC1) - | ||
| 154 | (YEAR0-YDAY0 HOUR0:MIN0:SEC0) in seconds, assuming that the clocks | ||
| 155 | were not adjusted between the time stamps. | ||
| 156 | |||
| 157 | The YEAR values uses the same numbering as TP->tm_year. Values | ||
| 158 | need not be in the usual range. However, YEAR1 must not be less | ||
| 159 | than 2 * INT_MIN or greater than 2 * INT_MAX. | ||
| 160 | |||
| 161 | The result may overflow. It is the caller's responsibility to | ||
| 162 | detect overflow. */ | ||
| 163 | |||
| 164 | static inline time_t | ||
| 165 | ydhms_diff (long int year1, long int yday1, int hour1, int min1, int sec1, | ||
| 166 | int year0, int yday0, int hour0, int min0, int sec0) | ||
| 167 | { | ||
| 168 | verify (C99_integer_division, -1 / 2 == 0); | ||
| 169 | #if 0 /* This assertion fails on 32-bit systems with 64-bit time_t, such as | ||
| 170 | NetBSD 5 on i386. */ | ||
| 171 | verify (long_int_year_and_yday_are_wide_enough, | ||
| 172 | INT_MAX <= LONG_MAX / 2 || TIME_T_MAX <= UINT_MAX); | ||
| 173 | #endif | ||
| 174 | |||
| 175 | /* Compute intervening leap days correctly even if year is negative. | ||
| 176 | Take care to avoid integer overflow here. */ | ||
| 177 | int a4 = SHR (year1, 2) + SHR (TM_YEAR_BASE, 2) - ! (year1 & 3); | ||
| 178 | int b4 = SHR (year0, 2) + SHR (TM_YEAR_BASE, 2) - ! (year0 & 3); | ||
| 179 | int a100 = a4 / 25 - (a4 % 25 < 0); | ||
| 180 | int b100 = b4 / 25 - (b4 % 25 < 0); | ||
| 181 | int a400 = SHR (a100, 2); | ||
| 182 | int b400 = SHR (b100, 2); | ||
| 183 | int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400); | ||
| 184 | |||
| 185 | /* Compute the desired time in time_t precision. Overflow might | ||
| 186 | occur here. */ | ||
| 187 | time_t tyear1 = year1; | ||
| 188 | time_t years = tyear1 - year0; | ||
| 189 | time_t days = 365 * years + yday1 - yday0 + intervening_leap_days; | ||
| 190 | time_t hours = 24 * days + hour1 - hour0; | ||
| 191 | time_t minutes = 60 * hours + min1 - min0; | ||
| 192 | time_t seconds = 60 * minutes + sec1 - sec0; | ||
| 193 | return seconds; | ||
| 194 | } | ||
| 195 | |||
| 196 | |||
| 197 | /* Return a time_t value corresponding to (YEAR-YDAY HOUR:MIN:SEC), | ||
| 198 | assuming that *T corresponds to *TP and that no clock adjustments | ||
| 199 | occurred between *TP and the desired time. | ||
| 200 | If TP is null, return a value not equal to *T; this avoids false matches. | ||
| 201 | If overflow occurs, yield the minimal or maximal value, except do not | ||
| 202 | yield a value equal to *T. */ | ||
| 203 | static time_t | ||
| 204 | guess_time_tm (long int year, long int yday, int hour, int min, int sec, | ||
| 205 | const time_t *t, const struct tm *tp) | ||
| 206 | { | ||
| 207 | if (tp) | ||
| 208 | { | ||
| 209 | time_t d = ydhms_diff (year, yday, hour, min, sec, | ||
| 210 | tp->tm_year, tp->tm_yday, | ||
| 211 | tp->tm_hour, tp->tm_min, tp->tm_sec); | ||
| 212 | time_t t1 = *t + d; | ||
| 213 | if ((t1 < *t) == (TYPE_SIGNED (time_t) ? d < 0 : TIME_T_MAX / 2 < d)) | ||
| 214 | return t1; | ||
| 215 | } | ||
| 216 | |||
| 217 | /* Overflow occurred one way or another. Return the nearest result | ||
| 218 | that is actually in range, except don't report a zero difference | ||
| 219 | if the actual difference is nonzero, as that would cause a false | ||
| 220 | match; and don't oscillate between two values, as that would | ||
| 221 | confuse the spring-forward gap detector. */ | ||
| 222 | return (*t < TIME_T_MIDPOINT | ||
| 223 | ? (*t <= TIME_T_MIN + 1 ? *t + 1 : TIME_T_MIN) | ||
| 224 | : (TIME_T_MAX - 1 <= *t ? *t - 1 : TIME_T_MAX)); | ||
| 225 | } | ||
| 226 | |||
| 227 | /* Use CONVERT to convert *T to a broken down time in *TP. | ||
| 228 | If *T is out of range for conversion, adjust it so that | ||
| 229 | it is the nearest in-range value and then convert that. */ | ||
| 230 | static struct tm * | ||
| 231 | ranged_convert (struct tm *(*convert) (const time_t *, struct tm *), | ||
| 232 | time_t *t, struct tm *tp) | ||
| 233 | { | ||
| 234 | struct tm *r = convert (t, tp); | ||
| 235 | |||
| 236 | if (!r && *t) | ||
| 237 | { | ||
| 238 | time_t bad = *t; | ||
| 239 | time_t ok = 0; | ||
| 240 | |||
| 241 | /* BAD is a known unconvertible time_t, and OK is a known good one. | ||
| 242 | Use binary search to narrow the range between BAD and OK until | ||
| 243 | they differ by 1. */ | ||
| 244 | while (bad != ok + (bad < 0 ? -1 : 1)) | ||
| 245 | { | ||
| 246 | time_t mid = *t = (bad < 0 | ||
| 247 | ? bad + ((ok - bad) >> 1) | ||
| 248 | : ok + ((bad - ok) >> 1)); | ||
| 249 | r = convert (t, tp); | ||
| 250 | if (r) | ||
| 251 | ok = mid; | ||
| 252 | else | ||
| 253 | bad = mid; | ||
| 254 | } | ||
| 255 | |||
| 256 | if (!r && ok) | ||
| 257 | { | ||
| 258 | /* The last conversion attempt failed; | ||
| 259 | revert to the most recent successful attempt. */ | ||
| 260 | *t = ok; | ||
| 261 | r = convert (t, tp); | ||
| 262 | } | ||
| 263 | } | ||
| 264 | |||
| 265 | return r; | ||
| 266 | } | ||
| 267 | |||
| 268 | |||
| 269 | /* Convert *TP to a time_t value, inverting | ||
| 270 | the monotonic and mostly-unit-linear conversion function CONVERT. | ||
| 271 | Use *OFFSET to keep track of a guess at the offset of the result, | ||
| 272 | compared to what the result would be for UTC without leap seconds. | ||
| 273 | If *OFFSET's guess is correct, only one CONVERT call is needed. | ||
| 274 | This function is external because it is used also by timegm.c. */ | ||
| 275 | time_t | ||
| 276 | __mktime_internal (struct tm *tp, | ||
| 277 | struct tm *(*convert) (const time_t *, struct tm *), | ||
| 278 | time_t *offset) | ||
| 279 | { | ||
| 280 | time_t t, gt, t0, t1, t2; | ||
| 281 | struct tm tm; | ||
| 282 | |||
| 283 | /* The maximum number of probes (calls to CONVERT) should be enough | ||
| 284 | to handle any combinations of time zone rule changes, solar time, | ||
| 285 | leap seconds, and oscillations around a spring-forward gap. | ||
| 286 | POSIX.1 prohibits leap seconds, but some hosts have them anyway. */ | ||
| 287 | int remaining_probes = 6; | ||
| 288 | |||
| 289 | /* Time requested. Copy it in case CONVERT modifies *TP; this can | ||
| 290 | occur if TP is localtime's returned value and CONVERT is localtime. */ | ||
| 291 | int sec = tp->tm_sec; | ||
| 292 | int min = tp->tm_min; | ||
| 293 | int hour = tp->tm_hour; | ||
| 294 | int mday = tp->tm_mday; | ||
| 295 | int mon = tp->tm_mon; | ||
| 296 | int year_requested = tp->tm_year; | ||
| 297 | /* Normalize the value. */ | ||
| 298 | int isdst = ((tp->tm_isdst >> (8 * sizeof (tp->tm_isdst) - 1)) | ||
| 299 | | (tp->tm_isdst != 0)); | ||
| 300 | |||
| 301 | /* 1 if the previous probe was DST. */ | ||
| 302 | int dst2; | ||
| 303 | |||
| 304 | /* Ensure that mon is in range, and set year accordingly. */ | ||
| 305 | int mon_remainder = mon % 12; | ||
| 306 | int negative_mon_remainder = mon_remainder < 0; | ||
| 307 | int mon_years = mon / 12 - negative_mon_remainder; | ||
| 308 | long int lyear_requested = year_requested; | ||
| 309 | long int year = lyear_requested + mon_years; | ||
| 310 | |||
| 311 | /* The other values need not be in range: | ||
| 312 | the remaining code handles minor overflows correctly, | ||
| 313 | assuming int and time_t arithmetic wraps around. | ||
| 314 | Major overflows are caught at the end. */ | ||
| 315 | |||
| 316 | /* Calculate day of year from year, month, and day of month. | ||
| 317 | The result need not be in range. */ | ||
| 318 | int mon_yday = ((__mon_yday[leapyear (year)] | ||
| 319 | [mon_remainder + 12 * negative_mon_remainder]) | ||
| 320 | - 1); | ||
| 321 | long int lmday = mday; | ||
| 322 | long int yday = mon_yday + lmday; | ||
| 323 | |||
| 324 | time_t guessed_offset = *offset; | ||
| 325 | |||
| 326 | int sec_requested = sec; | ||
| 327 | |||
| 328 | if (LEAP_SECONDS_POSSIBLE) | ||
| 329 | { | ||
| 330 | /* Handle out-of-range seconds specially, | ||
| 331 | since ydhms_tm_diff assumes every minute has 60 seconds. */ | ||
| 332 | if (sec < 0) | ||
| 333 | sec = 0; | ||
| 334 | if (59 < sec) | ||
| 335 | sec = 59; | ||
| 336 | } | ||
| 337 | |||
| 338 | /* Invert CONVERT by probing. First assume the same offset as last | ||
| 339 | time. */ | ||
| 340 | |||
| 341 | t0 = ydhms_diff (year, yday, hour, min, sec, | ||
| 342 | EPOCH_YEAR - TM_YEAR_BASE, 0, 0, 0, - guessed_offset); | ||
| 343 | |||
| 344 | if (TIME_T_MAX / INT_MAX / 366 / 24 / 60 / 60 < 3) | ||
| 345 | { | ||
| 346 | /* time_t isn't large enough to rule out overflows, so check | ||
| 347 | for major overflows. A gross check suffices, since if t0 | ||
| 348 | has overflowed, it is off by a multiple of TIME_T_MAX - | ||
| 349 | TIME_T_MIN + 1. So ignore any component of the difference | ||
| 350 | that is bounded by a small value. */ | ||
| 351 | |||
| 352 | /* Approximate log base 2 of the number of time units per | ||
| 353 | biennium. A biennium is 2 years; use this unit instead of | ||
| 354 | years to avoid integer overflow. For example, 2 average | ||
| 355 | Gregorian years are 2 * 365.2425 * 24 * 60 * 60 seconds, | ||
| 356 | which is 63113904 seconds, and rint (log2 (63113904)) is | ||
| 357 | 26. */ | ||
| 358 | int ALOG2_SECONDS_PER_BIENNIUM = 26; | ||
| 359 | int ALOG2_MINUTES_PER_BIENNIUM = 20; | ||
| 360 | int ALOG2_HOURS_PER_BIENNIUM = 14; | ||
| 361 | int ALOG2_DAYS_PER_BIENNIUM = 10; | ||
| 362 | int LOG2_YEARS_PER_BIENNIUM = 1; | ||
| 363 | |||
| 364 | int approx_requested_biennia = | ||
| 365 | (SHR (year_requested, LOG2_YEARS_PER_BIENNIUM) | ||
| 366 | - SHR (EPOCH_YEAR - TM_YEAR_BASE, LOG2_YEARS_PER_BIENNIUM) | ||
| 367 | + SHR (mday, ALOG2_DAYS_PER_BIENNIUM) | ||
| 368 | + SHR (hour, ALOG2_HOURS_PER_BIENNIUM) | ||
| 369 | + SHR (min, ALOG2_MINUTES_PER_BIENNIUM) | ||
| 370 | + (LEAP_SECONDS_POSSIBLE | ||
| 371 | ? 0 | ||
| 372 | : SHR (sec, ALOG2_SECONDS_PER_BIENNIUM))); | ||
| 373 | |||
| 374 | int approx_biennia = SHR (t0, ALOG2_SECONDS_PER_BIENNIUM); | ||
| 375 | int diff = approx_biennia - approx_requested_biennia; | ||
| 376 | int abs_diff = diff < 0 ? - diff : diff; | ||
| 377 | |||
| 378 | /* IRIX 4.0.5 cc miscaculates TIME_T_MIN / 3: it erroneously | ||
| 379 | gives a positive value of 715827882. Setting a variable | ||
| 380 | first then doing math on it seems to work. | ||
| 381 | (ghazi@caip.rutgers.edu) */ | ||
| 382 | time_t time_t_max = TIME_T_MAX; | ||
| 383 | time_t time_t_min = TIME_T_MIN; | ||
| 384 | time_t overflow_threshold = | ||
| 385 | (time_t_max / 3 - time_t_min / 3) >> ALOG2_SECONDS_PER_BIENNIUM; | ||
| 386 | |||
| 387 | if (overflow_threshold < abs_diff) | ||
| 388 | { | ||
| 389 | /* Overflow occurred. Try repairing it; this might work if | ||
| 390 | the time zone offset is enough to undo the overflow. */ | ||
| 391 | time_t repaired_t0 = -1 - t0; | ||
| 392 | approx_biennia = SHR (repaired_t0, ALOG2_SECONDS_PER_BIENNIUM); | ||
| 393 | diff = approx_biennia - approx_requested_biennia; | ||
| 394 | abs_diff = diff < 0 ? - diff : diff; | ||
| 395 | if (overflow_threshold < abs_diff) | ||
| 396 | return -1; | ||
| 397 | guessed_offset += repaired_t0 - t0; | ||
| 398 | t0 = repaired_t0; | ||
| 399 | } | ||
| 400 | } | ||
| 401 | |||
| 402 | /* Repeatedly use the error to improve the guess. */ | ||
| 403 | |||
| 404 | for (t = t1 = t2 = t0, dst2 = 0; | ||
| 405 | (gt = guess_time_tm (year, yday, hour, min, sec, &t, | ||
| 406 | ranged_convert (convert, &t, &tm)), | ||
| 407 | t != gt); | ||
| 408 | t1 = t2, t2 = t, t = gt, dst2 = tm.tm_isdst != 0) | ||
| 409 | if (t == t1 && t != t2 | ||
| 410 | && (tm.tm_isdst < 0 | ||
| 411 | || (isdst < 0 | ||
| 412 | ? dst2 <= (tm.tm_isdst != 0) | ||
| 413 | : (isdst != 0) != (tm.tm_isdst != 0)))) | ||
| 414 | /* We can't possibly find a match, as we are oscillating | ||
| 415 | between two values. The requested time probably falls | ||
| 416 | within a spring-forward gap of size GT - T. Follow the common | ||
| 417 | practice in this case, which is to return a time that is GT - T | ||
| 418 | away from the requested time, preferring a time whose | ||
| 419 | tm_isdst differs from the requested value. (If no tm_isdst | ||
| 420 | was requested and only one of the two values has a nonzero | ||
| 421 | tm_isdst, prefer that value.) In practice, this is more | ||
| 422 | useful than returning -1. */ | ||
| 423 | goto offset_found; | ||
| 424 | else if (--remaining_probes == 0) | ||
| 425 | return -1; | ||
| 426 | |||
| 427 | /* We have a match. Check whether tm.tm_isdst has the requested | ||
| 428 | value, if any. */ | ||
| 429 | if (isdst != tm.tm_isdst && 0 <= isdst && 0 <= tm.tm_isdst) | ||
| 430 | { | ||
| 431 | /* tm.tm_isdst has the wrong value. Look for a neighboring | ||
| 432 | time with the right value, and use its UTC offset. | ||
| 433 | |||
| 434 | Heuristic: probe the adjacent timestamps in both directions, | ||
| 435 | looking for the desired isdst. This should work for all real | ||
| 436 | time zone histories in the tz database. */ | ||
| 437 | |||
| 438 | /* Distance between probes when looking for a DST boundary. In | ||
| 439 | tzdata2003a, the shortest period of DST is 601200 seconds | ||
| 440 | (e.g., America/Recife starting 2000-10-08 01:00), and the | ||
| 441 | shortest period of non-DST surrounded by DST is 694800 | ||
| 442 | seconds (Africa/Tunis starting 1943-04-17 01:00). Use the | ||
| 443 | minimum of these two values, so we don't miss these short | ||
| 444 | periods when probing. */ | ||
| 445 | int stride = 601200; | ||
| 446 | |||
| 447 | /* The longest period of DST in tzdata2003a is 536454000 seconds | ||
| 448 | (e.g., America/Jujuy starting 1946-10-01 01:00). The longest | ||
| 449 | period of non-DST is much longer, but it makes no real sense | ||
| 450 | to search for more than a year of non-DST, so use the DST | ||
| 451 | max. */ | ||
| 452 | int duration_max = 536454000; | ||
| 453 | |||
| 454 | /* Search in both directions, so the maximum distance is half | ||
| 455 | the duration; add the stride to avoid off-by-1 problems. */ | ||
| 456 | int delta_bound = duration_max / 2 + stride; | ||
| 457 | |||
| 458 | int delta, direction; | ||
| 459 | |||
| 460 | for (delta = stride; delta < delta_bound; delta += stride) | ||
| 461 | for (direction = -1; direction <= 1; direction += 2) | ||
| 462 | { | ||
| 463 | time_t ot = t + delta * direction; | ||
| 464 | if ((ot < t) == (direction < 0)) | ||
| 465 | { | ||
| 466 | struct tm otm; | ||
| 467 | ranged_convert (convert, &ot, &otm); | ||
| 468 | if (otm.tm_isdst == isdst) | ||
| 469 | { | ||
| 470 | /* We found the desired tm_isdst. | ||
| 471 | Extrapolate back to the desired time. */ | ||
| 472 | t = guess_time_tm (year, yday, hour, min, sec, &ot, &otm); | ||
| 473 | ranged_convert (convert, &t, &tm); | ||
| 474 | goto offset_found; | ||
| 475 | } | ||
| 476 | } | ||
| 477 | } | ||
| 478 | } | ||
| 479 | |||
| 480 | offset_found: | ||
| 481 | *offset = guessed_offset + t - t0; | ||
| 482 | |||
| 483 | if (LEAP_SECONDS_POSSIBLE && sec_requested != tm.tm_sec) | ||
| 484 | { | ||
| 485 | /* Adjust time to reflect the tm_sec requested, not the normalized value. | ||
| 486 | Also, repair any damage from a false match due to a leap second. */ | ||
| 487 | int sec_adjustment = (sec == 0 && tm.tm_sec == 60) - sec; | ||
| 488 | t1 = t + sec_requested; | ||
| 489 | t2 = t1 + sec_adjustment; | ||
| 490 | if (((t1 < t) != (sec_requested < 0)) | ||
| 491 | | ((t2 < t1) != (sec_adjustment < 0)) | ||
| 492 | | ! convert (&t2, &tm)) | ||
| 493 | return -1; | ||
| 494 | t = t2; | ||
| 495 | } | ||
| 496 | |||
| 497 | *tp = tm; | ||
| 498 | return t; | ||
| 499 | } | ||
| 500 | |||
| 501 | |||
| 502 | /* FIXME: This should use a signed type wide enough to hold any UTC | ||
| 503 | offset in seconds. 'int' should be good enough for GNU code. We | ||
| 504 | can't fix this unilaterally though, as other modules invoke | ||
| 505 | __mktime_internal. */ | ||
| 506 | static time_t localtime_offset; | ||
| 507 | |||
| 508 | /* Convert *TP to a time_t value. */ | ||
| 509 | time_t | ||
| 510 | mktime (struct tm *tp) | ||
| 511 | { | ||
| 512 | #ifdef _LIBC | ||
| 513 | /* POSIX.1 8.1.1 requires that whenever mktime() is called, the | ||
| 514 | time zone names contained in the external variable `tzname' shall | ||
| 515 | be set as if the tzset() function had been called. */ | ||
| 516 | __tzset (); | ||
| 517 | #endif | ||
| 518 | |||
| 519 | return __mktime_internal (tp, __localtime_r, &localtime_offset); | ||
| 520 | } | ||
| 521 | |||
| 522 | #ifdef weak_alias | ||
| 523 | weak_alias (mktime, timelocal) | ||
| 524 | #endif | ||
| 525 | |||
| 526 | #ifdef _LIBC | ||
| 527 | libc_hidden_def (mktime) | ||
| 528 | libc_hidden_weak (timelocal) | ||
| 529 | #endif | ||
| 530 | |||
| 531 | #if DEBUG | ||
| 532 | |||
| 533 | static int | ||
| 534 | not_equal_tm (const struct tm *a, const struct tm *b) | ||
| 535 | { | ||
| 536 | return ((a->tm_sec ^ b->tm_sec) | ||
| 537 | | (a->tm_min ^ b->tm_min) | ||
| 538 | | (a->tm_hour ^ b->tm_hour) | ||
| 539 | | (a->tm_mday ^ b->tm_mday) | ||
| 540 | | (a->tm_mon ^ b->tm_mon) | ||
| 541 | | (a->tm_year ^ b->tm_year) | ||
| 542 | | (a->tm_yday ^ b->tm_yday) | ||
| 543 | | (a->tm_isdst ^ b->tm_isdst)); | ||
| 544 | } | ||
| 545 | |||
| 546 | static void | ||
| 547 | print_tm (const struct tm *tp) | ||
| 548 | { | ||
| 549 | if (tp) | ||
| 550 | printf ("%04d-%02d-%02d %02d:%02d:%02d yday %03d wday %d isdst %d", | ||
| 551 | tp->tm_year + TM_YEAR_BASE, tp->tm_mon + 1, tp->tm_mday, | ||
| 552 | tp->tm_hour, tp->tm_min, tp->tm_sec, | ||
| 553 | tp->tm_yday, tp->tm_wday, tp->tm_isdst); | ||
| 554 | else | ||
| 555 | printf ("0"); | ||
| 556 | } | ||
| 557 | |||
| 558 | static int | ||
| 559 | check_result (time_t tk, struct tm tmk, time_t tl, const struct tm *lt) | ||
| 560 | { | ||
| 561 | if (tk != tl || !lt || not_equal_tm (&tmk, lt)) | ||
| 562 | { | ||
| 563 | printf ("mktime ("); | ||
| 564 | print_tm (lt); | ||
| 565 | printf (")\nyields ("); | ||
| 566 | print_tm (&tmk); | ||
| 567 | printf (") == %ld, should be %ld\n", (long int) tk, (long int) tl); | ||
| 568 | return 1; | ||
| 569 | } | ||
| 570 | |||
| 571 | return 0; | ||
| 572 | } | ||
| 573 | |||
| 574 | int | ||
| 575 | main (int argc, char **argv) | ||
| 576 | { | ||
| 577 | int status = 0; | ||
| 578 | struct tm tm, tmk, tml; | ||
| 579 | struct tm *lt; | ||
| 580 | time_t tk, tl, tl1; | ||
| 581 | char trailer; | ||
| 582 | |||
| 583 | if ((argc == 3 || argc == 4) | ||
| 584 | && (sscanf (argv[1], "%d-%d-%d%c", | ||
| 585 | &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &trailer) | ||
| 586 | == 3) | ||
| 587 | && (sscanf (argv[2], "%d:%d:%d%c", | ||
| 588 | &tm.tm_hour, &tm.tm_min, &tm.tm_sec, &trailer) | ||
| 589 | == 3)) | ||
| 590 | { | ||
| 591 | tm.tm_year -= TM_YEAR_BASE; | ||
| 592 | tm.tm_mon--; | ||
| 593 | tm.tm_isdst = argc == 3 ? -1 : atoi (argv[3]); | ||
| 594 | tmk = tm; | ||
| 595 | tl = mktime (&tmk); | ||
| 596 | lt = localtime (&tl); | ||
| 597 | if (lt) | ||
| 598 | { | ||
| 599 | tml = *lt; | ||
| 600 | lt = &tml; | ||
| 601 | } | ||
| 602 | printf ("mktime returns %ld == ", (long int) tl); | ||
| 603 | print_tm (&tmk); | ||
| 604 | printf ("\n"); | ||
| 605 | status = check_result (tl, tmk, tl, lt); | ||
| 606 | } | ||
| 607 | else if (argc == 4 || (argc == 5 && strcmp (argv[4], "-") == 0)) | ||
| 608 | { | ||
| 609 | time_t from = atol (argv[1]); | ||
| 610 | time_t by = atol (argv[2]); | ||
| 611 | time_t to = atol (argv[3]); | ||
| 612 | |||
| 613 | if (argc == 4) | ||
| 614 | for (tl = from; by < 0 ? to <= tl : tl <= to; tl = tl1) | ||
| 615 | { | ||
| 616 | lt = localtime (&tl); | ||
| 617 | if (lt) | ||
| 618 | { | ||
| 619 | tmk = tml = *lt; | ||
| 620 | tk = mktime (&tmk); | ||
| 621 | status |= check_result (tk, tmk, tl, &tml); | ||
| 622 | } | ||
| 623 | else | ||
| 624 | { | ||
| 625 | printf ("localtime (%ld) yields 0\n", (long int) tl); | ||
| 626 | status = 1; | ||
| 627 | } | ||
| 628 | tl1 = tl + by; | ||
| 629 | if ((tl1 < tl) != (by < 0)) | ||
| 630 | break; | ||
| 631 | } | ||
| 632 | else | ||
| 633 | for (tl = from; by < 0 ? to <= tl : tl <= to; tl = tl1) | ||
| 634 | { | ||
| 635 | /* Null benchmark. */ | ||
| 636 | lt = localtime (&tl); | ||
| 637 | if (lt) | ||
| 638 | { | ||
| 639 | tmk = tml = *lt; | ||
| 640 | tk = tl; | ||
| 641 | status |= check_result (tk, tmk, tl, &tml); | ||
| 642 | } | ||
| 643 | else | ||
| 644 | { | ||
| 645 | printf ("localtime (%ld) yields 0\n", (long int) tl); | ||
| 646 | status = 1; | ||
| 647 | } | ||
| 648 | tl1 = tl + by; | ||
| 649 | if ((tl1 < tl) != (by < 0)) | ||
| 650 | break; | ||
| 651 | } | ||
| 652 | } | ||
| 653 | else | ||
| 654 | printf ("Usage:\ | ||
| 655 | \t%s YYYY-MM-DD HH:MM:SS [ISDST] # Test given time.\n\ | ||
| 656 | \t%s FROM BY TO # Test values FROM, FROM+BY, ..., TO.\n\ | ||
| 657 | \t%s FROM BY TO - # Do not test those values (for benchmark).\n", | ||
| 658 | argv[0], argv[0], argv[0]); | ||
| 659 | |||
| 660 | return status; | ||
| 661 | } | ||
| 662 | |||
| 663 | #endif /* DEBUG */ | ||
| 664 | |||
| 665 | /* | ||
| 666 | Local Variables: | ||
| 667 | compile-command: "gcc -DDEBUG -Wall -W -O -g mktime.c -o mktime" | ||
| 668 | End: | ||
| 669 | */ | ||
diff --git a/lib/stddef.in.h b/lib/stddef.in.h new file mode 100644 index 00000000000..62a91a7a6a3 --- /dev/null +++ b/lib/stddef.in.h | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | /* A substitute for POSIX 2008 <stddef.h>, for platforms that have issues. | ||
| 2 | |||
| 3 | Copyright (C) 2009-2011 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | This program is free software; you can redistribute it and/or modify | ||
| 6 | it under the terms of the GNU General Public License as published by | ||
| 7 | the Free Software Foundation; either version 3, or (at your option) | ||
| 8 | any later version. | ||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful, | ||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | GNU General Public License for more details. | ||
| 14 | |||
| 15 | You should have received a copy of the GNU General Public License | ||
| 16 | along with this program; if not, write to the Free Software Foundation, | ||
| 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
| 18 | |||
| 19 | /* Written by Eric Blake. */ | ||
| 20 | |||
| 21 | /* | ||
| 22 | * POSIX 2008 <stddef.h> for platforms that have issues. | ||
| 23 | * <http://www.opengroup.org/susv3xbd/stddef.h.html> | ||
| 24 | */ | ||
| 25 | |||
| 26 | #if __GNUC__ >= 3 | ||
| 27 | @PRAGMA_SYSTEM_HEADER@ | ||
| 28 | #endif | ||
| 29 | @PRAGMA_COLUMNS@ | ||
| 30 | |||
| 31 | #if defined __need_wchar_t || defined __need_size_t \ | ||
| 32 | || defined __need_ptrdiff_t || defined __need_NULL \ | ||
| 33 | || defined __need_wint_t | ||
| 34 | /* Special invocation convention inside gcc header files. In | ||
| 35 | particular, gcc provides a version of <stddef.h> that blindly | ||
| 36 | redefines NULL even when __need_wint_t was defined, even though | ||
| 37 | wint_t is not normally provided by <stddef.h>. Hence, we must | ||
| 38 | remember if special invocation has ever been used to obtain wint_t, | ||
| 39 | in which case we need to clean up NULL yet again. */ | ||
| 40 | |||
| 41 | # if !(defined _GL_STDDEF_H && defined _GL_STDDEF_WINT_T) | ||
| 42 | # ifdef __need_wint_t | ||
| 43 | # undef _GL_STDDEF_H | ||
| 44 | # define _GL_STDDEF_WINT_T | ||
| 45 | # endif | ||
| 46 | # @INCLUDE_NEXT@ @NEXT_STDDEF_H@ | ||
| 47 | # endif | ||
| 48 | |||
| 49 | #else | ||
| 50 | /* Normal invocation convention. */ | ||
| 51 | |||
| 52 | # ifndef _GL_STDDEF_H | ||
| 53 | |||
| 54 | /* The include_next requires a split double-inclusion guard. */ | ||
| 55 | |||
| 56 | # @INCLUDE_NEXT@ @NEXT_STDDEF_H@ | ||
| 57 | |||
| 58 | # ifndef _GL_STDDEF_H | ||
| 59 | # define _GL_STDDEF_H | ||
| 60 | |||
| 61 | /* On NetBSD 5.0, the definition of NULL lacks proper parentheses. */ | ||
| 62 | #if @REPLACE_NULL@ | ||
| 63 | # undef NULL | ||
| 64 | # ifdef __cplusplus | ||
| 65 | /* ISO C++ says that the macro NULL must expand to an integer constant | ||
| 66 | expression, hence '((void *) 0)' is not allowed in C++. */ | ||
| 67 | # if __GNUG__ >= 3 | ||
| 68 | /* GNU C++ has a __null macro that behaves like an integer ('int' or | ||
| 69 | 'long') but has the same size as a pointer. Use that, to avoid | ||
| 70 | warnings. */ | ||
| 71 | # define NULL __null | ||
| 72 | # else | ||
| 73 | # define NULL 0L | ||
| 74 | # endif | ||
| 75 | # else | ||
| 76 | # define NULL ((void *) 0) | ||
| 77 | # endif | ||
| 78 | #endif | ||
| 79 | |||
| 80 | /* Some platforms lack wchar_t. */ | ||
| 81 | #if !@HAVE_WCHAR_T@ | ||
| 82 | # define wchar_t int | ||
| 83 | #endif | ||
| 84 | |||
| 85 | # endif /* _GL_STDDEF_H */ | ||
| 86 | # endif /* _GL_STDDEF_H */ | ||
| 87 | #endif /* __need_XXX */ | ||
diff --git a/lib/time.h b/lib/time.h new file mode 100644 index 00000000000..fea68685438 --- /dev/null +++ b/lib/time.h | |||
| @@ -0,0 +1,555 @@ | |||
| 1 | /* DO NOT EDIT! GENERATED AUTOMATICALLY! */ | ||
| 2 | /* A more-standard <time.h>. | ||
| 3 | |||
| 4 | Copyright (C) 2007-2011 Free Software Foundation, Inc. | ||
| 5 | |||
| 6 | This program is free software; you can redistribute it and/or modify | ||
| 7 | it under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation; either version 3, or (at your option) | ||
| 9 | any later version. | ||
| 10 | |||
| 11 | This program is distributed in the hope that it will be useful, | ||
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with this program; if not, write to the Free Software Foundation, | ||
| 18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
| 19 | |||
| 20 | #if __GNUC__ >= 3 | ||
| 21 | #pragma GCC system_header | ||
| 22 | #endif | ||
| 23 | |||
| 24 | |||
| 25 | /* Don't get in the way of glibc when it includes time.h merely to | ||
| 26 | declare a few standard symbols, rather than to declare all the | ||
| 27 | symbols. Also, Solaris 8 <time.h> eventually includes itself | ||
| 28 | recursively; if that is happening, just include the system <time.h> | ||
| 29 | without adding our own declarations. */ | ||
| 30 | #if (defined __need_time_t || defined __need_clock_t \ | ||
| 31 | || defined __need_timespec \ | ||
| 32 | || defined _GL_TIME_H) | ||
| 33 | |||
| 34 | # include_next <time.h> | ||
| 35 | |||
| 36 | #else | ||
| 37 | |||
| 38 | # define _GL_TIME_H | ||
| 39 | |||
| 40 | # include_next <time.h> | ||
| 41 | |||
| 42 | /* NetBSD 5.0 mis-defines NULL. */ | ||
| 43 | # include <stddef.h> | ||
| 44 | |||
| 45 | /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ | ||
| 46 | #ifndef _GL_CXXDEFS_H | ||
| 47 | #define _GL_CXXDEFS_H | ||
| 48 | |||
| 49 | /* The three most frequent use cases of these macros are: | ||
| 50 | |||
| 51 | * For providing a substitute for a function that is missing on some | ||
| 52 | platforms, but is declared and works fine on the platforms on which | ||
| 53 | it exists: | ||
| 54 | |||
| 55 | #if @GNULIB_FOO@ | ||
| 56 | # if !@HAVE_FOO@ | ||
| 57 | _GL_FUNCDECL_SYS (foo, ...); | ||
| 58 | # endif | ||
| 59 | _GL_CXXALIAS_SYS (foo, ...); | ||
| 60 | _GL_CXXALIASWARN (foo); | ||
| 61 | #elif defined GNULIB_POSIXCHECK | ||
| 62 | ... | ||
| 63 | #endif | ||
| 64 | |||
| 65 | * For providing a replacement for a function that exists on all platforms, | ||
| 66 | but is broken/insufficient and needs to be replaced on some platforms: | ||
| 67 | |||
| 68 | #if @GNULIB_FOO@ | ||
| 69 | # if @REPLACE_FOO@ | ||
| 70 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 71 | # undef foo | ||
| 72 | # define foo rpl_foo | ||
| 73 | # endif | ||
| 74 | _GL_FUNCDECL_RPL (foo, ...); | ||
| 75 | _GL_CXXALIAS_RPL (foo, ...); | ||
| 76 | # else | ||
| 77 | _GL_CXXALIAS_SYS (foo, ...); | ||
| 78 | # endif | ||
| 79 | _GL_CXXALIASWARN (foo); | ||
| 80 | #elif defined GNULIB_POSIXCHECK | ||
| 81 | ... | ||
| 82 | #endif | ||
| 83 | |||
| 84 | * For providing a replacement for a function that exists on some platforms | ||
| 85 | but is broken/insufficient and needs to be replaced on some of them and | ||
| 86 | is additionally either missing or undeclared on some other platforms: | ||
| 87 | |||
| 88 | #if @GNULIB_FOO@ | ||
| 89 | # if @REPLACE_FOO@ | ||
| 90 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 91 | # undef foo | ||
| 92 | # define foo rpl_foo | ||
| 93 | # endif | ||
| 94 | _GL_FUNCDECL_RPL (foo, ...); | ||
| 95 | _GL_CXXALIAS_RPL (foo, ...); | ||
| 96 | # else | ||
| 97 | # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@ | ||
| 98 | _GL_FUNCDECL_SYS (foo, ...); | ||
| 99 | # endif | ||
| 100 | _GL_CXXALIAS_SYS (foo, ...); | ||
| 101 | # endif | ||
| 102 | _GL_CXXALIASWARN (foo); | ||
| 103 | #elif defined GNULIB_POSIXCHECK | ||
| 104 | ... | ||
| 105 | #endif | ||
| 106 | */ | ||
| 107 | |||
| 108 | /* _GL_EXTERN_C declaration; | ||
| 109 | performs the declaration with C linkage. */ | ||
| 110 | #if defined __cplusplus | ||
| 111 | # define _GL_EXTERN_C extern "C" | ||
| 112 | #else | ||
| 113 | # define _GL_EXTERN_C extern | ||
| 114 | #endif | ||
| 115 | |||
| 116 | /* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes); | ||
| 117 | declares a replacement function, named rpl_func, with the given prototype, | ||
| 118 | consisting of return type, parameters, and attributes. | ||
| 119 | Example: | ||
| 120 | _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...) | ||
| 121 | _GL_ARG_NONNULL ((1))); | ||
| 122 | */ | ||
| 123 | #define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \ | ||
| 124 | _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes) | ||
| 125 | #define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \ | ||
| 126 | _GL_EXTERN_C rettype rpl_func parameters_and_attributes | ||
| 127 | |||
| 128 | /* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes); | ||
| 129 | declares the system function, named func, with the given prototype, | ||
| 130 | consisting of return type, parameters, and attributes. | ||
| 131 | Example: | ||
| 132 | _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...) | ||
| 133 | _GL_ARG_NONNULL ((1))); | ||
| 134 | */ | ||
| 135 | #define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \ | ||
| 136 | _GL_EXTERN_C rettype func parameters_and_attributes | ||
| 137 | |||
| 138 | /* _GL_CXXALIAS_RPL (func, rettype, parameters); | ||
| 139 | declares a C++ alias called GNULIB_NAMESPACE::func | ||
| 140 | that redirects to rpl_func, if GNULIB_NAMESPACE is defined. | ||
| 141 | Example: | ||
| 142 | _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...)); | ||
| 143 | */ | ||
| 144 | #define _GL_CXXALIAS_RPL(func,rettype,parameters) \ | ||
| 145 | _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters) | ||
| 146 | #if defined __cplusplus && defined GNULIB_NAMESPACE | ||
| 147 | # define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \ | ||
| 148 | namespace GNULIB_NAMESPACE \ | ||
| 149 | { \ | ||
| 150 | rettype (*const func) parameters = ::rpl_func; \ | ||
| 151 | } \ | ||
| 152 | _GL_EXTERN_C int _gl_cxxalias_dummy | ||
| 153 | #else | ||
| 154 | # define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \ | ||
| 155 | _GL_EXTERN_C int _gl_cxxalias_dummy | ||
| 156 | #endif | ||
| 157 | |||
| 158 | /* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters); | ||
| 159 | is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters); | ||
| 160 | except that the C function rpl_func may have a slightly different | ||
| 161 | declaration. A cast is used to silence the "invalid conversion" error | ||
| 162 | that would otherwise occur. */ | ||
| 163 | #if defined __cplusplus && defined GNULIB_NAMESPACE | ||
| 164 | # define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \ | ||
| 165 | namespace GNULIB_NAMESPACE \ | ||
| 166 | { \ | ||
| 167 | rettype (*const func) parameters = \ | ||
| 168 | reinterpret_cast<rettype(*)parameters>(::rpl_func); \ | ||
| 169 | } \ | ||
| 170 | _GL_EXTERN_C int _gl_cxxalias_dummy | ||
| 171 | #else | ||
| 172 | # define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \ | ||
| 173 | _GL_EXTERN_C int _gl_cxxalias_dummy | ||
| 174 | #endif | ||
| 175 | |||
| 176 | /* _GL_CXXALIAS_SYS (func, rettype, parameters); | ||
| 177 | declares a C++ alias called GNULIB_NAMESPACE::func | ||
| 178 | that redirects to the system provided function func, if GNULIB_NAMESPACE | ||
| 179 | is defined. | ||
| 180 | Example: | ||
| 181 | _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...)); | ||
| 182 | */ | ||
| 183 | #if defined __cplusplus && defined GNULIB_NAMESPACE | ||
| 184 | /* If we were to write | ||
| 185 | rettype (*const func) parameters = ::func; | ||
| 186 | like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls | ||
| 187 | better (remove an indirection through a 'static' pointer variable), | ||
| 188 | but then the _GL_CXXALIASWARN macro below would cause a warning not only | ||
| 189 | for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */ | ||
| 190 | # define _GL_CXXALIAS_SYS(func,rettype,parameters) \ | ||
| 191 | namespace GNULIB_NAMESPACE \ | ||
| 192 | { \ | ||
| 193 | static rettype (*func) parameters = ::func; \ | ||
| 194 | } \ | ||
| 195 | _GL_EXTERN_C int _gl_cxxalias_dummy | ||
| 196 | #else | ||
| 197 | # define _GL_CXXALIAS_SYS(func,rettype,parameters) \ | ||
| 198 | _GL_EXTERN_C int _gl_cxxalias_dummy | ||
| 199 | #endif | ||
| 200 | |||
| 201 | /* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters); | ||
| 202 | is like _GL_CXXALIAS_SYS (func, rettype, parameters); | ||
| 203 | except that the C function func may have a slightly different declaration. | ||
| 204 | A cast is used to silence the "invalid conversion" error that would | ||
| 205 | otherwise occur. */ | ||
| 206 | #if defined __cplusplus && defined GNULIB_NAMESPACE | ||
| 207 | # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \ | ||
| 208 | namespace GNULIB_NAMESPACE \ | ||
| 209 | { \ | ||
| 210 | static rettype (*func) parameters = \ | ||
| 211 | reinterpret_cast<rettype(*)parameters>(::func); \ | ||
| 212 | } \ | ||
| 213 | _GL_EXTERN_C int _gl_cxxalias_dummy | ||
| 214 | #else | ||
| 215 | # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \ | ||
| 216 | _GL_EXTERN_C int _gl_cxxalias_dummy | ||
| 217 | #endif | ||
| 218 | |||
| 219 | /* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2); | ||
| 220 | is like _GL_CXXALIAS_SYS (func, rettype, parameters); | ||
| 221 | except that the C function is picked among a set of overloaded functions, | ||
| 222 | namely the one with rettype2 and parameters2. Two consecutive casts | ||
| 223 | are used to silence the "cannot find a match" and "invalid conversion" | ||
| 224 | errors that would otherwise occur. */ | ||
| 225 | #if defined __cplusplus && defined GNULIB_NAMESPACE | ||
| 226 | /* The outer cast must be a reinterpret_cast. | ||
| 227 | The inner cast: When the function is defined as a set of overloaded | ||
| 228 | functions, it works as a static_cast<>, choosing the designated variant. | ||
| 229 | When the function is defined as a single variant, it works as a | ||
| 230 | reinterpret_cast<>. The parenthesized cast syntax works both ways. */ | ||
| 231 | # define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \ | ||
| 232 | namespace GNULIB_NAMESPACE \ | ||
| 233 | { \ | ||
| 234 | static rettype (*func) parameters = \ | ||
| 235 | reinterpret_cast<rettype(*)parameters>( \ | ||
| 236 | (rettype2(*)parameters2)(::func)); \ | ||
| 237 | } \ | ||
| 238 | _GL_EXTERN_C int _gl_cxxalias_dummy | ||
| 239 | #else | ||
| 240 | # define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \ | ||
| 241 | _GL_EXTERN_C int _gl_cxxalias_dummy | ||
| 242 | #endif | ||
| 243 | |||
| 244 | /* _GL_CXXALIASWARN (func); | ||
| 245 | causes a warning to be emitted when ::func is used but not when | ||
| 246 | GNULIB_NAMESPACE::func is used. func must be defined without overloaded | ||
| 247 | variants. */ | ||
| 248 | #if defined __cplusplus && defined GNULIB_NAMESPACE | ||
| 249 | # define _GL_CXXALIASWARN(func) \ | ||
| 250 | _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE) | ||
| 251 | # define _GL_CXXALIASWARN_1(func,namespace) \ | ||
| 252 | _GL_CXXALIASWARN_2 (func, namespace) | ||
| 253 | /* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>, | ||
| 254 | we enable the warning only when not optimizing. */ | ||
| 255 | # if !__OPTIMIZE__ | ||
| 256 | # define _GL_CXXALIASWARN_2(func,namespace) \ | ||
| 257 | _GL_WARN_ON_USE (func, \ | ||
| 258 | "The symbol ::" #func " refers to the system function. " \ | ||
| 259 | "Use " #namespace "::" #func " instead.") | ||
| 260 | # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING | ||
| 261 | # define _GL_CXXALIASWARN_2(func,namespace) \ | ||
| 262 | extern __typeof__ (func) func | ||
| 263 | # else | ||
| 264 | # define _GL_CXXALIASWARN_2(func,namespace) \ | ||
| 265 | _GL_EXTERN_C int _gl_cxxalias_dummy | ||
| 266 | # endif | ||
| 267 | #else | ||
| 268 | # define _GL_CXXALIASWARN(func) \ | ||
| 269 | _GL_EXTERN_C int _gl_cxxalias_dummy | ||
| 270 | #endif | ||
| 271 | |||
| 272 | /* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes); | ||
| 273 | causes a warning to be emitted when the given overloaded variant of ::func | ||
| 274 | is used but not when GNULIB_NAMESPACE::func is used. */ | ||
| 275 | #if defined __cplusplus && defined GNULIB_NAMESPACE | ||
| 276 | # define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \ | ||
| 277 | _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \ | ||
| 278 | GNULIB_NAMESPACE) | ||
| 279 | # define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \ | ||
| 280 | _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace) | ||
| 281 | /* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>, | ||
| 282 | we enable the warning only when not optimizing. */ | ||
| 283 | # if !__OPTIMIZE__ | ||
| 284 | # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \ | ||
| 285 | _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \ | ||
| 286 | "The symbol ::" #func " refers to the system function. " \ | ||
| 287 | "Use " #namespace "::" #func " instead.") | ||
| 288 | # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING | ||
| 289 | # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \ | ||
| 290 | extern __typeof__ (func) func | ||
| 291 | # else | ||
| 292 | # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \ | ||
| 293 | _GL_EXTERN_C int _gl_cxxalias_dummy | ||
| 294 | # endif | ||
| 295 | #else | ||
| 296 | # define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \ | ||
| 297 | _GL_EXTERN_C int _gl_cxxalias_dummy | ||
| 298 | #endif | ||
| 299 | |||
| 300 | #endif /* _GL_CXXDEFS_H */ | ||
| 301 | |||
| 302 | /* The definition of _GL_ARG_NONNULL is copied here. */ | ||
| 303 | /* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools | ||
| 304 | that the values passed as arguments n, ..., m must be non-NULL pointers. | ||
| 305 | n = 1 stands for the first argument, n = 2 for the second argument etc. */ | ||
| 306 | #ifndef _GL_ARG_NONNULL | ||
| 307 | # if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3 | ||
| 308 | # define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params)) | ||
| 309 | # else | ||
| 310 | # define _GL_ARG_NONNULL(params) | ||
| 311 | # endif | ||
| 312 | #endif | ||
| 313 | |||
| 314 | /* The definition of _GL_WARN_ON_USE is copied here. */ | ||
| 315 | #ifndef _GL_WARN_ON_USE | ||
| 316 | |||
| 317 | # if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) | ||
| 318 | /* A compiler attribute is available in gcc versions 4.3.0 and later. */ | ||
| 319 | # define _GL_WARN_ON_USE(function, message) \ | ||
| 320 | extern __typeof__ (function) function __attribute__ ((__warning__ (message))) | ||
| 321 | # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING | ||
| 322 | /* Verify the existence of the function. */ | ||
| 323 | # define _GL_WARN_ON_USE(function, message) \ | ||
| 324 | extern __typeof__ (function) function | ||
| 325 | # else /* Unsupported. */ | ||
| 326 | # define _GL_WARN_ON_USE(function, message) \ | ||
| 327 | _GL_WARN_EXTERN_C int _gl_warn_on_use | ||
| 328 | # endif | ||
| 329 | #endif | ||
| 330 | |||
| 331 | /* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string") | ||
| 332 | is like _GL_WARN_ON_USE (function, "string"), except that the function is | ||
| 333 | declared with the given prototype, consisting of return type, parameters, | ||
| 334 | and attributes. | ||
| 335 | This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does | ||
| 336 | not work in this case. */ | ||
| 337 | #ifndef _GL_WARN_ON_USE_CXX | ||
| 338 | # if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) | ||
| 339 | # define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \ | ||
| 340 | extern rettype function parameters_and_attributes \ | ||
| 341 | __attribute__ ((__warning__ (msg))) | ||
| 342 | # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING | ||
| 343 | /* Verify the existence of the function. */ | ||
| 344 | # define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \ | ||
| 345 | extern rettype function parameters_and_attributes | ||
| 346 | # else /* Unsupported. */ | ||
| 347 | # define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \ | ||
| 348 | _GL_WARN_EXTERN_C int _gl_warn_on_use | ||
| 349 | # endif | ||
| 350 | #endif | ||
| 351 | |||
| 352 | /* _GL_WARN_EXTERN_C declaration; | ||
| 353 | performs the declaration with C linkage. */ | ||
| 354 | #ifndef _GL_WARN_EXTERN_C | ||
| 355 | # if defined __cplusplus | ||
| 356 | # define _GL_WARN_EXTERN_C extern "C" | ||
| 357 | # else | ||
| 358 | # define _GL_WARN_EXTERN_C extern | ||
| 359 | # endif | ||
| 360 | #endif | ||
| 361 | |||
| 362 | /* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3). | ||
| 363 | Or they define it with the wrong member names or define it in <sys/time.h> | ||
| 364 | (e.g., FreeBSD circa 1997). Stock Mingw does not define it, but the | ||
| 365 | pthreads-win32 library defines it in <pthread.h>. */ | ||
| 366 | # if ! 1 | ||
| 367 | # if 0 | ||
| 368 | # include <sys/time.h> | ||
| 369 | # elif 0 | ||
| 370 | # include <pthread.h> | ||
| 371 | /* The pthreads-win32 <pthread.h> also defines a couple of broken macros. */ | ||
| 372 | # undef asctime_r | ||
| 373 | # undef ctime_r | ||
| 374 | # undef gmtime_r | ||
| 375 | # undef localtime_r | ||
| 376 | # undef rand_r | ||
| 377 | # undef strtok_r | ||
| 378 | # else | ||
| 379 | |||
| 380 | # ifdef __cplusplus | ||
| 381 | extern "C" { | ||
| 382 | # endif | ||
| 383 | |||
| 384 | # undef timespec | ||
| 385 | # define timespec rpl_timespec | ||
| 386 | struct timespec | ||
| 387 | { | ||
| 388 | time_t tv_sec; | ||
| 389 | long int tv_nsec; | ||
| 390 | }; | ||
| 391 | |||
| 392 | # ifdef __cplusplus | ||
| 393 | } | ||
| 394 | # endif | ||
| 395 | |||
| 396 | # endif | ||
| 397 | # endif | ||
| 398 | |||
| 399 | /* Per http://austingroupbugs.net/view.php?id=327, POSIX requires | ||
| 400 | time_t to be an integer type, even though C99 permits floating | ||
| 401 | point. We don't know of any implementation that uses floating | ||
| 402 | point, and it is much easier to write code that doesn't have to | ||
| 403 | worry about that corner case, so we force the issue. */ | ||
| 404 | struct __time_t_must_be_integral { | ||
| 405 | unsigned int __floating_time_t_unsupported : (time_t) 1; | ||
| 406 | }; | ||
| 407 | |||
| 408 | /* Sleep for at least RQTP seconds unless interrupted, If interrupted, | ||
| 409 | return -1 and store the remaining time into RMTP. See | ||
| 410 | <http://www.opengroup.org/susv3xsh/nanosleep.html>. */ | ||
| 411 | # if 0 | ||
| 412 | # if GNULIB_PORTCHECK | ||
| 413 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 414 | # define nanosleep rpl_nanosleep | ||
| 415 | # endif | ||
| 416 | _GL_FUNCDECL_RPL (nanosleep, int, | ||
| 417 | (struct timespec const *__rqtp, struct timespec *__rmtp) | ||
| 418 | _GL_ARG_NONNULL ((1))); | ||
| 419 | _GL_CXXALIAS_RPL (nanosleep, int, | ||
| 420 | (struct timespec const *__rqtp, struct timespec *__rmtp)); | ||
| 421 | # else | ||
| 422 | # if ! 1 | ||
| 423 | _GL_FUNCDECL_SYS (nanosleep, int, | ||
| 424 | (struct timespec const *__rqtp, struct timespec *__rmtp) | ||
| 425 | _GL_ARG_NONNULL ((1))); | ||
| 426 | # endif | ||
| 427 | _GL_CXXALIAS_SYS (nanosleep, int, | ||
| 428 | (struct timespec const *__rqtp, struct timespec *__rmtp)); | ||
| 429 | # endif | ||
| 430 | _GL_CXXALIASWARN (nanosleep); | ||
| 431 | # endif | ||
| 432 | |||
| 433 | /* Return the 'time_t' representation of TP and normalize TP. */ | ||
| 434 | # if 1 | ||
| 435 | # if 0 | ||
| 436 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 437 | # define mktime rpl_mktime | ||
| 438 | # endif | ||
| 439 | _GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1))); | ||
| 440 | _GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp)); | ||
| 441 | # else | ||
| 442 | _GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp)); | ||
| 443 | # endif | ||
| 444 | _GL_CXXALIASWARN (mktime); | ||
| 445 | # endif | ||
| 446 | |||
| 447 | /* Convert TIMER to RESULT, assuming local time and UTC respectively. See | ||
| 448 | <http://www.opengroup.org/susv3xsh/localtime_r.html> and | ||
| 449 | <http://www.opengroup.org/susv3xsh/gmtime_r.html>. */ | ||
| 450 | # if 1 | ||
| 451 | # if 0 | ||
| 452 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 453 | # undef localtime_r | ||
| 454 | # define localtime_r rpl_localtime_r | ||
| 455 | # endif | ||
| 456 | _GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer, | ||
| 457 | struct tm *restrict __result) | ||
| 458 | _GL_ARG_NONNULL ((1, 2))); | ||
| 459 | _GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer, | ||
| 460 | struct tm *restrict __result)); | ||
| 461 | # else | ||
| 462 | # if ! 0 | ||
| 463 | _GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer, | ||
| 464 | struct tm *restrict __result) | ||
| 465 | _GL_ARG_NONNULL ((1, 2))); | ||
| 466 | # endif | ||
| 467 | _GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer, | ||
| 468 | struct tm *restrict __result)); | ||
| 469 | # endif | ||
| 470 | # if 0 | ||
| 471 | _GL_CXXALIASWARN (localtime_r); | ||
| 472 | # endif | ||
| 473 | # if 0 | ||
| 474 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 475 | # undef gmtime_r | ||
| 476 | # define gmtime_r rpl_gmtime_r | ||
| 477 | # endif | ||
| 478 | _GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer, | ||
| 479 | struct tm *restrict __result) | ||
| 480 | _GL_ARG_NONNULL ((1, 2))); | ||
| 481 | _GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer, | ||
| 482 | struct tm *restrict __result)); | ||
| 483 | # else | ||
| 484 | # if ! 0 | ||
| 485 | _GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer, | ||
| 486 | struct tm *restrict __result) | ||
| 487 | _GL_ARG_NONNULL ((1, 2))); | ||
| 488 | # endif | ||
| 489 | _GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer, | ||
| 490 | struct tm *restrict __result)); | ||
| 491 | # endif | ||
| 492 | # if 0 | ||
| 493 | _GL_CXXALIASWARN (gmtime_r); | ||
| 494 | # endif | ||
| 495 | # endif | ||
| 496 | |||
| 497 | /* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store | ||
| 498 | the resulting broken-down time into TM. See | ||
| 499 | <http://www.opengroup.org/susv3xsh/strptime.html>. */ | ||
| 500 | # if 0 | ||
| 501 | # if ! 1 | ||
| 502 | _GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf, | ||
| 503 | char const *restrict __format, | ||
| 504 | struct tm *restrict __tm) | ||
| 505 | _GL_ARG_NONNULL ((1, 2, 3))); | ||
| 506 | # endif | ||
| 507 | _GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf, | ||
| 508 | char const *restrict __format, | ||
| 509 | struct tm *restrict __tm)); | ||
| 510 | _GL_CXXALIASWARN (strptime); | ||
| 511 | # endif | ||
| 512 | |||
| 513 | /* Convert TM to a time_t value, assuming UTC. */ | ||
| 514 | # if 0 | ||
| 515 | # if GNULIB_PORTCHECK | ||
| 516 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 517 | # undef timegm | ||
| 518 | # define timegm rpl_timegm | ||
| 519 | # endif | ||
| 520 | _GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1))); | ||
| 521 | _GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm)); | ||
| 522 | # else | ||
| 523 | # if ! 1 | ||
| 524 | _GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1))); | ||
| 525 | # endif | ||
| 526 | _GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm)); | ||
| 527 | # endif | ||
| 528 | _GL_CXXALIASWARN (timegm); | ||
| 529 | # endif | ||
| 530 | |||
| 531 | /* Encourage applications to avoid unsafe functions that can overrun | ||
| 532 | buffers when given outlandish struct tm values. Portable | ||
| 533 | applications should use strftime (or even sprintf) instead. */ | ||
| 534 | # if defined GNULIB_POSIXCHECK | ||
| 535 | # undef asctime | ||
| 536 | _GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - " | ||
| 537 | "better use strftime (or even sprintf) instead"); | ||
| 538 | # endif | ||
| 539 | # if defined GNULIB_POSIXCHECK | ||
| 540 | # undef asctime_r | ||
| 541 | _GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - " | ||
| 542 | "better use strftime (or even sprintf) instead"); | ||
| 543 | # endif | ||
| 544 | # if defined GNULIB_POSIXCHECK | ||
| 545 | # undef ctime | ||
| 546 | _GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - " | ||
| 547 | "better use strftime (or even sprintf) instead"); | ||
| 548 | # endif | ||
| 549 | # if defined GNULIB_POSIXCHECK | ||
| 550 | # undef ctime_r | ||
| 551 | _GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - " | ||
| 552 | "better use strftime (or even sprintf) instead"); | ||
| 553 | # endif | ||
| 554 | |||
| 555 | #endif | ||
diff --git a/lib/time.in.h b/lib/time.in.h new file mode 100644 index 00000000000..2d6da7161fb --- /dev/null +++ b/lib/time.in.h | |||
| @@ -0,0 +1,243 @@ | |||
| 1 | /* A more-standard <time.h>. | ||
| 2 | |||
| 3 | Copyright (C) 2007-2011 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | This program is free software; you can redistribute it and/or modify | ||
| 6 | it under the terms of the GNU General Public License as published by | ||
| 7 | the Free Software Foundation; either version 3, or (at your option) | ||
| 8 | any later version. | ||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful, | ||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | GNU General Public License for more details. | ||
| 14 | |||
| 15 | You should have received a copy of the GNU General Public License | ||
| 16 | along with this program; if not, write to the Free Software Foundation, | ||
| 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
| 18 | |||
| 19 | #if __GNUC__ >= 3 | ||
| 20 | @PRAGMA_SYSTEM_HEADER@ | ||
| 21 | #endif | ||
| 22 | @PRAGMA_COLUMNS@ | ||
| 23 | |||
| 24 | /* Don't get in the way of glibc when it includes time.h merely to | ||
| 25 | declare a few standard symbols, rather than to declare all the | ||
| 26 | symbols. Also, Solaris 8 <time.h> eventually includes itself | ||
| 27 | recursively; if that is happening, just include the system <time.h> | ||
| 28 | without adding our own declarations. */ | ||
| 29 | #if (defined __need_time_t || defined __need_clock_t \ | ||
| 30 | || defined __need_timespec \ | ||
| 31 | || defined _GL_TIME_H) | ||
| 32 | |||
| 33 | # @INCLUDE_NEXT@ @NEXT_TIME_H@ | ||
| 34 | |||
| 35 | #else | ||
| 36 | |||
| 37 | # define _GL_TIME_H | ||
| 38 | |||
| 39 | # @INCLUDE_NEXT@ @NEXT_TIME_H@ | ||
| 40 | |||
| 41 | /* NetBSD 5.0 mis-defines NULL. */ | ||
| 42 | # include <stddef.h> | ||
| 43 | |||
| 44 | /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ | ||
| 45 | |||
| 46 | /* The definition of _GL_ARG_NONNULL is copied here. */ | ||
| 47 | |||
| 48 | /* The definition of _GL_WARN_ON_USE is copied here. */ | ||
| 49 | |||
| 50 | /* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3). | ||
| 51 | Or they define it with the wrong member names or define it in <sys/time.h> | ||
| 52 | (e.g., FreeBSD circa 1997). Stock Mingw does not define it, but the | ||
| 53 | pthreads-win32 library defines it in <pthread.h>. */ | ||
| 54 | # if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@ | ||
| 55 | # if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@ | ||
| 56 | # include <sys/time.h> | ||
| 57 | # elif @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@ | ||
| 58 | # include <pthread.h> | ||
| 59 | /* The pthreads-win32 <pthread.h> also defines a couple of broken macros. */ | ||
| 60 | # undef asctime_r | ||
| 61 | # undef ctime_r | ||
| 62 | # undef gmtime_r | ||
| 63 | # undef localtime_r | ||
| 64 | # undef rand_r | ||
| 65 | # undef strtok_r | ||
| 66 | # else | ||
| 67 | |||
| 68 | # ifdef __cplusplus | ||
| 69 | extern "C" { | ||
| 70 | # endif | ||
| 71 | |||
| 72 | # undef timespec | ||
| 73 | # define timespec rpl_timespec | ||
| 74 | struct timespec | ||
| 75 | { | ||
| 76 | time_t tv_sec; | ||
| 77 | long int tv_nsec; | ||
| 78 | }; | ||
| 79 | |||
| 80 | # ifdef __cplusplus | ||
| 81 | } | ||
| 82 | # endif | ||
| 83 | |||
| 84 | # endif | ||
| 85 | # endif | ||
| 86 | |||
| 87 | /* Per http://austingroupbugs.net/view.php?id=327, POSIX requires | ||
| 88 | time_t to be an integer type, even though C99 permits floating | ||
| 89 | point. We don't know of any implementation that uses floating | ||
| 90 | point, and it is much easier to write code that doesn't have to | ||
| 91 | worry about that corner case, so we force the issue. */ | ||
| 92 | struct __time_t_must_be_integral { | ||
| 93 | unsigned int __floating_time_t_unsupported : (time_t) 1; | ||
| 94 | }; | ||
| 95 | |||
| 96 | /* Sleep for at least RQTP seconds unless interrupted, If interrupted, | ||
| 97 | return -1 and store the remaining time into RMTP. See | ||
| 98 | <http://www.opengroup.org/susv3xsh/nanosleep.html>. */ | ||
| 99 | # if @GNULIB_NANOSLEEP@ | ||
| 100 | # if @REPLACE_NANOSLEEP@ | ||
| 101 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 102 | # define nanosleep rpl_nanosleep | ||
| 103 | # endif | ||
| 104 | _GL_FUNCDECL_RPL (nanosleep, int, | ||
| 105 | (struct timespec const *__rqtp, struct timespec *__rmtp) | ||
| 106 | _GL_ARG_NONNULL ((1))); | ||
| 107 | _GL_CXXALIAS_RPL (nanosleep, int, | ||
| 108 | (struct timespec const *__rqtp, struct timespec *__rmtp)); | ||
| 109 | # else | ||
| 110 | # if ! @HAVE_NANOSLEEP@ | ||
| 111 | _GL_FUNCDECL_SYS (nanosleep, int, | ||
| 112 | (struct timespec const *__rqtp, struct timespec *__rmtp) | ||
| 113 | _GL_ARG_NONNULL ((1))); | ||
| 114 | # endif | ||
| 115 | _GL_CXXALIAS_SYS (nanosleep, int, | ||
| 116 | (struct timespec const *__rqtp, struct timespec *__rmtp)); | ||
| 117 | # endif | ||
| 118 | _GL_CXXALIASWARN (nanosleep); | ||
| 119 | # endif | ||
| 120 | |||
| 121 | /* Return the 'time_t' representation of TP and normalize TP. */ | ||
| 122 | # if @GNULIB_MKTIME@ | ||
| 123 | # if @REPLACE_MKTIME@ | ||
| 124 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 125 | # define mktime rpl_mktime | ||
| 126 | # endif | ||
| 127 | _GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1))); | ||
| 128 | _GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp)); | ||
| 129 | # else | ||
| 130 | _GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp)); | ||
| 131 | # endif | ||
| 132 | _GL_CXXALIASWARN (mktime); | ||
| 133 | # endif | ||
| 134 | |||
| 135 | /* Convert TIMER to RESULT, assuming local time and UTC respectively. See | ||
| 136 | <http://www.opengroup.org/susv3xsh/localtime_r.html> and | ||
| 137 | <http://www.opengroup.org/susv3xsh/gmtime_r.html>. */ | ||
| 138 | # if @GNULIB_TIME_R@ | ||
| 139 | # if @REPLACE_LOCALTIME_R@ | ||
| 140 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 141 | # undef localtime_r | ||
| 142 | # define localtime_r rpl_localtime_r | ||
| 143 | # endif | ||
| 144 | _GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer, | ||
| 145 | struct tm *restrict __result) | ||
| 146 | _GL_ARG_NONNULL ((1, 2))); | ||
| 147 | _GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer, | ||
| 148 | struct tm *restrict __result)); | ||
| 149 | # else | ||
| 150 | # if ! @HAVE_DECL_LOCALTIME_R@ | ||
| 151 | _GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer, | ||
| 152 | struct tm *restrict __result) | ||
| 153 | _GL_ARG_NONNULL ((1, 2))); | ||
| 154 | # endif | ||
| 155 | _GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer, | ||
| 156 | struct tm *restrict __result)); | ||
| 157 | # endif | ||
| 158 | # if @HAVE_DECL_LOCALTIME_R@ | ||
| 159 | _GL_CXXALIASWARN (localtime_r); | ||
| 160 | # endif | ||
| 161 | # if @REPLACE_LOCALTIME_R@ | ||
| 162 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 163 | # undef gmtime_r | ||
| 164 | # define gmtime_r rpl_gmtime_r | ||
| 165 | # endif | ||
| 166 | _GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer, | ||
| 167 | struct tm *restrict __result) | ||
| 168 | _GL_ARG_NONNULL ((1, 2))); | ||
| 169 | _GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer, | ||
| 170 | struct tm *restrict __result)); | ||
| 171 | # else | ||
| 172 | # if ! @HAVE_DECL_LOCALTIME_R@ | ||
| 173 | _GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer, | ||
| 174 | struct tm *restrict __result) | ||
| 175 | _GL_ARG_NONNULL ((1, 2))); | ||
| 176 | # endif | ||
| 177 | _GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer, | ||
| 178 | struct tm *restrict __result)); | ||
| 179 | # endif | ||
| 180 | # if @HAVE_DECL_LOCALTIME_R@ | ||
| 181 | _GL_CXXALIASWARN (gmtime_r); | ||
| 182 | # endif | ||
| 183 | # endif | ||
| 184 | |||
| 185 | /* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store | ||
| 186 | the resulting broken-down time into TM. See | ||
| 187 | <http://www.opengroup.org/susv3xsh/strptime.html>. */ | ||
| 188 | # if @GNULIB_STRPTIME@ | ||
| 189 | # if ! @HAVE_STRPTIME@ | ||
| 190 | _GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf, | ||
| 191 | char const *restrict __format, | ||
| 192 | struct tm *restrict __tm) | ||
| 193 | _GL_ARG_NONNULL ((1, 2, 3))); | ||
| 194 | # endif | ||
| 195 | _GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf, | ||
| 196 | char const *restrict __format, | ||
| 197 | struct tm *restrict __tm)); | ||
| 198 | _GL_CXXALIASWARN (strptime); | ||
| 199 | # endif | ||
| 200 | |||
| 201 | /* Convert TM to a time_t value, assuming UTC. */ | ||
| 202 | # if @GNULIB_TIMEGM@ | ||
| 203 | # if @REPLACE_TIMEGM@ | ||
| 204 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 205 | # undef timegm | ||
| 206 | # define timegm rpl_timegm | ||
| 207 | # endif | ||
| 208 | _GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1))); | ||
| 209 | _GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm)); | ||
| 210 | # else | ||
| 211 | # if ! @HAVE_TIMEGM@ | ||
| 212 | _GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1))); | ||
| 213 | # endif | ||
| 214 | _GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm)); | ||
| 215 | # endif | ||
| 216 | _GL_CXXALIASWARN (timegm); | ||
| 217 | # endif | ||
| 218 | |||
| 219 | /* Encourage applications to avoid unsafe functions that can overrun | ||
| 220 | buffers when given outlandish struct tm values. Portable | ||
| 221 | applications should use strftime (or even sprintf) instead. */ | ||
| 222 | # if defined GNULIB_POSIXCHECK | ||
| 223 | # undef asctime | ||
| 224 | _GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - " | ||
| 225 | "better use strftime (or even sprintf) instead"); | ||
| 226 | # endif | ||
| 227 | # if defined GNULIB_POSIXCHECK | ||
| 228 | # undef asctime_r | ||
| 229 | _GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - " | ||
| 230 | "better use strftime (or even sprintf) instead"); | ||
| 231 | # endif | ||
| 232 | # if defined GNULIB_POSIXCHECK | ||
| 233 | # undef ctime | ||
| 234 | _GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - " | ||
| 235 | "better use strftime (or even sprintf) instead"); | ||
| 236 | # endif | ||
| 237 | # if defined GNULIB_POSIXCHECK | ||
| 238 | # undef ctime_r | ||
| 239 | _GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - " | ||
| 240 | "better use strftime (or even sprintf) instead"); | ||
| 241 | # endif | ||
| 242 | |||
| 243 | #endif | ||
diff --git a/lib/time_r.c b/lib/time_r.c new file mode 100644 index 00000000000..31d010e437b --- /dev/null +++ b/lib/time_r.c | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | /* Reentrant time functions like localtime_r. | ||
| 2 | |||
| 3 | Copyright (C) 2003, 2006-2007, 2010-2011 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | This program is free software; you can redistribute it and/or modify | ||
| 6 | it under the terms of the GNU General Public License as published by | ||
| 7 | the Free Software Foundation; either version 3, or (at your option) | ||
| 8 | any later version. | ||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful, | ||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | GNU General Public License for more details. | ||
| 14 | |||
| 15 | You should have received a copy of the GNU General Public License along | ||
| 16 | with this program; if not, write to the Free Software Foundation, | ||
| 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
| 18 | |||
| 19 | /* Written by Paul Eggert. */ | ||
| 20 | |||
| 21 | #include <config.h> | ||
| 22 | |||
| 23 | #include <time.h> | ||
| 24 | |||
| 25 | static struct tm * | ||
| 26 | copy_tm_result (struct tm *dest, struct tm const *src) | ||
| 27 | { | ||
| 28 | if (! src) | ||
| 29 | return 0; | ||
| 30 | *dest = *src; | ||
| 31 | return dest; | ||
| 32 | } | ||
| 33 | |||
| 34 | |||
| 35 | struct tm * | ||
| 36 | gmtime_r (time_t const * restrict t, struct tm * restrict tp) | ||
| 37 | { | ||
| 38 | return copy_tm_result (tp, gmtime (t)); | ||
| 39 | } | ||
| 40 | |||
| 41 | struct tm * | ||
| 42 | localtime_r (time_t const * restrict t, struct tm * restrict tp) | ||
| 43 | { | ||
| 44 | return copy_tm_result (tp, localtime (t)); | ||
| 45 | } | ||