1989-03-17 21:42:05 -05:00
|
|
|
#ifndef PRIVATE_H
|
|
|
|
|
|
|
|
|
|
#define PRIVATE_H
|
|
|
|
|
|
1996-06-05 08:01:58 -04:00
|
|
|
/*
|
|
|
|
|
** This file is in the public domain, so clarified as of
|
2005-12-08 11:35:32 -05:00
|
|
|
** 1996-06-05 by Arthur David Olson.
|
1996-06-05 08:01:58 -04:00
|
|
|
*/
|
|
|
|
|
|
1989-03-17 21:42:05 -05:00
|
|
|
/*
|
1989-03-17 22:10:45 -05:00
|
|
|
** This header is for use ONLY with the time conversion code.
|
1989-03-17 21:42:05 -05:00
|
|
|
** There is no guarantee that it will remain unchanged,
|
1989-03-17 22:06:54 -05:00
|
|
|
** or that it will remain at all.
|
1989-03-17 21:42:05 -05:00
|
|
|
** Do NOT copy it to any system include directory.
|
|
|
|
|
** Thank you!
|
|
|
|
|
*/
|
|
|
|
|
|
2005-05-26 14:54:06 -04:00
|
|
|
#define GRANDPARENTED "Local time zone must be set--see zic manual page"
|
|
|
|
|
|
1995-01-06 17:01:53 -05:00
|
|
|
/*
|
1995-01-06 17:19:28 -05:00
|
|
|
** Defaults for preprocessor symbols.
|
Don't abuse "`" to mean open quote.
This was appropriate before Unicode, where "`" and "'" often balanced
in visual output, but that's been obsolete for a while.
Overall, single-quote 'like this' instead of `like this', and
double-quote "like this" or (in typeset output) “like this”
instead of ``like this''. While we're at it, fix some glitches
with hyphens versus minus versus en dash versus em dash.
* Makefile ($(MANTXTS)): Use UTF-8 locale to produce *.txt output.
* checktab.awk, tzselect.ksh:
Quote 'like this' in diagnostics, instead of `like this'.
* date.1, newctime.3, newtzset.3, time2posix.3, zic.8 (q, lq, rq):
New macros. Use them for better double-quoting in output.
* workman.sh: Tell Perl that its stdin and stdout are UTF-8.
* NEWS: Document this.
2014-06-15 13:27:37 -07:00
|
|
|
** You can override these in your C compiler options, e.g. '-DHAVE_ADJTIME=0'.
|
1995-01-03 11:08:20 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef HAVE_ADJTIME
|
1995-01-06 15:29:02 -05:00
|
|
|
#define HAVE_ADJTIME 1
|
1995-01-03 11:26:27 -05:00
|
|
|
#endif /* !defined HAVE_ADJTIME */
|
1995-01-06 15:29:02 -05:00
|
|
|
|
1996-02-21 15:47:23 -05:00
|
|
|
#ifndef HAVE_GETTEXT
|
|
|
|
|
#define HAVE_GETTEXT 0
|
|
|
|
|
#endif /* !defined HAVE_GETTEXT */
|
|
|
|
|
|
2000-04-17 12:53:08 -04:00
|
|
|
#ifndef HAVE_INCOMPATIBLE_CTIME_R
|
|
|
|
|
#define HAVE_INCOMPATIBLE_CTIME_R 0
|
|
|
|
|
#endif /* !defined INCOMPATIBLE_CTIME_R */
|
|
|
|
|
|
2013-09-25 17:49:49 -07:00
|
|
|
#ifndef HAVE_LINK
|
|
|
|
|
#define HAVE_LINK 1
|
2013-09-26 06:52:15 -07:00
|
|
|
#endif /* !defined HAVE_LINK */
|
2013-09-25 17:49:49 -07:00
|
|
|
|
1995-01-03 11:08:20 -05:00
|
|
|
#ifndef HAVE_SETTIMEOFDAY
|
|
|
|
|
#define HAVE_SETTIMEOFDAY 3
|
1995-01-03 11:26:27 -05:00
|
|
|
#endif /* !defined HAVE_SETTIMEOFDAY */
|
1995-01-03 11:08:20 -05:00
|
|
|
|
1998-02-02 12:05:09 -05:00
|
|
|
#ifndef HAVE_SYMLINK
|
|
|
|
|
#define HAVE_SYMLINK 1
|
|
|
|
|
#endif /* !defined HAVE_SYMLINK */
|
|
|
|
|
|
2001-06-05 13:48:08 -04:00
|
|
|
#ifndef HAVE_SYS_STAT_H
|
|
|
|
|
#define HAVE_SYS_STAT_H 1
|
|
|
|
|
#endif /* !defined HAVE_SYS_STAT_H */
|
|
|
|
|
|
1999-08-17 14:09:05 -04:00
|
|
|
#ifndef HAVE_SYS_WAIT_H
|
|
|
|
|
#define HAVE_SYS_WAIT_H 1
|
|
|
|
|
#endif /* !defined HAVE_SYS_WAIT_H */
|
|
|
|
|
|
1995-03-04 11:22:05 -05:00
|
|
|
#ifndef HAVE_UNISTD_H
|
|
|
|
|
#define HAVE_UNISTD_H 1
|
|
|
|
|
#endif /* !defined HAVE_UNISTD_H */
|
|
|
|
|
|
1996-01-10 16:44:45 -05:00
|
|
|
#ifndef HAVE_UTMPX_H
|
1996-01-10 16:46:40 -05:00
|
|
|
#define HAVE_UTMPX_H 0
|
1996-01-10 16:44:45 -05:00
|
|
|
#endif /* !defined HAVE_UTMPX_H */
|
|
|
|
|
|
1995-01-03 11:08:20 -05:00
|
|
|
#ifndef LOCALE_HOME
|
1995-01-06 15:29:02 -05:00
|
|
|
#define LOCALE_HOME "/usr/lib/locale"
|
1995-01-03 11:26:27 -05:00
|
|
|
#endif /* !defined LOCALE_HOME */
|
1995-01-03 11:08:20 -05:00
|
|
|
|
2000-04-17 12:53:08 -04:00
|
|
|
#if HAVE_INCOMPATIBLE_CTIME_R
|
|
|
|
|
#define asctime_r _incompatible_asctime_r
|
|
|
|
|
#define ctime_r _incompatible_ctime_r
|
|
|
|
|
#endif /* HAVE_INCOMPATIBLE_CTIME_R */
|
|
|
|
|
|
2014-08-19 18:16:15 -07:00
|
|
|
/* Enable tm_gmtoff and tm_zone on GNUish systems. */
|
|
|
|
|
#define _GNU_SOURCE 1
|
|
|
|
|
|
1995-03-04 11:22:05 -05:00
|
|
|
/*
|
|
|
|
|
** Nested includes
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "sys/types.h" /* for time_t */
|
|
|
|
|
#include "stdio.h"
|
|
|
|
|
#include "errno.h"
|
|
|
|
|
#include "string.h"
|
2006-02-20 09:53:12 -05:00
|
|
|
#include "limits.h" /* for CHAR_BIT et al. */
|
1995-03-04 11:22:05 -05:00
|
|
|
#include "time.h"
|
|
|
|
|
#include "stdlib.h"
|
|
|
|
|
|
2005-01-31 14:06:06 -05:00
|
|
|
#if HAVE_GETTEXT
|
1996-02-21 15:47:23 -05:00
|
|
|
#include "libintl.h"
|
2005-01-31 14:06:06 -05:00
|
|
|
#endif /* HAVE_GETTEXT */
|
1996-02-21 15:47:23 -05:00
|
|
|
|
2005-01-31 14:06:06 -05:00
|
|
|
#if HAVE_SYS_WAIT_H
|
1999-08-17 14:09:05 -04:00
|
|
|
#include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */
|
2005-01-31 14:06:06 -05:00
|
|
|
#endif /* HAVE_SYS_WAIT_H */
|
1999-08-17 14:09:05 -04:00
|
|
|
|
|
|
|
|
#ifndef WIFEXITED
|
|
|
|
|
#define WIFEXITED(status) (((status) & 0xff) == 0)
|
|
|
|
|
#endif /* !defined WIFEXITED */
|
|
|
|
|
#ifndef WEXITSTATUS
|
|
|
|
|
#define WEXITSTATUS(status) (((status) >> 8) & 0xff)
|
|
|
|
|
#endif /* !defined WEXITSTATUS */
|
|
|
|
|
|
2005-01-31 14:06:06 -05:00
|
|
|
#if HAVE_UNISTD_H
|
2007-12-03 09:42:13 -05:00
|
|
|
#include "unistd.h" /* for F_OK, R_OK, and other POSIX goodness */
|
2005-01-31 14:06:06 -05:00
|
|
|
#endif /* HAVE_UNISTD_H */
|
1995-03-04 11:22:05 -05:00
|
|
|
|
|
|
|
|
#ifndef F_OK
|
|
|
|
|
#define F_OK 0
|
|
|
|
|
#endif /* !defined F_OK */
|
|
|
|
|
#ifndef R_OK
|
|
|
|
|
#define R_OK 4
|
|
|
|
|
#endif /* !defined R_OK */
|
|
|
|
|
|
2005-01-31 14:06:06 -05:00
|
|
|
/* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
|
1995-10-30 10:19:57 -05:00
|
|
|
#define is_digit(c) ((unsigned)(c) - '0' <= 9)
|
|
|
|
|
|
2006-03-14 13:38:55 -05:00
|
|
|
/*
|
|
|
|
|
** Define HAVE_STDINT_H's default value here, rather than at the
|
|
|
|
|
** start, since __GLIBC__'s value depends on previously-included
|
|
|
|
|
** files.
|
|
|
|
|
** (glibc 2.1 and later have stdint.h, even with pre-C99 compilers.)
|
|
|
|
|
*/
|
|
|
|
|
#ifndef HAVE_STDINT_H
|
|
|
|
|
#define HAVE_STDINT_H \
|
2014-03-26 18:16:48 -07:00
|
|
|
(199901 <= __STDC_VERSION__ \
|
|
|
|
|
|| 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__) \
|
|
|
|
|
|| __CYGWIN__)
|
2006-03-14 13:38:55 -05:00
|
|
|
#endif /* !defined HAVE_STDINT_H */
|
|
|
|
|
|
2006-02-20 09:53:12 -05:00
|
|
|
#if HAVE_STDINT_H
|
2006-03-14 13:38:55 -05:00
|
|
|
#include "stdint.h"
|
2006-02-20 09:53:12 -05:00
|
|
|
#endif /* !HAVE_STDINT_H */
|
|
|
|
|
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
#ifndef HAVE_INTTYPES_H
|
|
|
|
|
# define HAVE_INTTYPES_H HAVE_STDINT_H
|
|
|
|
|
#endif
|
|
|
|
|
#if HAVE_INTTYPES_H
|
|
|
|
|
# include <inttypes.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-02-20 09:53:12 -05:00
|
|
|
#ifndef INT_FAST64_MAX
|
2006-03-14 13:38:55 -05:00
|
|
|
/* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */
|
|
|
|
|
#if defined LLONG_MAX || defined __LONG_LONG_MAX__
|
2006-02-20 09:53:12 -05:00
|
|
|
typedef long long int_fast64_t;
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
# ifdef LLONG_MAX
|
|
|
|
|
# define INT_FAST64_MIN LLONG_MIN
|
|
|
|
|
# define INT_FAST64_MAX LLONG_MAX
|
|
|
|
|
# else
|
2014-08-19 15:53:39 -07:00
|
|
|
# define INT_FAST64_MIN (-1 - __LONG_LONG_MAX__)
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
# define INT_FAST64_MAX __LONG_LONG_MAX__
|
|
|
|
|
# endif
|
|
|
|
|
# define SCNdFAST64 "lld"
|
2006-03-14 13:38:55 -05:00
|
|
|
#else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
|
|
|
|
|
#if (LONG_MAX >> 31) < 0xffffffff
|
|
|
|
|
Please use a compiler that supports a 64-bit integer type (or wider);
|
|
|
|
|
you may need to compile with "-DHAVE_STDINT_H".
|
|
|
|
|
#endif /* (LONG_MAX >> 31) < 0xffffffff */
|
2006-02-20 09:53:12 -05:00
|
|
|
typedef long int_fast64_t;
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
# define INT_FAST64_MIN LONG_MIN
|
|
|
|
|
# define INT_FAST64_MAX LONG_MAX
|
|
|
|
|
# define SCNdFAST64 "ld"
|
2006-03-14 13:38:55 -05:00
|
|
|
#endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
|
2006-02-20 09:53:12 -05:00
|
|
|
#endif /* !defined INT_FAST64_MAX */
|
|
|
|
|
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
#ifndef INT_FAST32_MAX
|
|
|
|
|
# if INT_MAX >> 31 == 0
|
|
|
|
|
typedef long int_fast32_t;
|
2014-08-14 21:52:01 -07:00
|
|
|
# define INT_FAST32_MAX LONG_MAX
|
|
|
|
|
# define INT_FAST32_MIN LONG_MIN
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
# else
|
|
|
|
|
typedef int int_fast32_t;
|
2014-08-14 21:52:01 -07:00
|
|
|
# define INT_FAST32_MAX INT_MAX
|
|
|
|
|
# define INT_FAST32_MIN INT_MIN
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef INTMAX_MAX
|
|
|
|
|
# if defined LLONG_MAX || defined __LONG_LONG_MAX__
|
|
|
|
|
typedef long long intmax_t;
|
Add FreeBSD-style -r option to 'date'.
* date.1: Document -r.
* date.c (main, usage): Support -r.
(main, reset): Remove EBUG code.
(display): New argument NOW. Do not exit; that's now the
caller's responsibility. All callers changed.
(display, timeout, convert, checkfinal, iffy):
Don't assume that localtime and gmtime succeed.
This prevents a core dump for, e.g., 'date -r 0xffffffffffffffff'.
* private.h: Include float.h.
(strtoimax): New macro, for pre-C99 systems that lack strtoimax.
(time_t_min, time_t_max): New constants, from zdump, with
different names to avoid a clash when zdump.c includes private.h.
2013-08-09 00:40:14 -07:00
|
|
|
# define strtoimax strtoll
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
# define PRIdMAX "lld"
|
2013-08-07 09:03:09 -07:00
|
|
|
# ifdef LLONG_MAX
|
|
|
|
|
# define INTMAX_MAX LLONG_MAX
|
|
|
|
|
# define INTMAX_MIN LLONG_MIN
|
|
|
|
|
# else
|
|
|
|
|
# define INTMAX_MAX __LONG_LONG_MAX__
|
2014-08-19 15:53:39 -07:00
|
|
|
# define INTMAX_MIN (-1 - __LONG_LONG_MAX__)
|
2013-08-07 09:03:09 -07:00
|
|
|
# endif
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
# else
|
|
|
|
|
typedef long intmax_t;
|
Add FreeBSD-style -r option to 'date'.
* date.1: Document -r.
* date.c (main, usage): Support -r.
(main, reset): Remove EBUG code.
(display): New argument NOW. Do not exit; that's now the
caller's responsibility. All callers changed.
(display, timeout, convert, checkfinal, iffy):
Don't assume that localtime and gmtime succeed.
This prevents a core dump for, e.g., 'date -r 0xffffffffffffffff'.
* private.h: Include float.h.
(strtoimax): New macro, for pre-C99 systems that lack strtoimax.
(time_t_min, time_t_max): New constants, from zdump, with
different names to avoid a clash when zdump.c includes private.h.
2013-08-09 00:40:14 -07:00
|
|
|
# define strtoimax strtol
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
# define PRIdMAX "ld"
|
2013-08-07 09:03:09 -07:00
|
|
|
# define INTMAX_MAX LONG_MAX
|
|
|
|
|
# define INTMAX_MIN LONG_MIN
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef UINTMAX_MAX
|
|
|
|
|
# if defined ULLONG_MAX || defined __LONG_LONG_MAX__
|
|
|
|
|
typedef unsigned long long uintmax_t;
|
|
|
|
|
# define PRIuMAX "llu"
|
|
|
|
|
# else
|
|
|
|
|
typedef unsigned long uintmax_t;
|
|
|
|
|
# define PRIuMAX "lu"
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-02-20 09:53:12 -05:00
|
|
|
#ifndef INT32_MAX
|
|
|
|
|
#define INT32_MAX 0x7fffffff
|
|
|
|
|
#endif /* !defined INT32_MAX */
|
|
|
|
|
#ifndef INT32_MIN
|
|
|
|
|
#define INT32_MIN (-1 - INT32_MAX)
|
|
|
|
|
#endif /* !defined INT32_MIN */
|
|
|
|
|
|
Check for integer overflow errors in zic.
Also, allocate memory faster by growing buffers by a factor of 1.5
each time, rather than simply adding 1 to the size.
* private.h (SIZE_MAX): New macro, for older systems lacking it.
* zic.c (nrules_alloc, nzones_alloc, nlinks_alloc): New static vars.
(memory_exhausted, size_product, growalloc): New functions.
(memcheck, inrule, inzsub, inlink, getfields): Use them.
2014-03-20 14:34:32 -07:00
|
|
|
#ifndef SIZE_MAX
|
|
|
|
|
#define SIZE_MAX ((size_t) -1)
|
|
|
|
|
#endif
|
|
|
|
|
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
#if 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
|
|
|
|
|
# define ATTRIBUTE_CONST __attribute__ ((const))
|
Assume C89.
* Makefile (GCC_DEBUG_FLAGS): Modernize for GCC 4.6.3 x86.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, wildinput, nondigit, oops, display)
(timeout, sametm, netsettime):
* difftime.c (difftime):
* ialloc.c (icatalloc, icpyalloc):
* localtime.c (detzcode, detzcode64, differ_by_repeat)
(tzload, typesequiv, getzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, gmtload, tzsetwall, tzset)
(localsub, localtime, localtime_r, gmtsub, gmtime, gmtime_r)
(offtime, leaps_thru_end_of, timesub, ctime, ctime_r)
(increment_overflow, long_increment_overflow)
(normalize_overflow, long_normalize_overflow, tmcomp, time2sub)
(time2, time1, mktime, timelocal, timegm, timeoff, gtime)
(leapcorr, time2posix, posix2time):
* scheck.c (scheck):
* strftime.c (strftime, _fmt, _conv, _add, _yconv, _loc):
* zdump.c (my_localtime, abbrok, usage, main, yeartot)
(delta, abbr, dumptime):
* zic.c (memcheck, eats, eat, error, warning, main)
(dolink, itsdir, rcomp, associate, infile, gethms, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert)
(convert64, puttzcode, puttzcode64, atcomp, is32, writezone, DO)
(doabbr, updateminmax, stringoffset, stringrule, stringzone)
(outzone, addtt, addtype, leapadd, yearistype, lowerit, ciequal)
(itsabbr, byword, getfields, oadd, tadd, rpytime, newabbr)
(mkdirs, eitol):
Assume C89 or better. Mostly this consists of using function
prototypes. In a few places, prototypes are required for
portability to hosts where time_t does not promote to itself and
where a preceding prototype does not override a definition. But
while we're at it we might as well be consistent: it's safe to
assume at-least-C89 these days.
* ialloc.c (nonzero, imalloc, icalloc, irealloc, ifree, icfree):
Remove; no longer needed now that we assume C89 or better.
All callers changed to use malloc, calloc, realloc, free.
* localtime.c (getzname, getqzname, leaps_thru_end_of, transtime):
* zdump.c (delta, yeartot):
* zic.c (eitol):
Now pure.
* private.h, zdump.c (ATTRIBUTE_PURE): New macro.
* private.h (icalloc, imalloc, irealloc, icfree, ifree): Remove decls.
* zic.c: Remove no-longer-necessary forward decls.
(max_time, min_time): Now const.
(setboundaries): Remove.
2012-10-12 07:53:12 -07:00
|
|
|
# define ATTRIBUTE_PURE __attribute__ ((__pure__))
|
2013-09-08 21:47:29 -07:00
|
|
|
# define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
|
Assume C89.
* Makefile (GCC_DEBUG_FLAGS): Modernize for GCC 4.6.3 x86.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, wildinput, nondigit, oops, display)
(timeout, sametm, netsettime):
* difftime.c (difftime):
* ialloc.c (icatalloc, icpyalloc):
* localtime.c (detzcode, detzcode64, differ_by_repeat)
(tzload, typesequiv, getzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, gmtload, tzsetwall, tzset)
(localsub, localtime, localtime_r, gmtsub, gmtime, gmtime_r)
(offtime, leaps_thru_end_of, timesub, ctime, ctime_r)
(increment_overflow, long_increment_overflow)
(normalize_overflow, long_normalize_overflow, tmcomp, time2sub)
(time2, time1, mktime, timelocal, timegm, timeoff, gtime)
(leapcorr, time2posix, posix2time):
* scheck.c (scheck):
* strftime.c (strftime, _fmt, _conv, _add, _yconv, _loc):
* zdump.c (my_localtime, abbrok, usage, main, yeartot)
(delta, abbr, dumptime):
* zic.c (memcheck, eats, eat, error, warning, main)
(dolink, itsdir, rcomp, associate, infile, gethms, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert)
(convert64, puttzcode, puttzcode64, atcomp, is32, writezone, DO)
(doabbr, updateminmax, stringoffset, stringrule, stringzone)
(outzone, addtt, addtype, leapadd, yearistype, lowerit, ciequal)
(itsabbr, byword, getfields, oadd, tadd, rpytime, newabbr)
(mkdirs, eitol):
Assume C89 or better. Mostly this consists of using function
prototypes. In a few places, prototypes are required for
portability to hosts where time_t does not promote to itself and
where a preceding prototype does not override a definition. But
while we're at it we might as well be consistent: it's safe to
assume at-least-C89 these days.
* ialloc.c (nonzero, imalloc, icalloc, irealloc, ifree, icfree):
Remove; no longer needed now that we assume C89 or better.
All callers changed to use malloc, calloc, realloc, free.
* localtime.c (getzname, getqzname, leaps_thru_end_of, transtime):
* zdump.c (delta, yeartot):
* zic.c (eitol):
Now pure.
* private.h, zdump.c (ATTRIBUTE_PURE): New macro.
* private.h (icalloc, imalloc, irealloc, icfree, ifree): Remove decls.
* zic.c: Remove no-longer-necessary forward decls.
(max_time, min_time): Now const.
(setboundaries): Remove.
2012-10-12 07:53:12 -07:00
|
|
|
#else
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
# define ATTRIBUTE_CONST /* empty */
|
Assume C89.
* Makefile (GCC_DEBUG_FLAGS): Modernize for GCC 4.6.3 x86.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, wildinput, nondigit, oops, display)
(timeout, sametm, netsettime):
* difftime.c (difftime):
* ialloc.c (icatalloc, icpyalloc):
* localtime.c (detzcode, detzcode64, differ_by_repeat)
(tzload, typesequiv, getzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, gmtload, tzsetwall, tzset)
(localsub, localtime, localtime_r, gmtsub, gmtime, gmtime_r)
(offtime, leaps_thru_end_of, timesub, ctime, ctime_r)
(increment_overflow, long_increment_overflow)
(normalize_overflow, long_normalize_overflow, tmcomp, time2sub)
(time2, time1, mktime, timelocal, timegm, timeoff, gtime)
(leapcorr, time2posix, posix2time):
* scheck.c (scheck):
* strftime.c (strftime, _fmt, _conv, _add, _yconv, _loc):
* zdump.c (my_localtime, abbrok, usage, main, yeartot)
(delta, abbr, dumptime):
* zic.c (memcheck, eats, eat, error, warning, main)
(dolink, itsdir, rcomp, associate, infile, gethms, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert)
(convert64, puttzcode, puttzcode64, atcomp, is32, writezone, DO)
(doabbr, updateminmax, stringoffset, stringrule, stringzone)
(outzone, addtt, addtype, leapadd, yearistype, lowerit, ciequal)
(itsabbr, byword, getfields, oadd, tadd, rpytime, newabbr)
(mkdirs, eitol):
Assume C89 or better. Mostly this consists of using function
prototypes. In a few places, prototypes are required for
portability to hosts where time_t does not promote to itself and
where a preceding prototype does not override a definition. But
while we're at it we might as well be consistent: it's safe to
assume at-least-C89 these days.
* ialloc.c (nonzero, imalloc, icalloc, irealloc, ifree, icfree):
Remove; no longer needed now that we assume C89 or better.
All callers changed to use malloc, calloc, realloc, free.
* localtime.c (getzname, getqzname, leaps_thru_end_of, transtime):
* zdump.c (delta, yeartot):
* zic.c (eitol):
Now pure.
* private.h, zdump.c (ATTRIBUTE_PURE): New macro.
* private.h (icalloc, imalloc, irealloc, icfree, ifree): Remove decls.
* zic.c: Remove no-longer-necessary forward decls.
(max_time, min_time): Now const.
(setboundaries): Remove.
2012-10-12 07:53:12 -07:00
|
|
|
# define ATTRIBUTE_PURE /* empty */
|
2013-09-08 21:47:29 -07:00
|
|
|
# define ATTRIBUTE_FORMAT(spec) /* empty */
|
Assume C89.
* Makefile (GCC_DEBUG_FLAGS): Modernize for GCC 4.6.3 x86.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, wildinput, nondigit, oops, display)
(timeout, sametm, netsettime):
* difftime.c (difftime):
* ialloc.c (icatalloc, icpyalloc):
* localtime.c (detzcode, detzcode64, differ_by_repeat)
(tzload, typesequiv, getzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, gmtload, tzsetwall, tzset)
(localsub, localtime, localtime_r, gmtsub, gmtime, gmtime_r)
(offtime, leaps_thru_end_of, timesub, ctime, ctime_r)
(increment_overflow, long_increment_overflow)
(normalize_overflow, long_normalize_overflow, tmcomp, time2sub)
(time2, time1, mktime, timelocal, timegm, timeoff, gtime)
(leapcorr, time2posix, posix2time):
* scheck.c (scheck):
* strftime.c (strftime, _fmt, _conv, _add, _yconv, _loc):
* zdump.c (my_localtime, abbrok, usage, main, yeartot)
(delta, abbr, dumptime):
* zic.c (memcheck, eats, eat, error, warning, main)
(dolink, itsdir, rcomp, associate, infile, gethms, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert)
(convert64, puttzcode, puttzcode64, atcomp, is32, writezone, DO)
(doabbr, updateminmax, stringoffset, stringrule, stringzone)
(outzone, addtt, addtype, leapadd, yearistype, lowerit, ciequal)
(itsabbr, byword, getfields, oadd, tadd, rpytime, newabbr)
(mkdirs, eitol):
Assume C89 or better. Mostly this consists of using function
prototypes. In a few places, prototypes are required for
portability to hosts where time_t does not promote to itself and
where a preceding prototype does not override a definition. But
while we're at it we might as well be consistent: it's safe to
assume at-least-C89 these days.
* ialloc.c (nonzero, imalloc, icalloc, irealloc, ifree, icfree):
Remove; no longer needed now that we assume C89 or better.
All callers changed to use malloc, calloc, realloc, free.
* localtime.c (getzname, getqzname, leaps_thru_end_of, transtime):
* zdump.c (delta, yeartot):
* zic.c (eitol):
Now pure.
* private.h, zdump.c (ATTRIBUTE_PURE): New macro.
* private.h (icalloc, imalloc, irealloc, icfree, ifree): Remove decls.
* zic.c: Remove no-longer-necessary forward decls.
(max_time, min_time): Now const.
(setboundaries): Remove.
2012-10-12 07:53:12 -07:00
|
|
|
#endif
|
|
|
|
|
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
#if !defined _Noreturn && __STDC_VERSION__ < 201112
|
|
|
|
|
# if 2 < __GNUC__ + (8 <= __GNUC_MINOR__)
|
|
|
|
|
# define _Noreturn __attribute__ ((__noreturn__))
|
|
|
|
|
# else
|
|
|
|
|
# define _Noreturn
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
Add support for testing time_t types other than the system's.
This makes it easier to test on (say) Debian, even if we're
testing the time_t type on (say) NetBSD. NetBSD uses 64-bit
time_t on 32-bit hosts, and this lets us test a NetBSD-style
implementation (32-bit 'long', 64-bit time_t) on a 32-bit Debian host.
* Makefile: Update comments to talk about TIME_T_FLOATING and time_tz.
Sort the comments.
* private.h (restrict): Define to empty with older compilers.
'restrict' is now needed, to define gmtime_r and localtime_r in
standard ways when time_tz is defined.
Make the following changes if time_tz is defined:
(sys_time, time): New static functions. The former is the system
'time' function that applies to the system time_t, the latter
our function that applies to our time_t.
(time_t, ctime, ctime_r, difftime, gmtime, gmtime_r, localtime)
(localtime_r, mktime): Rename to tz_time_t, tz_ctime, etc.,
via macros. Declare the renamed versions.
* zdump.8: Document new options -V, -t.
* zdump.c: Include private.h if time_tz is defined.
(INITIALIZE): Remove; no longer needed.
(absolute_min_time, absolute_max_time): Work even if time_t
is wider than intmax_t, which can be true with GCC and __int128_t.
Use the new TIME_T_FLOATING macro for this.
(usage): Document new flags.
(main): Support them.
2013-05-27 14:01:55 -07:00
|
|
|
#if __STDC_VERSION__ < 199901 && !defined restrict
|
|
|
|
|
# define restrict /* empty */
|
|
|
|
|
#endif
|
|
|
|
|
|
1989-03-17 21:42:05 -05:00
|
|
|
/*
|
1995-01-06 16:21:56 -05:00
|
|
|
** Workarounds for compilers/systems.
|
1989-03-17 21:42:05 -05:00
|
|
|
*/
|
|
|
|
|
|
Add support for testing time_t types other than the system's.
This makes it easier to test on (say) Debian, even if we're
testing the time_t type on (say) NetBSD. NetBSD uses 64-bit
time_t on 32-bit hosts, and this lets us test a NetBSD-style
implementation (32-bit 'long', 64-bit time_t) on a 32-bit Debian host.
* Makefile: Update comments to talk about TIME_T_FLOATING and time_tz.
Sort the comments.
* private.h (restrict): Define to empty with older compilers.
'restrict' is now needed, to define gmtime_r and localtime_r in
standard ways when time_tz is defined.
Make the following changes if time_tz is defined:
(sys_time, time): New static functions. The former is the system
'time' function that applies to the system time_t, the latter
our function that applies to our time_t.
(time_t, ctime, ctime_r, difftime, gmtime, gmtime_r, localtime)
(localtime_r, mktime): Rename to tz_time_t, tz_ctime, etc.,
via macros. Declare the renamed versions.
* zdump.8: Document new options -V, -t.
* zdump.c: Include private.h if time_tz is defined.
(INITIALIZE): Remove; no longer needed.
(absolute_min_time, absolute_max_time): Work even if time_t
is wider than intmax_t, which can be true with GCC and __int128_t.
Use the new TIME_T_FLOATING macro for this.
(usage): Document new flags.
(main): Support them.
2013-05-27 14:01:55 -07:00
|
|
|
/*
|
|
|
|
|
** Compile with -Dtime_tz=T to build the tz package with a private
|
|
|
|
|
** time_t type equivalent to T rather than the system-supplied time_t.
|
|
|
|
|
** This debugging feature can test unusual design decisions
|
|
|
|
|
** (e.g., time_t wider than 'long', or unsigned time_t) even on
|
|
|
|
|
** typical platforms.
|
|
|
|
|
*/
|
|
|
|
|
#ifdef time_tz
|
2014-08-16 01:57:33 -07:00
|
|
|
# ifdef LOCALTIME_IMPLEMENTATION
|
Add support for testing time_t types other than the system's.
This makes it easier to test on (say) Debian, even if we're
testing the time_t type on (say) NetBSD. NetBSD uses 64-bit
time_t on 32-bit hosts, and this lets us test a NetBSD-style
implementation (32-bit 'long', 64-bit time_t) on a 32-bit Debian host.
* Makefile: Update comments to talk about TIME_T_FLOATING and time_tz.
Sort the comments.
* private.h (restrict): Define to empty with older compilers.
'restrict' is now needed, to define gmtime_r and localtime_r in
standard ways when time_tz is defined.
Make the following changes if time_tz is defined:
(sys_time, time): New static functions. The former is the system
'time' function that applies to the system time_t, the latter
our function that applies to our time_t.
(time_t, ctime, ctime_r, difftime, gmtime, gmtime_r, localtime)
(localtime_r, mktime): Rename to tz_time_t, tz_ctime, etc.,
via macros. Declare the renamed versions.
* zdump.8: Document new options -V, -t.
* zdump.c: Include private.h if time_tz is defined.
(INITIALIZE): Remove; no longer needed.
(absolute_min_time, absolute_max_time): Work even if time_t
is wider than intmax_t, which can be true with GCC and __int128_t.
Use the new TIME_T_FLOATING macro for this.
(usage): Document new flags.
(main): Support them.
2013-05-27 14:01:55 -07:00
|
|
|
static time_t sys_time(time_t *x) { return time(x); }
|
2014-08-16 01:57:33 -07:00
|
|
|
# endif
|
Add support for testing time_t types other than the system's.
This makes it easier to test on (say) Debian, even if we're
testing the time_t type on (say) NetBSD. NetBSD uses 64-bit
time_t on 32-bit hosts, and this lets us test a NetBSD-style
implementation (32-bit 'long', 64-bit time_t) on a 32-bit Debian host.
* Makefile: Update comments to talk about TIME_T_FLOATING and time_tz.
Sort the comments.
* private.h (restrict): Define to empty with older compilers.
'restrict' is now needed, to define gmtime_r and localtime_r in
standard ways when time_tz is defined.
Make the following changes if time_tz is defined:
(sys_time, time): New static functions. The former is the system
'time' function that applies to the system time_t, the latter
our function that applies to our time_t.
(time_t, ctime, ctime_r, difftime, gmtime, gmtime_r, localtime)
(localtime_r, mktime): Rename to tz_time_t, tz_ctime, etc.,
via macros. Declare the renamed versions.
* zdump.8: Document new options -V, -t.
* zdump.c: Include private.h if time_tz is defined.
(INITIALIZE): Remove; no longer needed.
(absolute_min_time, absolute_max_time): Work even if time_t
is wider than intmax_t, which can be true with GCC and __int128_t.
Use the new TIME_T_FLOATING macro for this.
(usage): Document new flags.
(main): Support them.
2013-05-27 14:01:55 -07:00
|
|
|
|
|
|
|
|
# undef ctime
|
|
|
|
|
# define ctime tz_ctime
|
|
|
|
|
# undef ctime_r
|
|
|
|
|
# define ctime_r tz_ctime_r
|
|
|
|
|
# undef difftime
|
|
|
|
|
# define difftime tz_difftime
|
|
|
|
|
# undef gmtime
|
|
|
|
|
# define gmtime tz_gmtime
|
|
|
|
|
# undef gmtime_r
|
|
|
|
|
# define gmtime_r tz_gmtime_r
|
|
|
|
|
# undef localtime
|
|
|
|
|
# define localtime tz_localtime
|
|
|
|
|
# undef localtime_r
|
|
|
|
|
# define localtime_r tz_localtime_r
|
|
|
|
|
# undef mktime
|
|
|
|
|
# define mktime tz_mktime
|
2014-08-14 21:32:56 -07:00
|
|
|
# undef offtime
|
|
|
|
|
# define offtime tz_offtime
|
|
|
|
|
# undef posix2time
|
|
|
|
|
# define posix2time tz_posix2time
|
Add support for testing time_t types other than the system's.
This makes it easier to test on (say) Debian, even if we're
testing the time_t type on (say) NetBSD. NetBSD uses 64-bit
time_t on 32-bit hosts, and this lets us test a NetBSD-style
implementation (32-bit 'long', 64-bit time_t) on a 32-bit Debian host.
* Makefile: Update comments to talk about TIME_T_FLOATING and time_tz.
Sort the comments.
* private.h (restrict): Define to empty with older compilers.
'restrict' is now needed, to define gmtime_r and localtime_r in
standard ways when time_tz is defined.
Make the following changes if time_tz is defined:
(sys_time, time): New static functions. The former is the system
'time' function that applies to the system time_t, the latter
our function that applies to our time_t.
(time_t, ctime, ctime_r, difftime, gmtime, gmtime_r, localtime)
(localtime_r, mktime): Rename to tz_time_t, tz_ctime, etc.,
via macros. Declare the renamed versions.
* zdump.8: Document new options -V, -t.
* zdump.c: Include private.h if time_tz is defined.
(INITIALIZE): Remove; no longer needed.
(absolute_min_time, absolute_max_time): Work even if time_t
is wider than intmax_t, which can be true with GCC and __int128_t.
Use the new TIME_T_FLOATING macro for this.
(usage): Document new flags.
(main): Support them.
2013-05-27 14:01:55 -07:00
|
|
|
# undef time
|
|
|
|
|
# define time tz_time
|
2014-08-14 21:32:56 -07:00
|
|
|
# undef time2posix
|
|
|
|
|
# define time2posix tz_time2posix
|
Add support for testing time_t types other than the system's.
This makes it easier to test on (say) Debian, even if we're
testing the time_t type on (say) NetBSD. NetBSD uses 64-bit
time_t on 32-bit hosts, and this lets us test a NetBSD-style
implementation (32-bit 'long', 64-bit time_t) on a 32-bit Debian host.
* Makefile: Update comments to talk about TIME_T_FLOATING and time_tz.
Sort the comments.
* private.h (restrict): Define to empty with older compilers.
'restrict' is now needed, to define gmtime_r and localtime_r in
standard ways when time_tz is defined.
Make the following changes if time_tz is defined:
(sys_time, time): New static functions. The former is the system
'time' function that applies to the system time_t, the latter
our function that applies to our time_t.
(time_t, ctime, ctime_r, difftime, gmtime, gmtime_r, localtime)
(localtime_r, mktime): Rename to tz_time_t, tz_ctime, etc.,
via macros. Declare the renamed versions.
* zdump.8: Document new options -V, -t.
* zdump.c: Include private.h if time_tz is defined.
(INITIALIZE): Remove; no longer needed.
(absolute_min_time, absolute_max_time): Work even if time_t
is wider than intmax_t, which can be true with GCC and __int128_t.
Use the new TIME_T_FLOATING macro for this.
(usage): Document new flags.
(main): Support them.
2013-05-27 14:01:55 -07:00
|
|
|
# undef time_t
|
|
|
|
|
# define time_t tz_time_t
|
2014-08-16 19:37:12 -07:00
|
|
|
# undef timegm
|
|
|
|
|
# define timegm tz_timegm
|
|
|
|
|
# undef timelocal
|
|
|
|
|
# define timelocal tz_timelocal
|
2014-08-14 21:32:56 -07:00
|
|
|
# undef timeoff
|
|
|
|
|
# define timeoff tz_timeoff
|
Add support for testing time_t types other than the system's.
This makes it easier to test on (say) Debian, even if we're
testing the time_t type on (say) NetBSD. NetBSD uses 64-bit
time_t on 32-bit hosts, and this lets us test a NetBSD-style
implementation (32-bit 'long', 64-bit time_t) on a 32-bit Debian host.
* Makefile: Update comments to talk about TIME_T_FLOATING and time_tz.
Sort the comments.
* private.h (restrict): Define to empty with older compilers.
'restrict' is now needed, to define gmtime_r and localtime_r in
standard ways when time_tz is defined.
Make the following changes if time_tz is defined:
(sys_time, time): New static functions. The former is the system
'time' function that applies to the system time_t, the latter
our function that applies to our time_t.
(time_t, ctime, ctime_r, difftime, gmtime, gmtime_r, localtime)
(localtime_r, mktime): Rename to tz_time_t, tz_ctime, etc.,
via macros. Declare the renamed versions.
* zdump.8: Document new options -V, -t.
* zdump.c: Include private.h if time_tz is defined.
(INITIALIZE): Remove; no longer needed.
(absolute_min_time, absolute_max_time): Work even if time_t
is wider than intmax_t, which can be true with GCC and __int128_t.
Use the new TIME_T_FLOATING macro for this.
(usage): Document new flags.
(main): Support them.
2013-05-27 14:01:55 -07:00
|
|
|
|
|
|
|
|
typedef time_tz time_t;
|
|
|
|
|
|
|
|
|
|
char *ctime(time_t const *);
|
|
|
|
|
char *ctime_r(time_t const *, char *);
|
|
|
|
|
double difftime(time_t, time_t);
|
|
|
|
|
struct tm *gmtime(time_t const *);
|
|
|
|
|
struct tm *gmtime_r(time_t const *restrict, struct tm *restrict);
|
|
|
|
|
struct tm *localtime(time_t const *);
|
|
|
|
|
struct tm *localtime_r(time_t const *restrict, struct tm *restrict);
|
|
|
|
|
time_t mktime(struct tm *);
|
2014-08-16 01:57:33 -07:00
|
|
|
time_t time(time_t *);
|
Add support for testing time_t types other than the system's.
This makes it easier to test on (say) Debian, even if we're
testing the time_t type on (say) NetBSD. NetBSD uses 64-bit
time_t on 32-bit hosts, and this lets us test a NetBSD-style
implementation (32-bit 'long', 64-bit time_t) on a 32-bit Debian host.
* Makefile: Update comments to talk about TIME_T_FLOATING and time_tz.
Sort the comments.
* private.h (restrict): Define to empty with older compilers.
'restrict' is now needed, to define gmtime_r and localtime_r in
standard ways when time_tz is defined.
Make the following changes if time_tz is defined:
(sys_time, time): New static functions. The former is the system
'time' function that applies to the system time_t, the latter
our function that applies to our time_t.
(time_t, ctime, ctime_r, difftime, gmtime, gmtime_r, localtime)
(localtime_r, mktime): Rename to tz_time_t, tz_ctime, etc.,
via macros. Declare the renamed versions.
* zdump.8: Document new options -V, -t.
* zdump.c: Include private.h if time_tz is defined.
(INITIALIZE): Remove; no longer needed.
(absolute_min_time, absolute_max_time): Work even if time_t
is wider than intmax_t, which can be true with GCC and __int128_t.
Use the new TIME_T_FLOATING macro for this.
(usage): Document new flags.
(main): Support them.
2013-05-27 14:01:55 -07:00
|
|
|
#endif
|
|
|
|
|
|
2014-08-14 21:32:56 -07:00
|
|
|
/*
|
|
|
|
|
** Some time.h implementations don't declare asctime_r.
|
|
|
|
|
** Others might define it as a macro.
|
|
|
|
|
** Fix the former without affecting the latter.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef asctime_r
|
|
|
|
|
extern char * asctime_r(struct tm const *, char *);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
** The STD_INSPIRED functions are similar, but most also need
|
|
|
|
|
** declarations if time_tz is defined.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef STD_INSPIRED
|
|
|
|
|
# if !defined tzsetwall
|
|
|
|
|
void tzsetwall(void);
|
|
|
|
|
# endif
|
|
|
|
|
# if !defined offtime || defined time_tz
|
|
|
|
|
struct tm *offtime(time_t const *, long);
|
|
|
|
|
# endif
|
2014-08-16 19:37:12 -07:00
|
|
|
# if !defined timegm || defined time_tz
|
|
|
|
|
time_t timegm(struct tm *);
|
|
|
|
|
# endif
|
|
|
|
|
# if !defined timelocal || defined time_tz
|
|
|
|
|
time_t timelocal(struct tm *);
|
|
|
|
|
# endif
|
2014-08-14 21:32:56 -07:00
|
|
|
# if !defined timeoff || defined time_tz
|
|
|
|
|
time_t timeoff(struct tm *, long);
|
|
|
|
|
# endif
|
|
|
|
|
# if !defined time2posix || defined time_tz
|
|
|
|
|
time_t time2posix(time_t);
|
|
|
|
|
# endif
|
|
|
|
|
# if !defined posix2time || defined time_tz
|
|
|
|
|
time_t posix2time(time_t);
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-08-19 18:16:15 -07:00
|
|
|
/* Infer TM_ZONE on systems where this information is known, but suppress
|
|
|
|
|
guessing if NO_TM_ZONE is defined. Similarly for TM_GMTOFF. */
|
|
|
|
|
#if (defined __GLIBC__ \
|
|
|
|
|
|| defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
|
|
|
|
|
|| (defined __APPLE__ && defined __MACH__))
|
|
|
|
|
# if !defined TM_GMTOFF && !defined NO_TM_GMTOFF
|
|
|
|
|
# define TM_GMTOFF tm_gmtoff
|
|
|
|
|
# endif
|
|
|
|
|
# if !defined TM_ZONE && !defined NO_TM_ZONE
|
|
|
|
|
# define TM_ZONE tm_zone
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
1997-03-03 12:11:26 -05:00
|
|
|
/*
|
|
|
|
|
** Private function declarations.
|
|
|
|
|
*/
|
2004-10-26 12:23:03 -04:00
|
|
|
|
2007-11-08 09:21:57 -05:00
|
|
|
char * icatalloc(char * old, const char * new);
|
|
|
|
|
char * icpyalloc(const char * string);
|
|
|
|
|
const char * scheck(const char * string, const char * format);
|
1997-03-03 12:11:26 -05:00
|
|
|
|
1995-01-06 16:21:56 -05:00
|
|
|
/*
|
|
|
|
|
** Finally, some convenience items.
|
|
|
|
|
*/
|
1989-03-17 21:42:05 -05:00
|
|
|
|
1989-03-22 18:09:56 -05:00
|
|
|
#ifndef TRUE
|
|
|
|
|
#define TRUE 1
|
|
|
|
|
#endif /* !defined TRUE */
|
|
|
|
|
|
|
|
|
|
#ifndef FALSE
|
|
|
|
|
#define FALSE 0
|
|
|
|
|
#endif /* !defined FALSE */
|
|
|
|
|
|
1996-01-06 13:41:43 -05:00
|
|
|
#ifndef TYPE_BIT
|
|
|
|
|
#define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
|
|
|
|
|
#endif /* !defined TYPE_BIT */
|
|
|
|
|
|
|
|
|
|
#ifndef TYPE_SIGNED
|
|
|
|
|
#define TYPE_SIGNED(type) (((type) -1) < 0)
|
|
|
|
|
#endif /* !defined TYPE_SIGNED */
|
|
|
|
|
|
Add FreeBSD-style -r option to 'date'.
* date.1: Document -r.
* date.c (main, usage): Support -r.
(main, reset): Remove EBUG code.
(display): New argument NOW. Do not exit; that's now the
caller's responsibility. All callers changed.
(display, timeout, convert, checkfinal, iffy):
Don't assume that localtime and gmtime succeed.
This prevents a core dump for, e.g., 'date -r 0xffffffffffffffff'.
* private.h: Include float.h.
(strtoimax): New macro, for pre-C99 systems that lack strtoimax.
(time_t_min, time_t_max): New constants, from zdump, with
different names to avoid a clash when zdump.c includes private.h.
2013-08-09 00:40:14 -07:00
|
|
|
/* The minimum and maximum finite time values. */
|
|
|
|
|
static time_t const time_t_min =
|
Remove attempt to support floating-point time_t.
It wasn't tested and probably never worked, no platform used it,
and the latest POSIX no longer allows it.
* Makefile (typecheck): Don't check time_t being 'double'.
* Theory: Document the change.
* difftime.c (difftime):
* localtime.c (differ_by_repeat, tzload, timesub, time2sub):
* private.h (time_t_min, time_t_max):
* zdump.c (absolute_min_time, absolute_max_time, tformat):
Don't try to support floating-point time_t.
* localtime.c, private.h, zdump.c: Don't include float.h.
* localtime.c (truncate_time, double_to_time):
* private.h (TYPE_INTEGRAL):
* zdump.c (checkabsolutes):
Remove; no longer needed. All uses removed.
* zdump.8 (LIMITATIONS): Remove discussion of floating-point time_t.
2013-08-12 01:41:34 -07:00
|
|
|
(TYPE_SIGNED(time_t)
|
Add FreeBSD-style -r option to 'date'.
* date.1: Document -r.
* date.c (main, usage): Support -r.
(main, reset): Remove EBUG code.
(display): New argument NOW. Do not exit; that's now the
caller's responsibility. All callers changed.
(display, timeout, convert, checkfinal, iffy):
Don't assume that localtime and gmtime succeed.
This prevents a core dump for, e.g., 'date -r 0xffffffffffffffff'.
* private.h: Include float.h.
(strtoimax): New macro, for pre-C99 systems that lack strtoimax.
(time_t_min, time_t_max): New constants, from zdump, with
different names to avoid a clash when zdump.c includes private.h.
2013-08-09 00:40:14 -07:00
|
|
|
? (time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1)
|
|
|
|
|
: 0);
|
|
|
|
|
static time_t const time_t_max =
|
Remove attempt to support floating-point time_t.
It wasn't tested and probably never worked, no platform used it,
and the latest POSIX no longer allows it.
* Makefile (typecheck): Don't check time_t being 'double'.
* Theory: Document the change.
* difftime.c (difftime):
* localtime.c (differ_by_repeat, tzload, timesub, time2sub):
* private.h (time_t_min, time_t_max):
* zdump.c (absolute_min_time, absolute_max_time, tformat):
Don't try to support floating-point time_t.
* localtime.c, private.h, zdump.c: Don't include float.h.
* localtime.c (truncate_time, double_to_time):
* private.h (TYPE_INTEGRAL):
* zdump.c (checkabsolutes):
Remove; no longer needed. All uses removed.
* zdump.8 (LIMITATIONS): Remove discussion of floating-point time_t.
2013-08-12 01:41:34 -07:00
|
|
|
(TYPE_SIGNED(time_t)
|
Add FreeBSD-style -r option to 'date'.
* date.1: Document -r.
* date.c (main, usage): Support -r.
(main, reset): Remove EBUG code.
(display): New argument NOW. Do not exit; that's now the
caller's responsibility. All callers changed.
(display, timeout, convert, checkfinal, iffy):
Don't assume that localtime and gmtime succeed.
This prevents a core dump for, e.g., 'date -r 0xffffffffffffffff'.
* private.h: Include float.h.
(strtoimax): New macro, for pre-C99 systems that lack strtoimax.
(time_t_min, time_t_max): New constants, from zdump, with
different names to avoid a clash when zdump.c includes private.h.
2013-08-09 00:40:14 -07:00
|
|
|
? - (~ 0 < 0) - ((time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1))
|
|
|
|
|
: -1);
|
|
|
|
|
|
1993-05-29 20:18:37 -04:00
|
|
|
#ifndef INT_STRLEN_MAXIMUM
|
1993-05-30 16:25:00 -04:00
|
|
|
/*
|
|
|
|
|
** 302 / 1000 is log10(2.0) rounded up.
|
1996-01-06 13:28:07 -05:00
|
|
|
** Subtract one for the sign bit if the type is signed;
|
|
|
|
|
** add one for integer division truncation;
|
|
|
|
|
** add one more for a minus sign if the type is signed.
|
1993-05-30 16:25:00 -04:00
|
|
|
*/
|
|
|
|
|
#define INT_STRLEN_MAXIMUM(type) \
|
2005-01-31 14:06:06 -05:00
|
|
|
((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
|
|
|
|
|
1 + TYPE_SIGNED(type))
|
1993-05-29 20:18:37 -04:00
|
|
|
#endif /* !defined INT_STRLEN_MAXIMUM */
|
|
|
|
|
|
1995-01-06 16:21:56 -05:00
|
|
|
/*
|
|
|
|
|
** INITIALIZE(x)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef lint
|
2014-06-18 23:25:57 -07:00
|
|
|
# define INITIALIZE(x) ((x) = 0)
|
|
|
|
|
#else
|
|
|
|
|
# define INITIALIZE(x)
|
|
|
|
|
#endif
|
1995-01-06 16:21:56 -05:00
|
|
|
|
1996-02-19 19:26:00 -05:00
|
|
|
/*
|
|
|
|
|
** For the benefit of GNU folk...
|
Don't abuse "`" to mean open quote.
This was appropriate before Unicode, where "`" and "'" often balanced
in visual output, but that's been obsolete for a while.
Overall, single-quote 'like this' instead of `like this', and
double-quote "like this" or (in typeset output) “like this”
instead of ``like this''. While we're at it, fix some glitches
with hyphens versus minus versus en dash versus em dash.
* Makefile ($(MANTXTS)): Use UTF-8 locale to produce *.txt output.
* checktab.awk, tzselect.ksh:
Quote 'like this' in diagnostics, instead of `like this'.
* date.1, newctime.3, newtzset.3, time2posix.3, zic.8 (q, lq, rq):
New macros. Use them for better double-quoting in output.
* workman.sh: Tell Perl that its stdin and stdout are UTF-8.
* NEWS: Document this.
2014-06-15 13:27:37 -07:00
|
|
|
** '_(MSGID)' uses the current locale's message library string for MSGID.
|
1996-02-21 15:47:23 -05:00
|
|
|
** The default is to use gettext if available, and use MSGID otherwise.
|
1996-02-19 19:26:00 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef _
|
2005-01-31 14:06:06 -05:00
|
|
|
#if HAVE_GETTEXT
|
1996-02-21 15:47:23 -05:00
|
|
|
#define _(msgid) gettext(msgid)
|
2005-01-31 14:06:06 -05:00
|
|
|
#else /* !HAVE_GETTEXT */
|
1996-02-21 15:47:23 -05:00
|
|
|
#define _(msgid) msgid
|
2005-01-31 14:06:06 -05:00
|
|
|
#endif /* !HAVE_GETTEXT */
|
1996-02-19 19:26:00 -05:00
|
|
|
#endif /* !defined _ */
|
|
|
|
|
|
2014-06-26 15:19:00 -07:00
|
|
|
#if !defined TZ_DOMAIN && defined HAVE_GETTEXT
|
2014-06-18 23:25:57 -07:00
|
|
|
# define TZ_DOMAIN "tz"
|
|
|
|
|
#endif
|
1996-02-21 15:47:23 -05:00
|
|
|
|
2000-04-17 12:53:08 -04:00
|
|
|
#if HAVE_INCOMPATIBLE_CTIME_R
|
|
|
|
|
#undef asctime_r
|
|
|
|
|
#undef ctime_r
|
2007-11-08 09:21:57 -05:00
|
|
|
char *asctime_r(struct tm const *, char *);
|
|
|
|
|
char *ctime_r(time_t const *, char *);
|
2000-04-17 12:53:08 -04:00
|
|
|
#endif /* HAVE_INCOMPATIBLE_CTIME_R */
|
|
|
|
|
|
2006-02-20 09:53:12 -05:00
|
|
|
#ifndef YEARSPERREPEAT
|
|
|
|
|
#define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
|
|
|
|
|
#endif /* !defined YEARSPERREPEAT */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef AVGSECSPERYEAR
|
|
|
|
|
#define AVGSECSPERYEAR 31556952L
|
|
|
|
|
#endif /* !defined AVGSECSPERYEAR */
|
|
|
|
|
|
|
|
|
|
#ifndef SECSPERREPEAT
|
|
|
|
|
#define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
|
|
|
|
|
#endif /* !defined SECSPERREPEAT */
|
2007-03-15 09:55:13 -04:00
|
|
|
|
2006-02-20 09:53:12 -05:00
|
|
|
#ifndef SECSPERREPEAT_BITS
|
|
|
|
|
#define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */
|
|
|
|
|
#endif /* !defined SECSPERREPEAT_BITS */
|
|
|
|
|
|
1989-03-17 21:42:05 -05:00
|
|
|
#endif /* !defined PRIVATE_H */
|