PostgreSQL Source Code git master
zic.c File Reference
#include "postgres_fe.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <time.h>
#include "pg_getopt.h"
#include "private.h"
#include "tzfile.h"
Include dependency graph for zic.c:

Go to the source code of this file.

Data Structures

struct  rule
 
struct  zone
 
struct  link
 
struct  lookup
 
struct  attype
 
struct  timerange
 

Macros

#define ZIC_VERSION_PRE_2013   '2'
 
#define ZIC_VERSION   '3'
 
#define ZIC_MIN   PG_INT64_MIN
 
#define ZIC_MAX   PG_INT64_MAX
 
#define ZIC_MAX_ABBR_LEN_WO_WARN   6
 
#define MKDIR_UMASK   0755
 
#define DC_DOM   0 /* 1..31 */ /* unused */
 
#define DC_DOWGEQ   1 /* 1..31 */ /* 0..6 (Sun..Sat) */
 
#define DC_DOWLEQ   2 /* 1..31 */ /* 0..6 (Sun..Sat) */
 
#define linkat(targetdir, target, linknamedir, linkname, flag)    (itssymlink(target) ? (errno = ENOTSUP, -1) : link(target, linkname))
 
#define LC_RULE   0
 
#define LC_ZONE   1
 
#define LC_LINK   2
 
#define LC_LEAP   3
 
#define LC_EXPIRES   4
 
#define ZF_NAME   1
 
#define ZF_STDOFF   2
 
#define ZF_RULE   3
 
#define ZF_FORMAT   4
 
#define ZF_TILYEAR   5
 
#define ZF_TILMONTH   6
 
#define ZF_TILDAY   7
 
#define ZF_TILTIME   8
 
#define ZONE_MINFIELDS   5
 
#define ZONE_MAXFIELDS   9
 
#define ZFC_STDOFF   0
 
#define ZFC_RULE   1
 
#define ZFC_FORMAT   2
 
#define ZFC_TILYEAR   3
 
#define ZFC_TILMONTH   4
 
#define ZFC_TILDAY   5
 
#define ZFC_TILTIME   6
 
#define ZONEC_MINFIELDS   3
 
#define ZONEC_MAXFIELDS   7
 
#define RF_NAME   1
 
#define RF_LOYEAR   2
 
#define RF_HIYEAR   3
 
#define RF_COMMAND   4
 
#define RF_MONTH   5
 
#define RF_DAY   6
 
#define RF_TOD   7
 
#define RF_SAVE   8
 
#define RF_ABBRVAR   9
 
#define RULE_FIELDS   10
 
#define LF_TARGET   1
 
#define LF_LINKNAME   2
 
#define LINK_FIELDS   3
 
#define LP_YEAR   1
 
#define LP_MONTH   2
 
#define LP_DAY   3
 
#define LP_TIME   4
 
#define LP_CORR   5
 
#define LP_ROLL   6
 
#define LEAP_FIELDS   7
 
#define EXPIRES_FIELDS   5
 
#define YR_MINIMUM   0
 
#define YR_MAXIMUM   1
 
#define YR_ONLY   2
 
#define TIME_T_BITS_IN_FILE   64
 
#define ZIC_BLOAT_DEFAULT   "slim"
 
#define DO(field)   fwrite(tzh.field, sizeof tzh.field, 1, fp)
 
#define LDAYSPERWEEK   ((zic_t) DAYSPERWEEK)
 

Typedefs

typedef int64 zic_t
 
typedef int lineno_t
 

Enumerations

enum  { PERCENT_Z_LEN_BOUND = sizeof "+995959" - 1 }
 
enum  { WORK_AROUND_QTBUG_53071 = true }
 

Functions

int link (const char *target, const char *linkname)
 
static void memory_exhausted (const char *msg) pg_attribute_noreturn()
 
static void verror (const char *string, va_list args) pg_attribute_printf(1
 
static void static void error (const char *string,...) pg_attribute_printf(1
 
static void static void static void warning (const char *string,...) pg_attribute_printf(1
 
static void static void static void static void usage (FILE *stream, int status) pg_attribute_noreturn()
 
static void addtt (zic_t starttime, int type)
 
static int addtype (zic_t utoff, char const *abbr, bool isdst, bool ttisstd, bool ttisut)
 
static void leapadd (zic_t t, int correction, int rolling)
 
static void adjleap (void)
 
static void associate (void)
 
static void dolink (char const *target, char const *linkname, bool staysymlink)
 
static char ** getfields (char *cp)
 
static zic_t gethms (const char *string, const char *errstring)
 
static zic_t getsave (char *field, bool *isdst)
 
static void inexpires (char **fields, int nfields)
 
static void infile (const char *name)
 
static void inleap (char **fields, int nfields)
 
static void inlink (char **fields, int nfields)
 
static void inrule (char **fields, int nfields)
 
static bool inzcont (char **fields, int nfields)
 
static bool inzone (char **fields, int nfields)
 
static bool inzsub (char **fields, int nfields, bool iscont)
 
static bool itsdir (char const *name)
 
static bool itssymlink (char const *name)
 
static bool is_alpha (char a)
 
static char lowerit (char a)
 
static void mkdirs (char const *argname, bool ancestors)
 
static void newabbr (const char *string)
 
static zic_t oadd (zic_t t1, zic_t t2)
 
static void outzone (const struct zone *zpfirst, ptrdiff_t zonecount)
 
static zic_t rpytime (const struct rule *rp, zic_t wantedy)
 
static void rulesub (struct rule *rp, const char *loyearp, const char *hiyearp, const char *typep, const char *monthp, const char *dayp, const char *timep)
 
static zic_t tadd (zic_t t1, zic_t t2)
 
static struct lookup const * byword (const char *word, const struct lookup *table)
 
static size_t size_product (size_t nitems, size_t itemsize)
 
static void * memcheck (void *ptr)
 
static void * emalloc (size_t size)
 
static void * erealloc (void *ptr, size_t size)
 
static char * ecpyalloc (char const *str)
 
static void * growalloc (void *ptr, size_t itemsize, ptrdiff_t nitems, ptrdiff_t *nitems_alloc)
 
static void eats (char const *name, lineno_t num, char const *rname, lineno_t rnum)
 
static void eat (char const *name, lineno_t num)
 
static void close_file (FILE *stream, char const *dir, char const *name)
 
static void change_directory (char const *dir)
 
static bool timerange_option (char *timerange)
 
static bool want_bloat (void)
 
int main (int argc, char **argv)
 
static bool componentcheck (char const *name, char const *component, char const *component_end)
 
static bool namecheck (const char *name)
 
static char * relname (char const *target, char const *linkname)
 
static int hardlinkerr (char const *target, char const *linkname)
 
static int rcomp (const void *cp1, const void *cp2)
 
static zic_t getleapdatetime (char **fields, int nfields, bool expire_line)
 
static void convert (const int32 val, char *const buf)
 
static void convert64 (const zic_t val, char *const buf)
 
static void puttzcode (const int32 val, FILE *const fp)
 
static void puttzcodepass (zic_t val, FILE *fp, int pass)
 
static int atcomp (const void *avp, const void *bvp)
 
static struct timerange limitrange (struct timerange r, zic_t lo, zic_t hi, zic_t const *ats, unsigned char const *types)
 
static void writezone (const char *const name, const char *const string, char version, int defaulttype)
 
static char const * abbroffset (char *buf, zic_t offset)
 
static size_t doabbr (char *abbr, struct zone const *zp, char const *letters, bool isdst, zic_t save, bool doquotes)
 
static void updateminmax (const zic_t x)
 
static int stringoffset (char *result, zic_t offset)
 
static int stringrule (char *result, struct rule *const rp, zic_t save, zic_t stdoff)
 
static int rule_cmp (struct rule const *a, struct rule const *b)
 
static int stringzone (char *result, struct zone const *zpfirst, ptrdiff_t zonecount)
 
static bool is_space (char a)
 
static bool ciequal (const char *ap, const char *bp)
 
static bool itsabbr (const char *abbr, const char *word)
 
static bool ciprefix (char const *abbr, char const *word)
 
static void time_overflow (void)
 

Variables

static ptrdiff_t const PTRDIFF_MAX = MAXVAL(ptrdiff_t, TYPE_BIT(ptrdiff_t))
 
static int charcnt
 
static bool errors
 
static bool warnings
 
static const char * filename
 
static int leapcnt
 
static bool leapseen
 
static zic_t leapminyear
 
static zic_t leapmaxyear
 
static lineno_t linenum
 
static int max_abbrvar_len = PERCENT_Z_LEN_BOUND
 
static int max_format_len
 
static zic_t max_year
 
static zic_t min_year
 
static bool noise
 
static bool print_abbrevs
 
static zic_t print_cutoff
 
static const char * rfilename
 
static lineno_t rlinenum
 
static const char * progname
 
static ptrdiff_t timecnt
 
static ptrdiff_t timecnt_alloc
 
static int typecnt
 
static struct rulerules
 
static ptrdiff_t nrules
 
static ptrdiff_t nrules_alloc
 
static struct zonezones
 
static ptrdiff_t nzones
 
static ptrdiff_t nzones_alloc
 
static struct linklinks
 
static ptrdiff_t nlinks
 
static ptrdiff_t nlinks_alloc
 
static struct lookup const zi_line_codes []
 
static struct lookup const leap_line_codes []
 
static struct lookup const mon_names []
 
static struct lookup const wday_names []
 
static struct lookup const lasts []
 
static struct lookup const begin_years []
 
static struct lookup const end_years []
 
static struct lookup const leap_types []
 
static const int len_months [2][MONSPERYEAR]
 
static const int len_years [2]
 
static struct attypeattypes
 
static zic_t utoffs [TZ_MAX_TYPES]
 
static char isdsts [TZ_MAX_TYPES]
 
static unsigned char desigidx [TZ_MAX_TYPES]
 
static bool ttisstds [TZ_MAX_TYPES]
 
static bool ttisuts [TZ_MAX_TYPES]
 
static char chars [TZ_MAX_CHARS]
 
static zic_t trans [TZ_MAX_LEAPS]
 
static zic_t corr [TZ_MAX_LEAPS]
 
static char roll [TZ_MAX_LEAPS]
 
static zic_t const min_time = MINVAL(zic_t, TIME_T_BITS_IN_FILE)
 
static zic_t const max_time = MAXVAL(zic_t, TIME_T_BITS_IN_FILE)
 
static zic_t lo_time = MINVAL(zic_t, TIME_T_BITS_IN_FILE)
 
static zic_t hi_time = MAXVAL(zic_t, TIME_T_BITS_IN_FILE)
 
static zic_t leapexpires = -1
 
static zic_t comment_leapexpires = -1
 
static const char * psxrules
 
static const char * lcltime
 
static const char * directory
 
static const char * leapsec
 
static const char * tzdefault
 
static int bloat
 

Macro Definition Documentation

◆ DC_DOM

#define DC_DOM   0 /* 1..31 */ /* unused */

Definition at line 89 of file zic.c.

◆ DC_DOWGEQ

#define DC_DOWGEQ   1 /* 1..31 */ /* 0..6 (Sun..Sat) */

Definition at line 90 of file zic.c.

◆ DC_DOWLEQ

#define DC_DOWLEQ   2 /* 1..31 */ /* 0..6 (Sun..Sat) */

Definition at line 91 of file zic.c.

◆ DO

#define DO (   field)    fwrite(tzh.field, sizeof tzh.field, 1, fp)

◆ EXPIRES_FIELDS

#define EXPIRES_FIELDS   5

Definition at line 273 of file zic.c.

◆ LC_EXPIRES

#define LC_EXPIRES   4

Definition at line 206 of file zic.c.

◆ LC_LEAP

#define LC_LEAP   3

Definition at line 205 of file zic.c.

◆ LC_LINK

#define LC_LINK   2

Definition at line 204 of file zic.c.

◆ LC_RULE

#define LC_RULE   0

Definition at line 202 of file zic.c.

◆ LC_ZONE

#define LC_ZONE   1

Definition at line 203 of file zic.c.

◆ LDAYSPERWEEK

#define LDAYSPERWEEK   ((zic_t) DAYSPERWEEK)

◆ LEAP_FIELDS

#define LEAP_FIELDS   7

Definition at line 270 of file zic.c.

◆ LF_LINKNAME

#define LF_LINKNAME   2

Definition at line 257 of file zic.c.

◆ LF_TARGET

#define LF_TARGET   1

Definition at line 256 of file zic.c.

◆ LINK_FIELDS

#define LINK_FIELDS   3

Definition at line 258 of file zic.c.

◆ linkat

#define linkat (   targetdir,
  target,
  linknamedir,
  linkname,
  flag 
)     (itssymlink(target) ? (errno = ENOTSUP, -1) : link(target, linkname))

Definition at line 116 of file zic.c.

◆ LP_CORR

#define LP_CORR   5

Definition at line 268 of file zic.c.

◆ LP_DAY

#define LP_DAY   3

Definition at line 266 of file zic.c.

◆ LP_MONTH

#define LP_MONTH   2

Definition at line 265 of file zic.c.

◆ LP_ROLL

#define LP_ROLL   6

Definition at line 269 of file zic.c.

◆ LP_TIME

#define LP_TIME   4

Definition at line 267 of file zic.c.

◆ LP_YEAR

#define LP_YEAR   1

Definition at line 264 of file zic.c.

◆ MKDIR_UMASK

#define MKDIR_UMASK   0755

Definition at line 37 of file zic.c.

◆ RF_ABBRVAR

#define RF_ABBRVAR   9

Definition at line 249 of file zic.c.

◆ RF_COMMAND

#define RF_COMMAND   4

Definition at line 244 of file zic.c.

◆ RF_DAY

#define RF_DAY   6

Definition at line 246 of file zic.c.

◆ RF_HIYEAR

#define RF_HIYEAR   3

Definition at line 243 of file zic.c.

◆ RF_LOYEAR

#define RF_LOYEAR   2

Definition at line 242 of file zic.c.

◆ RF_MONTH

#define RF_MONTH   5

Definition at line 245 of file zic.c.

◆ RF_NAME

#define RF_NAME   1

Definition at line 241 of file zic.c.

◆ RF_SAVE

#define RF_SAVE   8

Definition at line 248 of file zic.c.

◆ RF_TOD

#define RF_TOD   7

Definition at line 247 of file zic.c.

◆ RULE_FIELDS

#define RULE_FIELDS   10

Definition at line 250 of file zic.c.

◆ TIME_T_BITS_IN_FILE

#define TIME_T_BITS_IN_FILE   64

Definition at line 582 of file zic.c.

◆ YR_MAXIMUM

#define YR_MAXIMUM   1

Definition at line 280 of file zic.c.

◆ YR_MINIMUM

#define YR_MINIMUM   0

Definition at line 279 of file zic.c.

◆ YR_ONLY

#define YR_ONLY   2

Definition at line 281 of file zic.c.

◆ ZF_FORMAT

#define ZF_FORMAT   4

Definition at line 215 of file zic.c.

◆ ZF_NAME

#define ZF_NAME   1

Definition at line 212 of file zic.c.

◆ ZF_RULE

#define ZF_RULE   3

Definition at line 214 of file zic.c.

◆ ZF_STDOFF

#define ZF_STDOFF   2

Definition at line 213 of file zic.c.

◆ ZF_TILDAY

#define ZF_TILDAY   7

Definition at line 218 of file zic.c.

◆ ZF_TILMONTH

#define ZF_TILMONTH   6

Definition at line 217 of file zic.c.

◆ ZF_TILTIME

#define ZF_TILTIME   8

Definition at line 219 of file zic.c.

◆ ZF_TILYEAR

#define ZF_TILYEAR   5

Definition at line 216 of file zic.c.

◆ ZFC_FORMAT

#define ZFC_FORMAT   2

Definition at line 229 of file zic.c.

◆ ZFC_RULE

#define ZFC_RULE   1

Definition at line 228 of file zic.c.

◆ ZFC_STDOFF

#define ZFC_STDOFF   0

Definition at line 227 of file zic.c.

◆ ZFC_TILDAY

#define ZFC_TILDAY   5

Definition at line 232 of file zic.c.

◆ ZFC_TILMONTH

#define ZFC_TILMONTH   4

Definition at line 231 of file zic.c.

◆ ZFC_TILTIME

#define ZFC_TILTIME   6

Definition at line 233 of file zic.c.

◆ ZFC_TILYEAR

#define ZFC_TILYEAR   3

Definition at line 230 of file zic.c.

◆ ZIC_BLOAT_DEFAULT

#define ZIC_BLOAT_DEFAULT   "slim"

Definition at line 650 of file zic.c.

◆ ZIC_MAX

#define ZIC_MAX   PG_INT64_MAX

Definition at line 27 of file zic.c.

◆ ZIC_MAX_ABBR_LEN_WO_WARN

#define ZIC_MAX_ABBR_LEN_WO_WARN   6

Definition at line 30 of file zic.c.

◆ ZIC_MIN

#define ZIC_MIN   PG_INT64_MIN

Definition at line 26 of file zic.c.

◆ ZIC_VERSION

#define ZIC_VERSION   '3'

Definition at line 23 of file zic.c.

◆ ZIC_VERSION_PRE_2013

#define ZIC_VERSION_PRE_2013   '2'

Definition at line 22 of file zic.c.

◆ ZONE_MAXFIELDS

#define ZONE_MAXFIELDS   9

Definition at line 221 of file zic.c.

◆ ZONE_MINFIELDS

#define ZONE_MINFIELDS   5

Definition at line 220 of file zic.c.

◆ ZONEC_MAXFIELDS

#define ZONEC_MAXFIELDS   7

Definition at line 235 of file zic.c.

◆ ZONEC_MINFIELDS

#define ZONEC_MINFIELDS   3

Definition at line 234 of file zic.c.

Typedef Documentation

◆ lineno_t

typedef int lineno_t

Definition at line 55 of file zic.c.

◆ zic_t

typedef int64 zic_t

Definition at line 25 of file zic.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
PERCENT_Z_LEN_BOUND 

Definition at line 160 of file zic.c.

161{
162PERCENT_Z_LEN_BOUND = sizeof "+995959" - 1};
@ PERCENT_Z_LEN_BOUND
Definition: zic.c:162

◆ anonymous enum

anonymous enum
Enumerator
WORK_AROUND_QTBUG_53071 

Definition at line 170 of file zic.c.

171{
@ WORK_AROUND_QTBUG_53071
Definition: zic.c:172

Function Documentation

◆ abbroffset()

static char const * abbroffset ( char *  buf,
zic_t  offset 
)
static

Definition at line 2586 of file zic.c.

2587{
2588 char sign = '+';
2589 int seconds,
2590 minutes;
2591
2592 if (offset < 0)
2593 {
2594 offset = -offset;
2595 sign = '-';
2596 }
2597
2598 seconds = offset % SECSPERMIN;
2599 offset /= SECSPERMIN;
2600 minutes = offset % MINSPERHOUR;
2601 offset /= MINSPERHOUR;
2602 if (100 <= offset)
2603 {
2604 error(_("%%z UT offset magnitude exceeds 99:59:59"));
2605 return "%z";
2606 }
2607 else
2608 {
2609 char *p = buf;
2610
2611 *p++ = sign;
2612 *p++ = '0' + offset / 10;
2613 *p++ = '0' + offset % 10;
2614 if (minutes | seconds)
2615 {
2616 *p++ = '0' + minutes / 10;
2617 *p++ = '0' + minutes % 10;
2618 if (seconds)
2619 {
2620 *p++ = '0' + seconds / 10;
2621 *p++ = '0' + seconds % 10;
2622 }
2623 }
2624 *p = '\0';
2625 return buf;
2626 }
2627}
#define _(x)
Definition: elog.c:90
char sign
Definition: informix.c:693
static char * buf
Definition: pg_test_fsync.c:72
#define SECSPERMIN
Definition: private.h:97
#define MINSPERHOUR
Definition: private.h:98
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:504

References _, buf, error(), MINSPERHOUR, SECSPERMIN, and sign.

Referenced by doabbr().

◆ addtt()

static void addtt ( zic_t  starttime,
int  type 
)
static

Definition at line 3348 of file zic.c.

3349{
3351 attypes[timecnt].at = starttime;
3352 attypes[timecnt].dontmerge = false;
3354 ++timecnt;
3355}
bool dontmerge
Definition: zic.c:393
zic_t at
Definition: zic.c:392
unsigned char type
Definition: zic.c:394
const char * type
static void * growalloc(void *ptr, size_t itemsize, ptrdiff_t nitems, ptrdiff_t *nitems_alloc)
Definition: zic.c:452
static ptrdiff_t timecnt
Definition: zic.c:194
static ptrdiff_t timecnt_alloc
Definition: zic.c:195
static struct attype * attypes

References attype::at, attypes, attype::dontmerge, growalloc(), timecnt, timecnt_alloc, type, and attype::type.

Referenced by outzone().

◆ addtype()

static int addtype ( zic_t  utoff,
char const *  abbr,
bool  isdst,
bool  ttisstd,
bool  ttisut 
)
static

Definition at line 3358 of file zic.c.

3359{
3360 int i,
3361 j;
3362
3363 if (!(-1L - 2147483647L <= utoff && utoff <= 2147483647L))
3364 {
3365 error(_("UT offset out of range"));
3367 }
3368 if (!want_bloat())
3369 ttisstd = ttisut = false;
3370
3371 for (j = 0; j < charcnt; ++j)
3372 if (strcmp(&chars[j], abbr) == 0)
3373 break;
3374 if (j == charcnt)
3375 newabbr(abbr);
3376 else
3377 {
3378 /* If there's already an entry, return its index. */
3379 for (i = 0; i < typecnt; i++)
3380 if (utoff == utoffs[i] && isdst == isdsts[i] && j == desigidx[i]
3381 && ttisstd == ttisstds[i] && ttisut == ttisuts[i])
3382 return i;
3383 }
3384
3385 /*
3386 * There isn't one; add a new one, unless there are already too many.
3387 */
3388 if (typecnt >= TZ_MAX_TYPES)
3389 {
3390 error(_("too many local time types"));
3392 }
3393 i = typecnt++;
3394 utoffs[i] = utoff;
3395 isdsts[i] = isdst;
3396 ttisstds[i] = ttisstd;
3397 ttisuts[i] = ttisut;
3398 desigidx[i] = j;
3399 return i;
3400}
int j
Definition: isn.c:73
int i
Definition: isn.c:72
exit(1)
#define EXIT_FAILURE
Definition: settings.h:178
#define TZ_MAX_TYPES
Definition: tzfile.h:103
static char chars[TZ_MAX_CHARS]
Definition: zic.c:401
static int typecnt
Definition: zic.c:196
static unsigned char desigidx[TZ_MAX_TYPES]
Definition: zic.c:398
static bool ttisuts[TZ_MAX_TYPES]
Definition: zic.c:400
static char isdsts[TZ_MAX_TYPES]
Definition: zic.c:397
static bool ttisstds[TZ_MAX_TYPES]
Definition: zic.c:399
static bool want_bloat(void)
Definition: zic.c:644
static void newabbr(const char *string)
Definition: zic.c:3910
static int charcnt
Definition: zic.c:175
static zic_t utoffs[TZ_MAX_TYPES]
Definition: zic.c:396

References _, charcnt, chars, desigidx, error(), exit(), EXIT_FAILURE, i, isdsts, j, newabbr(), ttisstds, ttisuts, typecnt, TZ_MAX_TYPES, utoffs, and want_bloat().

Referenced by outzone(), and writezone().

◆ adjleap()

static void adjleap ( void  )
static

Definition at line 3425 of file zic.c.

3426{
3427 int i;
3428 zic_t last = 0;
3429 zic_t prevtrans = 0;
3430
3431 /*
3432 * propagate leap seconds forward
3433 */
3434 for (i = 0; i < leapcnt; ++i)
3435 {
3436 if (trans[i] - prevtrans < 28 * SECSPERDAY)
3437 {
3438 error(_("Leap seconds too close together"));
3440 }
3441 prevtrans = trans[i];
3442 trans[i] = tadd(trans[i], last);
3443 last = corr[i] += last;
3444 }
3445
3446 if (leapexpires < 0)
3447 {
3449 if (0 <= leapexpires)
3450 warning(_("\"#expires\" is obsolescent; use \"Expires\""));
3451 }
3452
3453 if (0 <= leapexpires)
3454 {
3455 leapexpires = oadd(leapexpires, last);
3456 if (!(leapcnt == 0 || (trans[leapcnt - 1] < leapexpires)))
3457 {
3458 error(_("last Leap time does not precede Expires time"));
3460 }
3461 if (leapexpires <= hi_time)
3462 hi_time = leapexpires - 1;
3463 }
3464}
#define SECSPERDAY
Definition: private.h:104
static zic_t tadd(zic_t t1, zic_t t2)
Definition: zic.c:3772
static zic_t comment_leapexpires
Definition: zic.c:597
int64 zic_t
Definition: zic.c:25
static zic_t leapexpires
Definition: zic.c:594
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:515
static zic_t oadd(zic_t t1, zic_t t2)
Definition: zic.c:3764
static int leapcnt
Definition: zic.c:179
static zic_t hi_time
Definition: zic.c:591
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:402
static zic_t corr[TZ_MAX_LEAPS]
Definition: zic.c:403

References _, comment_leapexpires, corr, error(), exit(), EXIT_FAILURE, hi_time, i, leapcnt, leapexpires, oadd(), SECSPERDAY, tadd(), trans, and warning().

Referenced by main().

◆ associate()

static void associate ( void  )
static

Definition at line 1158 of file zic.c.

1159{
1160 struct zone *zp;
1161 struct rule *rp;
1162 ptrdiff_t i,
1163 j,
1164 base,
1165 out;
1166
1167 if (nrules != 0)
1168 {
1169 qsort(rules, nrules, sizeof *rules, rcomp);
1170 for (i = 0; i < nrules - 1; ++i)
1171 {
1172 if (strcmp(rules[i].r_name,
1173 rules[i + 1].r_name) != 0)
1174 continue;
1175 if (strcmp(rules[i].r_filename,
1176 rules[i + 1].r_filename) == 0)
1177 continue;
1179 warning(_("same rule name in multiple files"));
1180 eat(rules[i + 1].r_filename, rules[i + 1].r_linenum);
1181 warning(_("same rule name in multiple files"));
1182 for (j = i + 2; j < nrules; ++j)
1183 {
1184 if (strcmp(rules[i].r_name,
1185 rules[j].r_name) != 0)
1186 break;
1187 if (strcmp(rules[i].r_filename,
1188 rules[j].r_filename) == 0)
1189 continue;
1190 if (strcmp(rules[i + 1].r_filename,
1191 rules[j].r_filename) == 0)
1192 continue;
1193 break;
1194 }
1195 i = j - 1;
1196 }
1197 }
1198 for (i = 0; i < nzones; ++i)
1199 {
1200 zp = &zones[i];
1201 zp->z_rules = NULL;
1202 zp->z_nrules = 0;
1203 }
1204 for (base = 0; base < nrules; base = out)
1205 {
1206 rp = &rules[base];
1207 for (out = base + 1; out < nrules; ++out)
1208 if (strcmp(rp->r_name, rules[out].r_name) != 0)
1209 break;
1210 for (i = 0; i < nzones; ++i)
1211 {
1212 zp = &zones[i];
1213 if (strcmp(zp->z_rule, rp->r_name) != 0)
1214 continue;
1215 zp->z_rules = rp;
1216 zp->z_nrules = out - base;
1217 }
1218 }
1219 for (i = 0; i < nzones; ++i)
1220 {
1221 zp = &zones[i];
1222 if (zp->z_nrules == 0)
1223 {
1224 /*
1225 * Maybe we have a local standard time offset.
1226 */
1227 eat(zp->z_filename, zp->z_linenum);
1228 zp->z_save = getsave(zp->z_rule, &zp->z_isdst);
1229
1230 /*
1231 * Note, though, that if there's no rule, a '%s' in the format is
1232 * a bad thing.
1233 */
1234 if (zp->z_format_specifier == 's')
1235 error("%s", _("%s in ruleless zone"));
1236 }
1237 }
1238 if (errors)
1240}
#define qsort(a, b, c, d)
Definition: port.h:474
Definition: localtime.c:73
const char * r_filename
Definition: zic.c:59
const char * r_name
Definition: zic.c:61
lineno_t r_linenum
Definition: zic.c:60
Definition: zic.c:94
lineno_t z_linenum
Definition: zic.c:96
zic_t z_save
Definition: zic.c:105
char * z_rule
Definition: zic.c:100
ptrdiff_t z_nrules
Definition: zic.c:108
char z_format_specifier
Definition: zic.c:102
bool z_isdst
Definition: zic.c:104
struct rule * z_rules
Definition: zic.c:107
const char * z_filename
Definition: zic.c:95
static struct zone * zones
Definition: zic.c:287
static void eat(char const *name, lineno_t num)
Definition: zic.c:482
static ptrdiff_t nrules
Definition: zic.c:284
static struct rule * rules
Definition: zic.c:283
static zic_t getsave(char *field, bool *isdst)
Definition: zic.c:1443
static bool errors
Definition: zic.c:176
static ptrdiff_t nzones
Definition: zic.c:288
static int rcomp(const void *cp1, const void *cp2)
Definition: zic.c:1151

References _, eat(), error(), errors, exit(), EXIT_FAILURE, getsave(), i, j, nrules, nzones, qsort, rule::r_filename, rule::r_linenum, rule::r_name, rcomp(), rules, warning(), zone::z_filename, zone::z_format_specifier, zone::z_isdst, zone::z_linenum, zone::z_nrules, zone::z_rule, zone::z_rules, zone::z_save, and zones.

Referenced by main().

◆ atcomp()

static int atcomp ( const void *  avp,
const void *  bvp 
)
static

Definition at line 2037 of file zic.c.

2038{
2039 const zic_t a = ((const struct attype *) avp)->at;
2040 const zic_t b = ((const struct attype *) bvp)->at;
2041
2042 return (a < b) ? -1 : (a > b);
2043}
int b
Definition: isn.c:69
int a
Definition: isn.c:68
Definition: zic.c:391

References a, and b.

Referenced by writezone().

◆ byword()

static const struct lookup * byword ( const char *  word,
const struct lookup table 
)
static

Definition at line 3651 of file zic.c.

3652{
3653 const struct lookup *foundlp;
3654 const struct lookup *lp;
3655
3656 if (word == NULL || table == NULL)
3657 return NULL;
3658
3659 /*
3660 * If TABLE is LASTS and the word starts with "last" followed by a
3661 * non-'-', skip the "last" and look in WDAY_NAMES instead. Warn about any
3662 * usage of the undocumented prefix "last-".
3663 */
3664 if (table == lasts && ciprefix("last", word) && word[4])
3665 {
3666 if (word[4] == '-')
3667 warning(_("\"%s\" is undocumented; use \"last%s\" instead"),
3668 word, word + 5);
3669 else
3670 {
3671 word += 4;
3672 table = wday_names;
3673 }
3674 }
3675
3676 /*
3677 * Look for exact match.
3678 */
3679 for (lp = table; lp->l_word != NULL; ++lp)
3680 if (ciequal(word, lp->l_word))
3681 return lp;
3682
3683 /*
3684 * Look for inexact match.
3685 */
3686 foundlp = NULL;
3687 for (lp = table; lp->l_word != NULL; ++lp)
3688 if (ciprefix(word, lp->l_word))
3689 {
3690 if (foundlp == NULL)
3691 foundlp = lp;
3692 else
3693 return NULL; /* multiple inexact matches */
3694 }
3695
3696 if (foundlp && noise)
3697 {
3698 /* Warn about any backward-compatibility issue with pre-2017c zic. */
3699 bool pre_2017c_match = false;
3700
3701 for (lp = table; lp->l_word; lp++)
3702 if (itsabbr(word, lp->l_word))
3703 {
3704 if (pre_2017c_match)
3705 {
3706 warning(_("\"%s\" is ambiguous in pre-2017c zic"), word);
3707 break;
3708 }
3709 pre_2017c_match = true;
3710 }
3711 }
3712
3713 return foundlp;
3714}
static void word(struct vars *v, int dir, struct state *lp, struct state *rp)
Definition: regcomp.c:1476
Definition: zic.c:304
const char * l_word
Definition: zic.c:305
static struct lookup const lasts[]
Definition: zic.c:351
static bool ciprefix(char const *abbr, char const *word)
Definition: zic.c:3640
static bool ciequal(const char *ap, const char *bp)
Definition: zic.c:3614
static bool itsabbr(const char *abbr, const char *word)
Definition: zic.c:3623
static struct lookup const wday_names[]
Definition: zic.c:340
static bool noise
Definition: zic.c:188

References _, ciequal(), ciprefix(), itsabbr(), lookup::l_word, lasts, noise, warning(), wday_names, and word().

Referenced by getleapdatetime(), infile(), inleap(), and rulesub().

◆ change_directory()

static void change_directory ( char const *  dir)
static

Definition at line 562 of file zic.c.

563{
564 if (chdir(dir) != 0)
565 {
566 int chdir_errno = errno;
567
568 if (chdir_errno == ENOENT)
569 {
570 mkdirs(dir, false);
571 chdir_errno = chdir(dir) == 0 ? 0 : errno;
572 }
573 if (chdir_errno != 0)
574 {
575 fprintf(stderr, _("%s: Can't chdir to %s: %s\n"),
576 progname, dir, strerror(chdir_errno));
578 }
579 }
580}
#define fprintf(file, fmt, msg)
Definition: cubescan.l:21
#define strerror
Definition: port.h:251
static void mkdirs(char const *argname, bool ancestors)
Definition: zic.c:3948
static const char * progname
Definition: zic.c:193

References _, exit(), EXIT_FAILURE, fprintf, mkdirs(), progname, and strerror.

Referenced by main().

◆ ciequal()

static bool ciequal ( const char *  ap,
const char *  bp 
)
static

Definition at line 3614 of file zic.c.

3615{
3616 while (lowerit(*ap) == lowerit(*bp++))
3617 if (*ap++ == '\0')
3618 return true;
3619 return false;
3620}
static char lowerit(char a)
Definition: zic.c:3551

References lowerit().

Referenced by byword().

◆ ciprefix()

static bool ciprefix ( char const *  abbr,
char const *  word 
)
static

Definition at line 3640 of file zic.c.

3641{
3642 do
3643 if (!*abbr)
3644 return true;
3645 while (lowerit(*abbr++) == lowerit(*word++));
3646
3647 return false;
3648}

References lowerit(), and word().

Referenced by byword().

◆ close_file()

static void close_file ( FILE *  stream,
char const *  dir,
char const *  name 
)
static

Definition at line 527 of file zic.c.

528{
529 char const *e = (ferror(stream) ? _("I/O error")
530 : fclose(stream) != 0 ? strerror(errno) : NULL);
531
532 if (e)
533 {
534 fprintf(stderr, "%s: %s%s%s%s%s\n", progname,
535 dir ? dir : "", dir ? "/" : "",
536 name ? name : "", name ? ": " : "",
537 e);
539 }
540}
e
Definition: preproc-init.c:82
const char * name

References _, exit(), EXIT_FAILURE, fprintf, name, progname, and strerror.

Referenced by dolink(), infile(), main(), usage(), and writezone().

◆ componentcheck()

static bool componentcheck ( char const *  name,
char const *  component,
char const *  component_end 
)
static

Definition at line 859 of file zic.c.

861{
862 enum
863 {
864 component_len_max = 14};
865 ptrdiff_t component_len = component_end - component;
866
867 if (component_len == 0)
868 {
869 if (!*name)
870 error(_("empty file name"));
871 else
872 error(_(component == name
873 ? "file name '%s' begins with '/'"
874 : *component_end
875 ? "file name '%s' contains '//'"
876 : "file name '%s' ends with '/'"),
877 name);
878 return false;
879 }
880 if (0 < component_len && component_len <= 2
881 && component[0] == '.' && component_end[-1] == '.')
882 {
883 int len = component_len;
884
885 error(_("file name '%s' contains '%.*s' component"),
886 name, len, component);
887 return false;
888 }
889 if (noise)
890 {
891 if (0 < component_len && component[0] == '-')
892 warning(_("file name '%s' component contains leading '-'"),
893 name);
894 if (component_len_max < component_len)
895 warning(_("file name '%s' contains overlength component"
896 " '%.*s...'"),
897 name, component_len_max, component);
898 }
899 return true;
900}
const void size_t len

References _, error(), len, name, noise, and warning().

Referenced by namecheck().

◆ convert()

static void convert ( const int32  val,
char *const  buf 
)
static

Definition at line 1992 of file zic.c.

1993{
1994 int i;
1995 int shift;
1996 unsigned char *const b = (unsigned char *) buf;
1997
1998 for (i = 0, shift = 24; i < 4; ++i, shift -= 8)
1999 b[i] = val >> shift;
2000}
long val
Definition: informix.c:689

References b, buf, i, and val.

Referenced by ExecInitExprRec(), fmtfloat(), fmtint(), fmtptr(), get_rule_expr(), pg_strfromd(), print_double(), puttzcode(), and writezone().

◆ convert64()

static void convert64 ( const zic_t  val,
char *const  buf 
)
static

Definition at line 2003 of file zic.c.

2004{
2005 int i;
2006 int shift;
2007 unsigned char *const b = (unsigned char *) buf;
2008
2009 for (i = 0, shift = 56; i < 8; ++i, shift -= 8)
2010 b[i] = val >> shift;
2011}

References b, buf, i, and val.

Referenced by puttzcodepass().

◆ doabbr()

static size_t doabbr ( char *  abbr,
struct zone const *  zp,
char const *  letters,
bool  isdst,
zic_t  save,
bool  doquotes 
)
static

Definition at line 2630 of file zic.c.

2632{
2633 char *cp;
2634 char *slashp;
2635 size_t len;
2636 char const *format = zp->z_format;
2637
2638 slashp = strchr(format, '/');
2639 if (slashp == NULL)
2640 {
2641 char letterbuf[PERCENT_Z_LEN_BOUND + 1];
2642
2643 if (zp->z_format_specifier == 'z')
2644 letters = abbroffset(letterbuf, zp->z_stdoff + save);
2645 else if (!letters)
2646 letters = "%s";
2647 sprintf(abbr, format, letters);
2648 }
2649 else if (isdst)
2650 {
2651 strcpy(abbr, slashp + 1);
2652 }
2653 else
2654 {
2655 memcpy(abbr, format, slashp - format);
2656 abbr[slashp - format] = '\0';
2657 }
2658 len = strlen(abbr);
2659 if (!doquotes)
2660 return len;
2661 for (cp = abbr; is_alpha(*cp); cp++)
2662 continue;
2663 if (len > 0 && *cp == '\0')
2664 return len;
2665 abbr[len + 2] = '\0';
2666 abbr[len + 1] = '>';
2667 memmove(abbr + 1, abbr, len);
2668 abbr[0] = '<';
2669 return len + 2;
2670}
static char format
#define sprintf
Definition: port.h:240
static char const * abbroffset(char *buf, zic_t offset)
Definition: zic.c:2586
static bool is_alpha(char a)
Definition: zic.c:3486

References abbroffset(), format, is_alpha(), len, PERCENT_Z_LEN_BOUND, sprintf, zone::z_format, zone::z_format_specifier, and zone::z_stdoff.

Referenced by outzone(), and stringzone().

◆ dolink()

static void dolink ( char const *  target,
char const *  linkname,
bool  staysymlink 
)
static

Definition at line 1004 of file zic.c.

1005{
1006 bool remove_only = strcmp(target, "-") == 0;
1007 bool linkdirs_made = false;
1008 int link_errno;
1009
1010 /*
1011 * We get to be careful here since there's a fair chance of root running
1012 * us.
1013 */
1014 if (!remove_only && itsdir(target))
1015 {
1016 fprintf(stderr, _("%s: linking target %s/%s failed: %s\n"),
1017 progname, directory, target, strerror(EPERM));
1019 }
1020 if (staysymlink)
1021 staysymlink = itssymlink(linkname);
1022 if (remove(linkname) == 0)
1023 linkdirs_made = true;
1024 else if (errno != ENOENT)
1025 {
1026 char const *e = strerror(errno);
1027
1028 fprintf(stderr, _("%s: Can't remove %s/%s: %s\n"),
1029 progname, directory, linkname, e);
1031 }
1032 if (remove_only)
1033 return;
1034 link_errno = staysymlink ? ENOTSUP : hardlinkerr(target, linkname);
1035 if (link_errno == ENOENT && !linkdirs_made)
1036 {
1037 mkdirs(linkname, true);
1038 linkdirs_made = true;
1039 link_errno = hardlinkerr(target, linkname);
1040 }
1041 if (link_errno != 0)
1042 {
1043#ifdef HAVE_SYMLINK
1044 bool absolute = *target == '/';
1045 char *linkalloc = absolute ? NULL : relname(target, linkname);
1046 char const *contents = absolute ? target : linkalloc;
1047 int symlink_errno = symlink(contents, linkname) == 0 ? 0 : errno;
1048
1049 if (!linkdirs_made
1050 && (symlink_errno == ENOENT || symlink_errno == ENOTSUP))
1051 {
1052 mkdirs(linkname, true);
1053 if (symlink_errno == ENOENT)
1054 symlink_errno = symlink(contents, linkname) == 0 ? 0 : errno;
1055 }
1056 free(linkalloc);
1057 if (symlink_errno == 0)
1058 {
1059 if (link_errno != ENOTSUP)
1060 warning(_("symbolic link used because hard link failed: %s"),
1061 strerror(link_errno));
1062 }
1063 else
1064#endif /* HAVE_SYMLINK */
1065 {
1066 FILE *fp,
1067 *tp;
1068 int c;
1069
1070 fp = fopen(target, "rb");
1071 if (!fp)
1072 {
1073 char const *e = strerror(errno);
1074
1075 fprintf(stderr, _("%s: Can't read %s/%s: %s\n"),
1076 progname, directory, target, e);
1078 }
1079 tp = fopen(linkname, "wb");
1080 if (!tp)
1081 {
1082 char const *e = strerror(errno);
1083
1084 fprintf(stderr, _("%s: Can't create %s/%s: %s\n"),
1085 progname, directory, linkname, e);
1087 }
1088 while ((c = getc(fp)) != EOF)
1089 putc(c, tp);
1090 close_file(fp, directory, target);
1091 close_file(tp, directory, linkname);
1092 if (link_errno != ENOTSUP)
1093 warning(_("copy used because hard link failed: %s"),
1094 strerror(link_errno));
1095#ifdef HAVE_SYMLINK
1096 else if (symlink_errno != ENOTSUP)
1097 warning(_("copy used because symbolic link failed: %s"),
1098 strerror(symlink_errno));
1099#endif
1100 }
1101 }
1102}
#define free(a)
Definition: header.h:65
char * c
#define ENOTSUP
Definition: private.h:38
#define symlink(oldpath, newpath)
Definition: win32_port.h:225
static char * relname(char const *target, char const *linkname)
Definition: zic.c:951
static bool itsdir(char const *name)
Definition: zic.c:1106
static int hardlinkerr(char const *target, char const *linkname)
Definition: zic.c:996
static void close_file(FILE *stream, char const *dir, char const *name)
Definition: zic.c:527
static bool itssymlink(char const *name)
Definition: zic.c:1131
static const char * directory
Definition: zic.c:634

References _, close_file(), directory, ENOTSUP, exit(), EXIT_FAILURE, fprintf, free, hardlinkerr(), itsdir(), itssymlink(), mkdirs(), progname, relname(), strerror, symlink, and warning().

Referenced by main().

◆ eat()

static void eat ( char const *  name,
lineno_t  num 
)
static

Definition at line 482 of file zic.c.

483{
484 eats(name, num, NULL, -1);
485}
static void eats(char const *name, lineno_t num, char const *rname, lineno_t rnum)
Definition: zic.c:473

References eats(), and name.

Referenced by associate(), infile(), main(), and outzone().

◆ eats()

static void eats ( char const *  name,
lineno_t  num,
char const *  rname,
lineno_t  rnum 
)
static

Definition at line 473 of file zic.c.

474{
475 filename = name;
476 linenum = num;
477 rfilename = rname;
478 rlinenum = rnum;
479}
static const char * rfilename
Definition: zic.c:191
static const char * filename
Definition: zic.c:178
static lineno_t rlinenum
Definition: zic.c:192
static lineno_t linenum
Definition: zic.c:183

References filename, linenum, name, rfilename, and rlinenum.

Referenced by eat(), and outzone().

◆ ecpyalloc()

static char * ecpyalloc ( char const *  str)
static

Definition at line 446 of file zic.c.

447{
448 return memcheck(strdup(str));
449}
const char * str
static void * memcheck(void *ptr)
Definition: zic.c:426

References memcheck(), and str.

Referenced by inlink(), inrule(), inzsub(), mkdirs(), and rulesub().

◆ emalloc()

static void * emalloc ( size_t  size)
static

Definition at line 434 of file zic.c.

435{
436 return memcheck(malloc(size));
437}
#define malloc(a)
Definition: header.h:50
static pg_noinline void Size size
Definition: slab.c:607

References malloc, memcheck(), and size.

Referenced by getfields(), itsdir(), outzone(), relname(), and writezone().

◆ erealloc()

static void * erealloc ( void *  ptr,
size_t  size 
)
static

Definition at line 440 of file zic.c.

441{
442 return memcheck(realloc(ptr, size));
443}
#define realloc(a, b)
Definition: header.h:60

References memcheck(), realloc, and size.

Referenced by growalloc().

◆ error()

static void error ( const char *  string,
  ... 
)
static

Definition at line 504 of file zic.c.

505{
506 va_list args;
507
508 va_start(args, string);
509 verror(string, args);
510 va_end(args);
511 errors = true;
512}
va_end(args)
va_start(args, fmt)
static void verror(const char *string, va_list args) pg_attribute_printf(1
Definition: zic.c:488

References generate_unaccent_rules::args, errors, va_end(), va_start(), and verror().

Referenced by abbroffset(), addtype(), adjleap(), associate(), componentcheck(), getfields(), gethms(), getleapdatetime(), inexpires(), infile(), inleap(), inlink(), inrule(), inzcont(), inzone(), inzsub(), leapadd(), main(), mkdirs(), newabbr(), outzone(), rpytime(), rulesub(), time_overflow(), and writezone().

◆ getfields()

static char ** getfields ( char *  cp)
static

Definition at line 3717 of file zic.c.

3718{
3719 char *dp;
3720 char **array;
3721 int nsubs;
3722
3723 if (cp == NULL)
3724 return NULL;
3725 array = emalloc(size_product(strlen(cp) + 1, sizeof *array));
3726 nsubs = 0;
3727 for (;;)
3728 {
3729 while (is_space(*cp))
3730 ++cp;
3731 if (*cp == '\0' || *cp == '#')
3732 break;
3733 array[nsubs++] = dp = cp;
3734 do
3735 {
3736 if ((*dp = *cp++) != '"')
3737 ++dp;
3738 else
3739 while ((*dp = *cp++) != '"')
3740 if (*dp != '\0')
3741 ++dp;
3742 else
3743 {
3744 error(_("Odd number of quotation marks"));
3746 }
3747 } while (*cp && *cp != '#' && !is_space(*cp));
3748 if (is_space(*cp))
3749 ++cp;
3750 *dp = '\0';
3751 }
3752 array[nsubs] = NULL;
3753 return array;
3754}
static bool is_space(char a)
Definition: zic.c:3468
static size_t size_product(size_t nitems, size_t itemsize)
Definition: zic.c:418
static void * emalloc(size_t size)
Definition: zic.c:434

References _, emalloc(), error(), exit(), EXIT_FAILURE, is_space(), and size_product().

Referenced by infile().

◆ gethms()

static zic_t gethms ( const char *  string,
const char *  errstring 
)
static

Definition at line 1365 of file zic.c.

1366{
1367 /* PG: make hh be int not zic_t to avoid sscanf portability issues */
1368 int hh;
1369 int sign,
1370 mm = 0,
1371 ss = 0;
1372 char hhx,
1373 mmx,
1374 ssx,
1375 xr = '0',
1376 xs;
1377 int tenths = 0;
1378 bool ok = true;
1379
1380 if (string == NULL || *string == '\0')
1381 return 0;
1382 if (*string == '-')
1383 {
1384 sign = -1;
1385 ++string;
1386 }
1387 else
1388 sign = 1;
1389 switch (sscanf(string,
1390 "%d%c%d%c%d%c%1d%*[0]%c%*[0123456789]%c",
1391 &hh, &hhx, &mm, &mmx, &ss, &ssx, &tenths, &xr, &xs))
1392 {
1393 default:
1394 ok = false;
1395 break;
1396 case 8:
1397 ok = '0' <= xr && xr <= '9';
1398 /* fallthrough */
1399 case 7:
1400 ok &= ssx == '.';
1401 if (ok && noise)
1402 warning(_("fractional seconds rejected by"
1403 " pre-2018 versions of zic"));
1404 /* fallthrough */
1405 case 5:
1406 ok &= mmx == ':';
1407 /* fallthrough */
1408 case 3:
1409 ok &= hhx == ':';
1410 /* fallthrough */
1411 case 1:
1412 break;
1413 }
1414 if (!ok)
1415 {
1416 error("%s", errstring);
1417 return 0;
1418 }
1419 if (hh < 0 ||
1420 mm < 0 || mm >= MINSPERHOUR ||
1421 ss < 0 || ss > SECSPERMIN)
1422 {
1423 error("%s", errstring);
1424 return 0;
1425 }
1426 /* Some compilers warn that this test is unsatisfiable for 32-bit ints */
1427#if INT_MAX > PG_INT32_MAX
1428 if (ZIC_MAX / SECSPERHOUR < hh)
1429 {
1430 error(_("time overflow"));
1431 return 0;
1432 }
1433#endif
1434 ss += 5 + ((ss ^ 1) & (xr == '0')) <= tenths; /* Round to even. */
1435 if (noise && (hh > HOURSPERDAY ||
1436 (hh == HOURSPERDAY && (mm != 0 || ss != 0))))
1437 warning(_("values over 24 hours not handled by pre-2007 versions of zic"));
1438 return oadd(sign * (zic_t) hh * SECSPERHOUR,
1439 sign * (mm * SECSPERMIN + ss));
1440}
char string[11]
Definition: preproc-type.c:52
#define SECSPERHOUR
Definition: private.h:103
#define HOURSPERDAY
Definition: private.h:99
#define ZIC_MAX
Definition: zic.c:27

References _, error(), HOURSPERDAY, MINSPERHOUR, noise, oadd(), SECSPERHOUR, SECSPERMIN, sign, warning(), and ZIC_MAX.

Referenced by getleapdatetime(), getsave(), inzsub(), and rulesub().

◆ getleapdatetime()

static zic_t getleapdatetime ( char **  fields,
int  nfields,
bool  expire_line 
)
static

Definition at line 1666 of file zic.c.

1667{
1668 const char *cp;
1669 const struct lookup *lp;
1670 zic_t i,
1671 j;
1672
1673 /* PG: make year be int not zic_t to avoid sscanf portability issues */
1674 int year;
1675 int month,
1676 day;
1677 zic_t dayoff,
1678 tod;
1679 zic_t t;
1680 char xs;
1681
1682 dayoff = 0;
1683 cp = fields[LP_YEAR];
1684 if (sscanf(cp, "%d%c", &year, &xs) != 1)
1685 {
1686 /*
1687 * Leapin' Lizards!
1688 */
1689 error(_("invalid leaping year"));
1690 return -1;
1691 }
1692 if (!expire_line)
1693 {
1694 if (!leapseen || leapmaxyear < year)
1695 leapmaxyear = year;
1696 if (!leapseen || leapminyear > year)
1697 leapminyear = year;
1698 leapseen = true;
1699 }
1700 j = EPOCH_YEAR;
1701 while (j != year)
1702 {
1703 if (year > j)
1704 {
1705 i = len_years[isleap(j)];
1706 ++j;
1707 }
1708 else
1709 {
1710 --j;
1711 i = -len_years[isleap(j)];
1712 }
1713 dayoff = oadd(dayoff, i);
1714 }
1715 if ((lp = byword(fields[LP_MONTH], mon_names)) == NULL)
1716 {
1717 error(_("invalid month name"));
1718 return -1;
1719 }
1720 month = lp->l_value;
1721 j = TM_JANUARY;
1722 while (j != month)
1723 {
1724 i = len_months[isleap(year)][j];
1725 dayoff = oadd(dayoff, i);
1726 ++j;
1727 }
1728 cp = fields[LP_DAY];
1729 if (sscanf(cp, "%d%c", &day, &xs) != 1 ||
1730 day <= 0 || day > len_months[isleap(year)][month])
1731 {
1732 error(_("invalid day of month"));
1733 return -1;
1734 }
1735 dayoff = oadd(dayoff, day - 1);
1736 if (dayoff < min_time / SECSPERDAY)
1737 {
1738 error(_("time too small"));
1739 return -1;
1740 }
1741 if (dayoff > max_time / SECSPERDAY)
1742 {
1743 error(_("time too large"));
1744 return -1;
1745 }
1746 t = dayoff * SECSPERDAY;
1747 tod = gethms(fields[LP_TIME], _("invalid time of day"));
1748 t = tadd(t, tod);
1749 if (t < 0)
1750 error(_("leap second precedes Epoch"));
1751 return t;
1752}
#define isleap(y)
Definition: datetime.h:271
#define TM_JANUARY
Definition: private.h:115
#define EPOCH_YEAR
Definition: private.h:130
const int l_value
Definition: zic.c:306
static zic_t gethms(const char *string, const char *errstring)
Definition: zic.c:1365
#define LP_MONTH
Definition: zic.c:265
static struct lookup const mon_names[]
Definition: zic.c:324
static bool leapseen
Definition: zic.c:180
#define LP_TIME
Definition: zic.c:267
static zic_t leapminyear
Definition: zic.c:181
#define LP_YEAR
Definition: zic.c:264
static const int len_months[2][MONSPERYEAR]
Definition: zic.c:381
static zic_t leapmaxyear
Definition: zic.c:182
static struct lookup const * byword(const char *word, const struct lookup *table)
Definition: zic.c:3651
static zic_t const max_time
Definition: zic.c:586
static zic_t const min_time
Definition: zic.c:585
#define LP_DAY
Definition: zic.c:266
static const int len_years[2]
Definition: zic.c:386

References _, byword(), EPOCH_YEAR, error(), gethms(), i, isleap, j, lookup::l_value, leapmaxyear, leapminyear, leapseen, len_months, len_years, LP_DAY, LP_MONTH, LP_TIME, LP_YEAR, max_time, min_time, mon_names, oadd(), SECSPERDAY, tadd(), and TM_JANUARY.

Referenced by inexpires(), and inleap().

◆ getsave()

static zic_t getsave ( char *  field,
bool *  isdst 
)
static

Definition at line 1443 of file zic.c.

1444{
1445 int dst = -1;
1446 zic_t save;
1447 size_t fieldlen = strlen(field);
1448
1449 if (fieldlen != 0)
1450 {
1451 char *ep = field + fieldlen - 1;
1452
1453 switch (*ep)
1454 {
1455 case 'd':
1456 dst = 1;
1457 *ep = '\0';
1458 break;
1459 case 's':
1460 dst = 0;
1461 *ep = '\0';
1462 break;
1463 }
1464 }
1465 save = gethms(field, _("invalid saved time"));
1466 *isdst = dst < 0 ? save != 0 : dst;
1467 return save;
1468}

References _, and gethms().

Referenced by associate(), and inrule().

◆ growalloc()

static void * growalloc ( void *  ptr,
size_t  itemsize,
ptrdiff_t  nitems,
ptrdiff_t *  nitems_alloc 
)
static

Definition at line 452 of file zic.c.

453{
454 if (nitems < *nitems_alloc)
455 return ptr;
456 else
457 {
458 ptrdiff_t nitems_max = PTRDIFF_MAX - WORK_AROUND_QTBUG_53071;
459 ptrdiff_t amax = nitems_max < SIZE_MAX ? nitems_max : SIZE_MAX;
460
461 if ((amax - 1) / 3 * 2 < *nitems_alloc)
462 memory_exhausted(_("integer overflow"));
463 *nitems_alloc += (*nitems_alloc >> 1) + 1;
464 return erealloc(ptr, size_product(*nitems_alloc, itemsize));
465 }
466}
#define nitems(x)
Definition: indent.h:31
static ptrdiff_t const PTRDIFF_MAX
Definition: zic.c:47
static void * erealloc(void *ptr, size_t size)
Definition: zic.c:440
static void memory_exhausted(const char *msg) pg_attribute_noreturn()
Definition: zic.c:411

References _, erealloc(), memory_exhausted(), nitems, PTRDIFF_MAX, size_product(), and WORK_AROUND_QTBUG_53071.

Referenced by addtt(), inlink(), inrule(), and inzsub().

◆ hardlinkerr()

static int hardlinkerr ( char const *  target,
char const *  linkname 
)
static

Definition at line 996 of file zic.c.

997{
998 int r = linkat(AT_FDCWD, target, AT_FDCWD, linkname, AT_SYMLINK_FOLLOW);
999
1000 return r == 0 ? 0 : errno;
1001}
#define linkat(targetdir, target, linknamedir, linkname, flag)
Definition: zic.c:116

References linkat.

Referenced by dolink().

◆ inexpires()

static void inexpires ( char **  fields,
int  nfields 
)
static

Definition at line 1787 of file zic.c.

1788{
1789 if (nfields != EXPIRES_FIELDS)
1790 error(_("wrong number of fields on Expires line"));
1791 else if (0 <= leapexpires)
1792 error(_("multiple Expires lines"));
1793 else
1794 leapexpires = getleapdatetime(fields, nfields, true);
1795}
static zic_t getleapdatetime(char **fields, int nfields, bool expire_line)
Definition: zic.c:1666
#define EXPIRES_FIELDS
Definition: zic.c:273

References _, error(), EXPIRES_FIELDS, getleapdatetime(), and leapexpires.

Referenced by infile().

◆ infile()

static void infile ( const char *  name)
static

Definition at line 1243 of file zic.c.

1244{
1245 FILE *fp;
1246 char **fields;
1247 char *cp;
1248 const struct lookup *lp;
1249 int nfields;
1250 bool wantcont;
1251 lineno_t num;
1252 char buf[BUFSIZ];
1253
1254 if (strcmp(name, "-") == 0)
1255 {
1256 name = _("standard input");
1257 fp = stdin;
1258 }
1259 else if ((fp = fopen(name, "r")) == NULL)
1260 {
1261 const char *e = strerror(errno);
1262
1263 fprintf(stderr, _("%s: Cannot open %s: %s\n"),
1264 progname, name, e);
1266 }
1267 wantcont = false;
1268 for (num = 1;; ++num)
1269 {
1270 eat(name, num);
1271 if (fgets(buf, sizeof buf, fp) != buf)
1272 break;
1273 cp = strchr(buf, '\n');
1274 if (cp == NULL)
1275 {
1276 error(_("line too long"));
1278 }
1279 *cp = '\0';
1280 fields = getfields(buf);
1281 nfields = 0;
1282 while (fields[nfields] != NULL)
1283 {
1284 static char nada;
1285
1286 if (strcmp(fields[nfields], "-") == 0)
1287 fields[nfields] = &nada;
1288 ++nfields;
1289 }
1290 if (nfields == 0)
1291 {
1292 if (name == leapsec && *buf == '#')
1293 {
1294 /*
1295 * PG: INT64_FORMAT isn't portable for sscanf, so be content
1296 * with scanning a "long". Once we are requiring C99 in all
1297 * live branches, it'd be sensible to adopt upstream's
1298 * practice of using the <inttypes.h> macros. But for now, we
1299 * don't actually use this code, and it won't overflow before
1300 * 2038 anyway.
1301 */
1302 long cl_tmp;
1303
1304 sscanf(buf, "#expires %ld", &cl_tmp);
1305 comment_leapexpires = cl_tmp;
1306 }
1307 }
1308 else if (wantcont)
1309 {
1310 wantcont = inzcont(fields, nfields);
1311 }
1312 else
1313 {
1314 struct lookup const *line_codes
1316
1317 lp = byword(fields[0], line_codes);
1318 if (lp == NULL)
1319 error(_("input line of unknown type"));
1320 else
1321 switch (lp->l_value)
1322 {
1323 case LC_RULE:
1324 inrule(fields, nfields);
1325 wantcont = false;
1326 break;
1327 case LC_ZONE:
1328 wantcont = inzone(fields, nfields);
1329 break;
1330 case LC_LINK:
1331 inlink(fields, nfields);
1332 wantcont = false;
1333 break;
1334 case LC_LEAP:
1335 inleap(fields, nfields);
1336 wantcont = false;
1337 break;
1338 case LC_EXPIRES:
1339 inexpires(fields, nfields);
1340 wantcont = false;
1341 break;
1342 default: /* "cannot happen" */
1343 fprintf(stderr,
1344 _("%s: panic: Invalid l_value %d\n"),
1345 progname, lp->l_value);
1347 }
1348 }
1349 free(fields);
1350 }
1351 close_file(fp, NULL, filename);
1352 if (wantcont)
1353 error(_("expected continuation line not found"));
1354}
static const char * leapsec
Definition: zic.c:635
#define LC_EXPIRES
Definition: zic.c:206
#define LC_LINK
Definition: zic.c:204
static void inleap(char **fields, int nfields)
Definition: zic.c:1755
int lineno_t
Definition: zic.c:55
static bool inzone(char **fields, int nfields)
Definition: zic.c:1518
#define LC_RULE
Definition: zic.c:202
static bool inzcont(char **fields, int nfields)
Definition: zic.c:1556
static struct lookup const zi_line_codes[]
Definition: zic.c:312
static void inexpires(char **fields, int nfields)
Definition: zic.c:1787
static void inrule(char **fields, int nfields)
Definition: zic.c:1471
#define LC_LEAP
Definition: zic.c:205
#define LC_ZONE
Definition: zic.c:203
static char ** getfields(char *cp)
Definition: zic.c:3717
static struct lookup const leap_line_codes[]
Definition: zic.c:318
static void inlink(char **fields, int nfields)
Definition: zic.c:1798

References _, buf, byword(), close_file(), comment_leapexpires, eat(), error(), exit(), EXIT_FAILURE, filename, fprintf, free, getfields(), inexpires(), inleap(), inlink(), inrule(), inzcont(), inzone(), lookup::l_value, LC_EXPIRES, LC_LEAP, LC_LINK, LC_RULE, LC_ZONE, leap_line_codes, leapsec, name, progname, strerror, and zi_line_codes.

Referenced by AlterSystemSetConfigFile(), isolation_start_test(), main(), psql_start_test(), and readfile().

◆ inleap()

static void inleap ( char **  fields,
int  nfields 
)
static

Definition at line 1755 of file zic.c.

1756{
1757 if (nfields != LEAP_FIELDS)
1758 error(_("wrong number of fields on Leap line"));
1759 else
1760 {
1761 zic_t t = getleapdatetime(fields, nfields, false);
1762
1763 if (0 <= t)
1764 {
1765 struct lookup const *lp = byword(fields[LP_ROLL], leap_types);
1766
1767 if (!lp)
1768 error(_("invalid Rolling/Stationary field on Leap line"));
1769 else
1770 {
1771 int correction = 0;
1772
1773 if (!fields[LP_CORR][0]) /* infile() turns "-" into "". */
1774 correction = -1;
1775 else if (strcmp(fields[LP_CORR], "+") == 0)
1776 correction = 1;
1777 else
1778 error(_("invalid CORRECTION field on Leap line"));
1779 if (correction)
1780 leapadd(t, correction, lp->l_value);
1781 }
1782 }
1783 }
1784}
static struct lookup const leap_types[]
Definition: zic.c:375
#define LP_CORR
Definition: zic.c:268
#define LEAP_FIELDS
Definition: zic.c:270
#define LP_ROLL
Definition: zic.c:269
static void leapadd(zic_t t, int correction, int rolling)
Definition: zic.c:3403

References _, byword(), error(), getleapdatetime(), lookup::l_value, LEAP_FIELDS, leap_types, leapadd(), LP_CORR, and LP_ROLL.

Referenced by infile().

◆ inlink()

static void inlink ( char **  fields,
int  nfields 
)
static

Definition at line 1798 of file zic.c.

1799{
1800 struct link l;
1801
1802 if (nfields != LINK_FIELDS)
1803 {
1804 error(_("wrong number of fields on Link line"));
1805 return;
1806 }
1807 if (*fields[LF_TARGET] == '\0')
1808 {
1809 error(_("blank TARGET field on Link line"));
1810 return;
1811 }
1812 if (!namecheck(fields[LF_LINKNAME]))
1813 return;
1814 l.l_filename = filename;
1815 l.l_linenum = linenum;
1816 l.l_target = ecpyalloc(fields[LF_TARGET]);
1817 l.l_linkname = ecpyalloc(fields[LF_LINKNAME]);
1819 links[nlinks++] = l;
1820}
static ptrdiff_t nlinks
Definition: zic.c:300
#define LINK_FIELDS
Definition: zic.c:258
#define LF_LINKNAME
Definition: zic.c:257
static ptrdiff_t nlinks_alloc
Definition: zic.c:301
#define LF_TARGET
Definition: zic.c:256
static char * ecpyalloc(char const *str)
Definition: zic.c:446
static bool namecheck(const char *name)
Definition: zic.c:903
static struct link * links
Definition: zic.c:299

References _, ecpyalloc(), error(), filename, growalloc(), link::l_filename, link::l_linenum, link::l_linkname, link::l_target, LF_LINKNAME, LF_TARGET, linenum, LINK_FIELDS, links, namecheck(), nlinks, and nlinks_alloc.

Referenced by infile().

◆ inrule()

static void inrule ( char **  fields,
int  nfields 
)
static

Definition at line 1471 of file zic.c.

1472{
1473 static struct rule r;
1474
1475 if (nfields != RULE_FIELDS)
1476 {
1477 error(_("wrong number of fields on Rule line"));
1478 return;
1479 }
1480 switch (*fields[RF_NAME])
1481 {
1482 case '\0':
1483 case ' ':
1484 case '\f':
1485 case '\n':
1486 case '\r':
1487 case '\t':
1488 case '\v':
1489 case '+':
1490 case '-':
1491 case '0':
1492 case '1':
1493 case '2':
1494 case '3':
1495 case '4':
1496 case '5':
1497 case '6':
1498 case '7':
1499 case '8':
1500 case '9':
1501 error(_("Invalid rule name \"%s\""), fields[RF_NAME]);
1502 return;
1503 }
1504 r.r_filename = filename;
1505 r.r_linenum = linenum;
1506 r.r_save = getsave(fields[RF_SAVE], &r.r_isdst);
1507 rulesub(&r, fields[RF_LOYEAR], fields[RF_HIYEAR], fields[RF_COMMAND],
1508 fields[RF_MONTH], fields[RF_DAY], fields[RF_TOD]);
1509 r.r_name = ecpyalloc(fields[RF_NAME]);
1510 r.r_abbrvar = ecpyalloc(fields[RF_ABBRVAR]);
1511 if (max_abbrvar_len < strlen(r.r_abbrvar))
1512 max_abbrvar_len = strlen(r.r_abbrvar);
1514 rules[nrules++] = r;
1515}
#define RF_LOYEAR
Definition: zic.c:242
#define RF_SAVE
Definition: zic.c:248
#define RF_ABBRVAR
Definition: zic.c:249
static int max_abbrvar_len
Definition: zic.c:184
#define RF_HIYEAR
Definition: zic.c:243
#define RF_TOD
Definition: zic.c:247
#define RF_COMMAND
Definition: zic.c:244
#define RF_NAME
Definition: zic.c:241
static ptrdiff_t nrules_alloc
Definition: zic.c:285
#define RF_DAY
Definition: zic.c:246
static void rulesub(struct rule *rp, const char *loyearp, const char *hiyearp, const char *typep, const char *monthp, const char *dayp, const char *timep)
Definition: zic.c:1823
#define RULE_FIELDS
Definition: zic.c:250
#define RF_MONTH
Definition: zic.c:245

References _, ecpyalloc(), error(), filename, getsave(), growalloc(), linenum, max_abbrvar_len, nrules, nrules_alloc, rule::r_abbrvar, rule::r_filename, rule::r_isdst, rule::r_linenum, rule::r_name, rule::r_save, RF_ABBRVAR, RF_COMMAND, RF_DAY, RF_HIYEAR, RF_LOYEAR, RF_MONTH, RF_NAME, RF_SAVE, RF_TOD, RULE_FIELDS, rules, and rulesub().

Referenced by infile().

◆ inzcont()

static bool inzcont ( char **  fields,
int  nfields 
)
static

Definition at line 1556 of file zic.c.

1557{
1558 if (nfields < ZONEC_MINFIELDS || nfields > ZONEC_MAXFIELDS)
1559 {
1560 error(_("wrong number of fields on Zone continuation line"));
1561 return false;
1562 }
1563 return inzsub(fields, nfields, true);
1564}
#define ZONEC_MAXFIELDS
Definition: zic.c:235
static bool inzsub(char **fields, int nfields, bool iscont)
Definition: zic.c:1567

References _, error(), inzsub(), and ZONEC_MAXFIELDS.

Referenced by infile().

◆ inzone()

static bool inzone ( char **  fields,
int  nfields 
)
static

Definition at line 1518 of file zic.c.

1519{
1520 ptrdiff_t i;
1521
1522 if (nfields < ZONE_MINFIELDS || nfields > ZONE_MAXFIELDS)
1523 {
1524 error(_("wrong number of fields on Zone line"));
1525 return false;
1526 }
1527 if (lcltime != NULL && strcmp(fields[ZF_NAME], tzdefault) == 0)
1528 {
1529 error(
1530 _("\"Zone %s\" line and -l option are mutually exclusive"),
1531 tzdefault);
1532 return false;
1533 }
1534 if (strcmp(fields[ZF_NAME], TZDEFRULES) == 0 && psxrules != NULL)
1535 {
1536 error(
1537 _("\"Zone %s\" line and -p option are mutually exclusive"),
1538 TZDEFRULES);
1539 return false;
1540 }
1541 for (i = 0; i < nzones; ++i)
1542 if (zones[i].z_name != NULL &&
1543 strcmp(zones[i].z_name, fields[ZF_NAME]) == 0)
1544 {
1545 error(_("duplicate zone name %s"
1546 " (file \"%s\", line %d)"),
1547 fields[ZF_NAME],
1548 zones[i].z_filename,
1549 zones[i].z_linenum);
1550 return false;
1551 }
1552 return inzsub(fields, nfields, false);
1553}
#define TZDEFRULES
Definition: tzfile.h:28
#define ZONE_MAXFIELDS
Definition: zic.c:221
static const char * lcltime
Definition: zic.c:633
static const char * psxrules
Definition: zic.c:632
#define ZF_NAME
Definition: zic.c:212
static const char * tzdefault
Definition: zic.c:636

References _, error(), i, inzsub(), lcltime, nzones, psxrules, tzdefault, TZDEFRULES, ZF_NAME, ZONE_MAXFIELDS, and zones.

Referenced by infile().

◆ inzsub()

static bool inzsub ( char **  fields,
int  nfields,
bool  iscont 
)
static

Definition at line 1567 of file zic.c.

1568{
1569 char *cp;
1570 char *cp1;
1571 static struct zone z;
1572 int i_stdoff,
1573 i_rule,
1574 i_format;
1575 int i_untilyear,
1576 i_untilmonth;
1577 int i_untilday,
1578 i_untiltime;
1579 bool hasuntil;
1580
1581 if (iscont)
1582 {
1583 i_stdoff = ZFC_STDOFF;
1584 i_rule = ZFC_RULE;
1585 i_format = ZFC_FORMAT;
1586 i_untilyear = ZFC_TILYEAR;
1587 i_untilmonth = ZFC_TILMONTH;
1588 i_untilday = ZFC_TILDAY;
1589 i_untiltime = ZFC_TILTIME;
1590 z.z_name = NULL;
1591 }
1592 else if (!namecheck(fields[ZF_NAME]))
1593 return false;
1594 else
1595 {
1596 i_stdoff = ZF_STDOFF;
1597 i_rule = ZF_RULE;
1598 i_format = ZF_FORMAT;
1599 i_untilyear = ZF_TILYEAR;
1600 i_untilmonth = ZF_TILMONTH;
1601 i_untilday = ZF_TILDAY;
1602 i_untiltime = ZF_TILTIME;
1603 z.z_name = ecpyalloc(fields[ZF_NAME]);
1604 }
1605 z.z_filename = filename;
1606 z.z_linenum = linenum;
1607 z.z_stdoff = gethms(fields[i_stdoff], _("invalid UT offset"));
1608 if ((cp = strchr(fields[i_format], '%')) != NULL)
1609 {
1610 if ((*++cp != 's' && *cp != 'z') || strchr(cp, '%')
1611 || strchr(fields[i_format], '/'))
1612 {
1613 error(_("invalid abbreviation format"));
1614 return false;
1615 }
1616 }
1617 z.z_rule = ecpyalloc(fields[i_rule]);
1618 z.z_format = cp1 = ecpyalloc(fields[i_format]);
1619 z.z_format_specifier = cp ? *cp : '\0';
1620 if (z.z_format_specifier == 'z')
1621 {
1622 if (noise)
1623 warning(_("format '%s' not handled by pre-2015 versions of zic"),
1624 z.z_format);
1625 cp1[cp - fields[i_format]] = 's';
1626 }
1627 if (max_format_len < strlen(z.z_format))
1628 max_format_len = strlen(z.z_format);
1629 hasuntil = nfields > i_untilyear;
1630 if (hasuntil)
1631 {
1632 z.z_untilrule.r_filename = filename;
1633 z.z_untilrule.r_linenum = linenum;
1634 rulesub(&z.z_untilrule,
1635 fields[i_untilyear],
1636 "only",
1637 "",
1638 (nfields > i_untilmonth) ?
1639 fields[i_untilmonth] : "Jan",
1640 (nfields > i_untilday) ? fields[i_untilday] : "1",
1641 (nfields > i_untiltime) ? fields[i_untiltime] : "0");
1642 z.z_untiltime = rpytime(&z.z_untilrule,
1643 z.z_untilrule.r_loyear);
1644 if (iscont && nzones > 0 &&
1645 z.z_untiltime > min_time &&
1646 z.z_untiltime < max_time &&
1649 zones[nzones - 1].z_untiltime >= z.z_untiltime)
1650 {
1651 error(_("Zone continuation line end time is not after end time of previous line"));
1652 return false;
1653 }
1654 }
1656 zones[nzones++] = z;
1657
1658 /*
1659 * If there was an UNTIL field on this line, there's more information
1660 * about the zone on the next line.
1661 */
1662 return hasuntil;
1663}
zic_t z_untiltime
Definition: zic.c:111
#define ZF_FORMAT
Definition: zic.c:215
#define ZFC_TILDAY
Definition: zic.c:232
#define ZFC_TILYEAR
Definition: zic.c:230
#define ZF_RULE
Definition: zic.c:214
#define ZFC_TILMONTH
Definition: zic.c:231
#define ZFC_STDOFF
Definition: zic.c:227
#define ZF_TILYEAR
Definition: zic.c:216
#define ZF_TILDAY
Definition: zic.c:218
#define ZFC_RULE
Definition: zic.c:228
static int max_format_len
Definition: zic.c:185
static ptrdiff_t nzones_alloc
Definition: zic.c:289
#define ZFC_TILTIME
Definition: zic.c:233
static zic_t rpytime(const struct rule *rp, zic_t wantedy)
Definition: zic.c:3801
#define ZF_STDOFF
Definition: zic.c:213
#define ZF_TILMONTH
Definition: zic.c:217
#define ZF_TILTIME
Definition: zic.c:219
#define ZFC_FORMAT
Definition: zic.c:229

References _, ecpyalloc(), error(), filename, gethms(), growalloc(), linenum, max_format_len, max_time, min_time, namecheck(), noise, nzones, nzones_alloc, rule::r_filename, rule::r_linenum, rule::r_loyear, rpytime(), rulesub(), warning(), zone::z_filename, zone::z_format, zone::z_format_specifier, zone::z_linenum, zone::z_name, zone::z_rule, zone::z_stdoff, zone::z_untilrule, zone::z_untiltime, ZF_FORMAT, ZF_NAME, ZF_RULE, ZF_STDOFF, ZF_TILDAY, ZF_TILMONTH, ZF_TILTIME, ZF_TILYEAR, ZFC_FORMAT, ZFC_RULE, ZFC_STDOFF, ZFC_TILDAY, ZFC_TILMONTH, ZFC_TILTIME, ZFC_TILYEAR, and zones.

Referenced by inzcont(), and inzone().

◆ is_alpha()

static bool is_alpha ( char  a)
static

Definition at line 3486 of file zic.c.

3487{
3488 switch (a)
3489 {
3490 default:
3491 return false;
3492 case 'A':
3493 case 'B':
3494 case 'C':
3495 case 'D':
3496 case 'E':
3497 case 'F':
3498 case 'G':
3499 case 'H':
3500 case 'I':
3501 case 'J':
3502 case 'K':
3503 case 'L':
3504 case 'M':
3505 case 'N':
3506 case 'O':
3507 case 'P':
3508 case 'Q':
3509 case 'R':
3510 case 'S':
3511 case 'T':
3512 case 'U':
3513 case 'V':
3514 case 'W':
3515 case 'X':
3516 case 'Y':
3517 case 'Z':
3518 case 'a':
3519 case 'b':
3520 case 'c':
3521 case 'd':
3522 case 'e':
3523 case 'f':
3524 case 'g':
3525 case 'h':
3526 case 'i':
3527 case 'j':
3528 case 'k':
3529 case 'l':
3530 case 'm':
3531 case 'n':
3532 case 'o':
3533 case 'p':
3534 case 'q':
3535 case 'r':
3536 case 's':
3537 case 't':
3538 case 'u':
3539 case 'v':
3540 case 'w':
3541 case 'x':
3542 case 'y':
3543 case 'z':
3544 return true;
3545 }
3546}

References a.

Referenced by doabbr(), and newabbr().

◆ is_space()

static bool is_space ( char  a)
static

Definition at line 3468 of file zic.c.

3469{
3470 switch (a)
3471 {
3472 default:
3473 return false;
3474 case ' ':
3475 case '\f':
3476 case '\n':
3477 case '\r':
3478 case '\t':
3479 case '\v':
3480 return true;
3481 }
3482}

References a.

Referenced by getfields().

◆ itsabbr()

static bool itsabbr ( const char *  abbr,
const char *  word 
)
static

Definition at line 3623 of file zic.c.

3624{
3625 if (lowerit(*abbr) != lowerit(*word))
3626 return false;
3627 ++word;
3628 while (*++abbr != '\0')
3629 do
3630 {
3631 if (*word == '\0')
3632 return false;
3633 } while (lowerit(*word++) != lowerit(*abbr));
3634 return true;
3635}

References lowerit(), and word().

Referenced by byword().

◆ itsdir()

static bool itsdir ( char const *  name)
static

Definition at line 1106 of file zic.c.

1107{
1108 struct stat st;
1109 int res = stat(name, &st);
1110#ifdef S_ISDIR
1111 if (res == 0)
1112 return S_ISDIR(st.st_mode) != 0;
1113#endif
1114 if (res == 0 || errno == EOVERFLOW)
1115 {
1116 size_t n = strlen(name);
1117 char *nameslashdot = emalloc(n + 3);
1118 bool dir;
1119
1120 memcpy(nameslashdot, name, n);
1121 strcpy(&nameslashdot[n], &"/."[!(n && name[n - 1] != '/')]);
1122 dir = stat(nameslashdot, &st) == 0 || errno == EOVERFLOW;
1123 free(nameslashdot);
1124 return dir;
1125 }
1126 return false;
1127}
#define EOVERFLOW
Definition: private.h:41
#define stat
Definition: win32_port.h:274
#define S_ISDIR(m)
Definition: win32_port.h:315

References emalloc(), EOVERFLOW, free, name, res, S_ISDIR, stat::st_mode, and stat.

Referenced by dolink(), and mkdirs().

◆ itssymlink()

static bool itssymlink ( char const *  name)
static

Definition at line 1131 of file zic.c.

1132{
1133#ifdef HAVE_SYMLINK
1134 char c;
1135
1136 return 0 <= readlink(name, &c, 1);
1137#else
1138 return false;
1139#endif
1140}
#define readlink(path, buf, size)
Definition: win32_port.h:226

References name, and readlink.

Referenced by dolink().

◆ leapadd()

static void leapadd ( zic_t  t,
int  correction,
int  rolling 
)
static

Definition at line 3403 of file zic.c.

3404{
3405 int i;
3406
3407 if (TZ_MAX_LEAPS <= leapcnt)
3408 {
3409 error(_("too many leap seconds"));
3411 }
3412 for (i = 0; i < leapcnt; ++i)
3413 if (t <= trans[i])
3414 break;
3415 memmove(&trans[i + 1], &trans[i], (leapcnt - i) * sizeof *trans);
3416 memmove(&corr[i + 1], &corr[i], (leapcnt - i) * sizeof *corr);
3417 memmove(&roll[i + 1], &roll[i], (leapcnt - i) * sizeof *roll);
3418 trans[i] = t;
3419 corr[i] = correction;
3420 roll[i] = rolling;
3421 ++leapcnt;
3422}
#define TZ_MAX_LEAPS
Definition: tzfile.h:108
static char roll[TZ_MAX_LEAPS]
Definition: zic.c:404

References _, corr, error(), exit(), EXIT_FAILURE, i, leapcnt, roll, trans, and TZ_MAX_LEAPS.

Referenced by inleap().

◆ limitrange()

static struct timerange limitrange ( struct timerange  r,
zic_t  lo,
zic_t  hi,
zic_t const *  ats,
unsigned char const *  types 
)
static

Definition at line 2055 of file zic.c.

2057{
2058 while (0 < r.count && ats[r.base] < lo)
2059 {
2060 r.defaulttype = types[r.base];
2061 r.count--;
2062 r.base++;
2063 }
2064 while (0 < r.leapcount && trans[r.leapbase] < lo)
2065 {
2066 r.leapcount--;
2067 r.leapbase++;
2068 }
2069
2070 if (hi < ZIC_MAX)
2071 {
2072 while (0 < r.count && hi + 1 < ats[r.base + r.count - 1])
2073 r.count--;
2074 while (0 < r.leapcount && hi + 1 < trans[r.leapbase + r.leapcount - 1])
2075 r.leapcount--;
2076 }
2077
2078 return r;
2079}
struct typedefs * types
Definition: ecpg.c:30
int leapbase
Definition: zic.c:2050
ptrdiff_t count
Definition: zic.c:2049
ptrdiff_t base
Definition: zic.c:2048
int leapcount
Definition: zic.c:2051
int defaulttype
Definition: zic.c:2047

References timerange::defaulttype, trans, types, and ZIC_MAX.

Referenced by writezone().

◆ link()

int link ( const char *  target,
const char *  linkname 
)

Definition at line 18 of file win32link.c.

19{
20 /*
21 * CreateHardLinkA returns zero for failure
22 * https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createhardlinka
23 */
24 if (CreateHardLinkA(dst, src, NULL) == 0)
25 {
26 _dosmaperr(GetLastError());
27 return -1;
28 }
29 else
30 return 0;
31}
void _dosmaperr(unsigned long)
Definition: win32error.c:177

References _dosmaperr().

Referenced by AllocSetAllocFromNewBlock(), AllocSetFree(), check_hard_link(), and linkFile().

◆ lowerit()

static char lowerit ( char  a)
static

Definition at line 3551 of file zic.c.

3552{
3553 switch (a)
3554 {
3555 default:
3556 return a;
3557 case 'A':
3558 return 'a';
3559 case 'B':
3560 return 'b';
3561 case 'C':
3562 return 'c';
3563 case 'D':
3564 return 'd';
3565 case 'E':
3566 return 'e';
3567 case 'F':
3568 return 'f';
3569 case 'G':
3570 return 'g';
3571 case 'H':
3572 return 'h';
3573 case 'I':
3574 return 'i';
3575 case 'J':
3576 return 'j';
3577 case 'K':
3578 return 'k';
3579 case 'L':
3580 return 'l';
3581 case 'M':
3582 return 'm';
3583 case 'N':
3584 return 'n';
3585 case 'O':
3586 return 'o';
3587 case 'P':
3588 return 'p';
3589 case 'Q':
3590 return 'q';
3591 case 'R':
3592 return 'r';
3593 case 'S':
3594 return 's';
3595 case 'T':
3596 return 't';
3597 case 'U':
3598 return 'u';
3599 case 'V':
3600 return 'v';
3601 case 'W':
3602 return 'w';
3603 case 'X':
3604 return 'x';
3605 case 'Y':
3606 return 'y';
3607 case 'Z':
3608 return 'z';
3609 }
3610}

References a.

Referenced by ciequal(), ciprefix(), itsabbr(), and rulesub().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 654 of file zic.c.

655{
656 int c,
657 k;
658 ptrdiff_t i,
659 j;
660 bool timerange_given = false;
661
662#ifndef WIN32
663 umask(umask(S_IWGRP | S_IWOTH) | (S_IWGRP | S_IWOTH));
664#endif
665 progname = argv[0];
666 if (TYPE_BIT(zic_t) < 64)
667 {
668 fprintf(stderr, "%s: %s\n", progname,
669 _("wild compilation-time specification of zic_t"));
670 return EXIT_FAILURE;
671 }
672 for (k = 1; k < argc; k++)
673 if (strcmp(argv[k], "--version") == 0)
674 {
675 printf("zic %s\n", PG_VERSION);
676 close_file(stdout, NULL, NULL);
677 return EXIT_SUCCESS;
678 }
679 else if (strcmp(argv[k], "--help") == 0)
680 {
682 }
683 while ((c = getopt(argc, argv, "b:d:l:L:p:Pr:st:vy:")) != EOF && c != -1)
684 switch (c)
685 {
686 default:
687 usage(stderr, EXIT_FAILURE);
688 case 'b':
689 if (strcmp(optarg, "slim") == 0)
690 {
691 if (0 < bloat)
692 error(_("incompatible -b options"));
693 bloat = -1;
694 }
695 else if (strcmp(optarg, "fat") == 0)
696 {
697 if (bloat < 0)
698 error(_("incompatible -b options"));
699 bloat = 1;
700 }
701 else
702 error(_("invalid option: -b '%s'"), optarg);
703 break;
704 case 'd':
705 if (directory == NULL)
706 directory = strdup(optarg);
707 else
708 {
709 fprintf(stderr,
710 _("%s: More than one -d option specified\n"),
711 progname);
712 return EXIT_FAILURE;
713 }
714 break;
715 case 'l':
716 if (lcltime == NULL)
717 lcltime = strdup(optarg);
718 else
719 {
720 fprintf(stderr,
721 _("%s: More than one -l option specified\n"),
722 progname);
723 return EXIT_FAILURE;
724 }
725 break;
726 case 'p':
727 if (psxrules == NULL)
728 psxrules = strdup(optarg);
729 else
730 {
731 fprintf(stderr,
732 _("%s: More than one -p option specified\n"),
733 progname);
734 return EXIT_FAILURE;
735 }
736 break;
737 case 't':
738 if (tzdefault != NULL)
739 {
740 fprintf(stderr,
741 _("%s: More than one -t option"
742 " specified\n"),
743 progname);
744 return EXIT_FAILURE;
745 }
747 break;
748 case 'y':
749 warning(_("-y ignored"));
750 break;
751 case 'L':
752 if (leapsec == NULL)
753 leapsec = strdup(optarg);
754 else
755 {
756 fprintf(stderr,
757 _("%s: More than one -L option specified\n"),
758 progname);
759 return EXIT_FAILURE;
760 }
761 break;
762 case 'v':
763 noise = true;
764 break;
765 case 'P':
766 print_abbrevs = true;
767 print_cutoff = time(NULL);
768 break;
769 case 'r':
770 if (timerange_given)
771 {
772 fprintf(stderr,
773 _("%s: More than one -r option specified\n"),
774 progname);
775 return EXIT_FAILURE;
776 }
778 {
779 fprintf(stderr,
780 _("%s: invalid time range: %s\n"),
782 return EXIT_FAILURE;
783 }
784 timerange_given = true;
785 break;
786 case 's':
787 warning(_("-s ignored"));
788 break;
789 }
790 if (optind == argc - 1 && strcmp(argv[optind], "=") == 0)
791 usage(stderr, EXIT_FAILURE); /* usage message by request */
792 if (bloat == 0)
793 {
794 static char const bloat_default[] = ZIC_BLOAT_DEFAULT;
795
796 if (strcmp(bloat_default, "slim") == 0)
797 bloat = -1;
798 else if (strcmp(bloat_default, "fat") == 0)
799 bloat = 1;
800 else
801 abort(); /* Configuration error. */
802 }
803 if (directory == NULL)
804 directory = "data";
805 if (tzdefault == NULL)
807
808 if (optind < argc && leapsec != NULL)
809 {
811 adjleap();
812 }
813
814 for (k = optind; k < argc; k++)
815 infile(argv[k]);
816 if (errors)
817 return EXIT_FAILURE;
818 associate();
820 for (i = 0; i < nzones; i = j)
821 {
822 /*
823 * Find the next non-continuation zone entry.
824 */
825 for (j = i + 1; j < nzones && zones[j].z_name == NULL; ++j)
826 continue;
827 outzone(&zones[i], j - i);
828 }
829
830 /*
831 * Make links.
832 */
833 for (i = 0; i < nlinks; ++i)
834 {
835 eat(links[i].l_filename, links[i].l_linenum);
836 dolink(links[i].l_target, links[i].l_linkname, false);
837 if (noise)
838 for (j = 0; j < nlinks; ++j)
839 if (strcmp(links[i].l_linkname,
840 links[j].l_target) == 0)
841 warning(_("link to link"));
842 }
843 if (lcltime != NULL)
844 {
845 eat(_("command line"), 1);
846 dolink(lcltime, tzdefault, true);
847 }
848 if (psxrules != NULL)
849 {
850 eat(_("command line"), 1);
851 dolink(psxrules, TZDEFRULES, true);
852 }
853 if (warnings && (ferror(stderr) || fclose(stderr) != 0))
854 return EXIT_FAILURE;
856}
PGDLLIMPORT int optind
Definition: getopt.c:51
int getopt(int nargc, char *const *nargv, const char *ostr)
Definition: getopt.c:72
PGDLLIMPORT char * optarg
Definition: getopt.c:53
#define printf(...)
Definition: port.h:244
#define TYPE_BIT(type)
Definition: private.h:56
#define EXIT_SUCCESS
Definition: settings.h:174
const char * z_name
Definition: zic.c:98
#define TZDEFAULT
Definition: tzfile.h:27
#define S_IWOTH
Definition: win32_port.h:306
#define S_IWGRP
Definition: win32_port.h:294
#define ZIC_BLOAT_DEFAULT
Definition: zic.c:650
static void change_directory(char const *dir)
Definition: zic.c:562
static bool print_abbrevs
Definition: zic.c:189
static zic_t print_cutoff
Definition: zic.c:190
static int bloat
Definition: zic.c:641
static void outzone(const struct zone *zpfirst, ptrdiff_t zonecount)
Definition: zic.c:2946
static bool timerange_option(char *timerange)
Definition: zic.c:602
static bool warnings
Definition: zic.c:177
static void dolink(char const *target, char const *linkname, bool staysymlink)
Definition: zic.c:1004
static void infile(const char *name)
Definition: zic.c:1243
static void static void static void static void usage(FILE *stream, int status) pg_attribute_noreturn()
Definition: zic.c:543
static void adjleap(void)
Definition: zic.c:3425
static void associate(void)
Definition: zic.c:1158

References _, adjleap(), associate(), bloat, change_directory(), close_file(), directory, dolink(), eat(), error(), errors, EXIT_FAILURE, EXIT_SUCCESS, fprintf, getopt(), i, infile(), j, lcltime, leapsec, links, nlinks, noise, nzones, optarg, optind, outzone(), print_abbrevs, print_cutoff, printf, progname, psxrules, S_IWGRP, S_IWOTH, generate_unaccent_rules::stdout, timerange_option(), TYPE_BIT, TZDEFAULT, tzdefault, TZDEFRULES, usage(), warning(), warnings, zone::z_name, ZIC_BLOAT_DEFAULT, and zones.

◆ memcheck()

static void * memcheck ( void *  ptr)
static

Definition at line 426 of file zic.c.

427{
428 if (ptr == NULL)
430 return ptr;
431}

References memory_exhausted(), and strerror.

Referenced by ecpyalloc(), emalloc(), and erealloc().

◆ memory_exhausted()

static void memory_exhausted ( const char *  msg)
static

Definition at line 411 of file zic.c.

412{
413 fprintf(stderr, _("%s: Memory exhausted: %s\n"), progname, msg);
415}

References _, exit(), EXIT_FAILURE, fprintf, and progname.

Referenced by growalloc(), memcheck(), and size_product().

◆ mkdirs()

static void mkdirs ( char const *  argname,
bool  ancestors 
)
static

Definition at line 3948 of file zic.c.

3949{
3950 char *name;
3951 char *cp;
3952
3953 cp = name = ecpyalloc(argname);
3954
3955 /*
3956 * On MS-Windows systems, do not worry about drive letters or backslashes,
3957 * as this should suffice in practice. Time zone names do not use drive
3958 * letters and backslashes. If the -d option of zic does not name an
3959 * already-existing directory, it can use slashes to separate the
3960 * already-existing ancestor prefix from the to-be-created subdirectories.
3961 */
3962
3963 /* Do not mkdir a root directory, as it must exist. */
3964 while (*cp == '/')
3965 cp++;
3966
3967 while (cp && ((cp = strchr(cp, '/')) || !ancestors))
3968 {
3969 if (cp)
3970 *cp = '\0';
3971
3972 /*
3973 * Try to create it. It's OK if creation fails because the directory
3974 * already exists, perhaps because some other process just created it.
3975 * For simplicity do not check first whether it already exists, as
3976 * that is checked anyway if the mkdir fails.
3977 */
3978 if (mkdir(name, MKDIR_UMASK) != 0)
3979 {
3980 /*
3981 * For speed, skip itsdir if errno == EEXIST. Since mkdirs is
3982 * called only after open fails with ENOENT on a subfile, EEXIST
3983 * implies itsdir here.
3984 */
3985 int err = errno;
3986
3987 if (err != EEXIST && !itsdir(name))
3988 {
3989 error(_("%s: Cannot create directory %s: %s"),
3992 }
3993 }
3994 if (cp)
3995 *cp++ = '/';
3996 }
3997 free(name);
3998}
void err(int eval, const char *fmt,...)
Definition: err.c:43
#define mkdir(a, b)
Definition: win32_port.h:80
#define MKDIR_UMASK
Definition: zic.c:37

References _, ecpyalloc(), err(), error(), exit(), EXIT_FAILURE, free, itsdir(), mkdir, MKDIR_UMASK, name, progname, and strerror.

Referenced by change_directory(), dolink(), and writezone().

◆ namecheck()

static bool namecheck ( const char *  name)
static

Definition at line 903 of file zic.c.

904{
905 char const *cp;
906
907 /* Benign characters in a portable file name. */
908 static char const benign[] =
909 "-/_"
910 "abcdefghijklmnopqrstuvwxyz"
911 "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
912
913 /*
914 * Non-control chars in the POSIX portable character set, excluding the
915 * benign characters.
916 */
917 static char const printable_and_not_benign[] =
918 " !\"#$%&'()*+,.0123456789:;<=>?@[\\]^`{|}~";
919
920 char const *component = name;
921
922 for (cp = name; *cp; cp++)
923 {
924 unsigned char c = *cp;
925
926 if (noise && !strchr(benign, c))
927 {
928 warning((strchr(printable_and_not_benign, c)
929 ? _("file name '%s' contains byte '%c'")
930 : _("file name '%s' contains byte '\\%o'")),
931 name, c);
932 }
933 if (c == '/')
934 {
935 if (!componentcheck(name, component, cp))
936 return false;
937 component = cp + 1;
938 }
939 }
940 return componentcheck(name, component, cp);
941}
static bool componentcheck(char const *name, char const *component, char const *component_end)
Definition: zic.c:859

References _, componentcheck(), name, noise, and warning().

Referenced by inlink(), and inzsub().

◆ newabbr()

static void newabbr ( const char *  string)
static

Definition at line 3910 of file zic.c.

3911{
3912 int i;
3913
3914 if (strcmp(string, GRANDPARENTED) != 0)
3915 {
3916 const char *cp;
3917 const char *mp;
3918
3919 cp = string;
3920 mp = NULL;
3921 while (is_alpha(*cp) || ('0' <= *cp && *cp <= '9')
3922 || *cp == '-' || *cp == '+')
3923 ++cp;
3924 if (noise && cp - string < 3)
3925 mp = _("time zone abbreviation has fewer than 3 characters");
3926 if (cp - string > ZIC_MAX_ABBR_LEN_WO_WARN)
3927 mp = _("time zone abbreviation has too many characters");
3928 if (*cp != '\0')
3929 mp = _("time zone abbreviation differs from POSIX standard");
3930 if (mp != NULL)
3931 warning("%s (%s)", mp, string);
3932 }
3933 i = strlen(string) + 1;
3934 if (charcnt + i > TZ_MAX_CHARS)
3935 {
3936 error(_("too many, or too long, time zone abbreviations"));
3938 }
3939 strcpy(&chars[charcnt], string);
3940 charcnt += i;
3941}
#define GRANDPARENTED
Definition: private.h:30
#define TZ_MAX_CHARS
Definition: tzfile.h:105
#define ZIC_MAX_ABBR_LEN_WO_WARN
Definition: zic.c:30

References _, charcnt, chars, error(), exit(), EXIT_FAILURE, GRANDPARENTED, i, is_alpha(), noise, TZ_MAX_CHARS, warning(), and ZIC_MAX_ABBR_LEN_WO_WARN.

Referenced by addtype().

◆ oadd()

static zic_t oadd ( zic_t  t1,
zic_t  t2 
)
static

Definition at line 3764 of file zic.c.

3765{
3766 if (t1 < 0 ? t2 < ZIC_MIN - t1 : ZIC_MAX - t1 < t2)
3767 time_overflow();
3768 return t1 + t2;
3769}
#define ZIC_MIN
Definition: zic.c:26
static void time_overflow(void)
Definition: zic.c:3757

References time_overflow(), ZIC_MAX, and ZIC_MIN.

Referenced by adjleap(), gethms(), getleapdatetime(), outzone(), and rpytime().

◆ outzone()

static void outzone ( const struct zone zpfirst,
ptrdiff_t  zonecount 
)
static

Definition at line 2946 of file zic.c.

2947{
2948 const struct zone *zp;
2949 struct rule *rp;
2950 ptrdiff_t i,
2951 j;
2952 bool usestart,
2953 useuntil;
2954 zic_t starttime,
2955 untiltime;
2956 zic_t stdoff;
2957 zic_t save;
2958 zic_t year;
2959 zic_t startoff;
2960 bool startttisstd;
2961 bool startttisut;
2962 int type;
2963 char *startbuf;
2964 char *ab;
2965 char *envvar;
2966 int max_abbr_len;
2967 int max_envvar_len;
2968 bool prodstic; /* all rules are min to max */
2969 int compat;
2970 bool do_extend;
2971 char version;
2972 ptrdiff_t lastatmax = -1;
2973 zic_t one = 1;
2974 zic_t y2038_boundary = one << 31;
2975 zic_t max_year0;
2976 int defaulttype = -1;
2977
2978 max_abbr_len = 2 + max_format_len + max_abbrvar_len;
2979 max_envvar_len = 2 * max_abbr_len + 5 * 9;
2980 startbuf = emalloc(max_abbr_len + 1);
2981 ab = emalloc(max_abbr_len + 1);
2982 envvar = emalloc(max_envvar_len + 1);
2983 INITIALIZE(untiltime);
2984 INITIALIZE(starttime);
2985
2986 /*
2987 * Now. . .finally. . .generate some useful data!
2988 */
2989 timecnt = 0;
2990 typecnt = 0;
2991 charcnt = 0;
2992 prodstic = zonecount == 1;
2993
2994 /*
2995 * Thanks to Earl Chew for noting the need to unconditionally initialize
2996 * startttisstd.
2997 */
2998 startttisstd = false;
2999 startttisut = false;
3001 if (leapseen)
3002 {
3005 }
3006 for (i = 0; i < zonecount; ++i)
3007 {
3008 zp = &zpfirst[i];
3009 if (i < zonecount - 1)
3011 for (j = 0; j < zp->z_nrules; ++j)
3012 {
3013 rp = &zp->z_rules[j];
3014 if (rp->r_lowasnum)
3016 if (rp->r_hiwasnum)
3018 if (rp->r_lowasnum || rp->r_hiwasnum)
3019 prodstic = false;
3020 }
3021 }
3022
3023 /*
3024 * Generate lots of data if a rule can't cover all future times.
3025 */
3026 compat = stringzone(envvar, zpfirst, zonecount);
3027 version = compat < 2013 ? ZIC_VERSION_PRE_2013 : ZIC_VERSION;
3028 do_extend = compat < 0;
3029 if (noise)
3030 {
3031 if (!*envvar)
3032 warning("%s %s",
3033 _("no POSIX environment variable for zone"),
3034 zpfirst->z_name);
3035 else if (compat != 0)
3036 {
3037 /*
3038 * Circa-COMPAT clients, and earlier clients, might not work for
3039 * this zone when given dates before 1970 or after 2038.
3040 */
3041 warning(_("%s: pre-%d clients may mishandle"
3042 " distant timestamps"),
3043 zpfirst->z_name, compat);
3044 }
3045 }
3046 if (do_extend)
3047 {
3048 /*
3049 * Search through a couple of extra years past the obvious 400, to
3050 * avoid edge cases. For example, suppose a non-POSIX rule applies
3051 * from 2012 onwards and has transitions in March and September, plus
3052 * some one-off transitions in November 2013. If zic looked only at
3053 * the last 400 years, it would set max_year=2413, with the intent
3054 * that the 400 years 2014 through 2413 will be repeated. The last
3055 * transition listed in the tzfile would be in 2413-09, less than 400
3056 * years after the last one-off transition in 2013-11. Two years
3057 * might be overkill, but with the kind of edge cases available we're
3058 * not sure that one year would suffice.
3059 */
3060 enum
3061 {
3062 years_of_observations = YEARSPERREPEAT + 2};
3063
3064 if (min_year >= ZIC_MIN + years_of_observations)
3065 min_year -= years_of_observations;
3066 else
3067 min_year = ZIC_MIN;
3068 if (max_year <= ZIC_MAX - years_of_observations)
3069 max_year += years_of_observations;
3070 else
3071 max_year = ZIC_MAX;
3072
3073 /*
3074 * Regardless of any of the above, for a "proDSTic" zone which
3075 * specifies that its rules always have and always will be in effect,
3076 * we only need one cycle to define the zone.
3077 */
3078 if (prodstic)
3079 {
3080 min_year = 1900;
3081 max_year = min_year + years_of_observations;
3082 }
3083 }
3084 max_year0 = max_year;
3085 if (want_bloat())
3086 {
3087 /*
3088 * For the benefit of older systems, generate data from 1900 through
3089 * 2038.
3090 */
3091 if (min_year > 1900)
3092 min_year = 1900;
3093 if (max_year < 2038)
3094 max_year = 2038;
3095 }
3096
3097 for (i = 0; i < zonecount; ++i)
3098 {
3099 struct rule *prevrp = NULL;
3100
3101 /*
3102 * A guess that may well be corrected later.
3103 */
3104 save = 0;
3105 zp = &zpfirst[i];
3106 usestart = i > 0 && (zp - 1)->z_untiltime > min_time;
3107 useuntil = i < (zonecount - 1);
3108 if (useuntil && zp->z_untiltime <= min_time)
3109 continue;
3110 stdoff = zp->z_stdoff;
3111 eat(zp->z_filename, zp->z_linenum);
3112 *startbuf = '\0';
3113 startoff = zp->z_stdoff;
3114 if (zp->z_nrules == 0)
3115 {
3116 save = zp->z_save;
3117 doabbr(startbuf, zp, NULL, zp->z_isdst, save, false);
3118 type = addtype(oadd(zp->z_stdoff, save),
3119 startbuf, zp->z_isdst, startttisstd,
3120 startttisut);
3121 if (usestart)
3122 {
3123 addtt(starttime, type);
3124 usestart = false;
3125 }
3126 else
3127 defaulttype = type;
3128 }
3129 else
3130 for (year = min_year; year <= max_year; ++year)
3131 {
3132 if (useuntil && year > zp->z_untilrule.r_hiyear)
3133 break;
3134
3135 /*
3136 * Mark which rules to do in the current year. For those to
3137 * do, calculate rpytime(rp, year); The former TYPE field was
3138 * also considered here.
3139 */
3140 for (j = 0; j < zp->z_nrules; ++j)
3141 {
3142 rp = &zp->z_rules[j];
3143 eats(zp->z_filename, zp->z_linenum,
3144 rp->r_filename, rp->r_linenum);
3145 rp->r_todo = year >= rp->r_loyear &&
3146 year <= rp->r_hiyear;
3147 if (rp->r_todo)
3148 {
3149 rp->r_temp = rpytime(rp, year);
3150 rp->r_todo
3151 = (rp->r_temp < y2038_boundary
3152 || year <= max_year0);
3153 }
3154 }
3155 for (;;)
3156 {
3157 ptrdiff_t k;
3158 zic_t jtime,
3159 ktime;
3160 zic_t offset;
3161
3162 INITIALIZE(ktime);
3163 if (useuntil)
3164 {
3165 /*
3166 * Turn untiltime into UT assuming the current stdoff
3167 * and save values.
3168 */
3169 untiltime = zp->z_untiltime;
3170 if (!zp->z_untilrule.r_todisut)
3171 untiltime = tadd(untiltime,
3172 -stdoff);
3173 if (!zp->z_untilrule.r_todisstd)
3174 untiltime = tadd(untiltime,
3175 -save);
3176 }
3177
3178 /*
3179 * Find the rule (of those to do, if any) that takes
3180 * effect earliest in the year.
3181 */
3182 k = -1;
3183 for (j = 0; j < zp->z_nrules; ++j)
3184 {
3185 rp = &zp->z_rules[j];
3186 if (!rp->r_todo)
3187 continue;
3188 eats(zp->z_filename, zp->z_linenum,
3189 rp->r_filename, rp->r_linenum);
3190 offset = rp->r_todisut ? 0 : stdoff;
3191 if (!rp->r_todisstd)
3192 offset = oadd(offset, save);
3193 jtime = rp->r_temp;
3194 if (jtime == min_time ||
3195 jtime == max_time)
3196 continue;
3197 jtime = tadd(jtime, -offset);
3198 if (k < 0 || jtime < ktime)
3199 {
3200 k = j;
3201 ktime = jtime;
3202 }
3203 else if (jtime == ktime)
3204 {
3205 char const *dup_rules_msg =
3206 _("two rules for same instant");
3207
3208 eats(zp->z_filename, zp->z_linenum,
3209 rp->r_filename, rp->r_linenum);
3210 warning("%s", dup_rules_msg);
3211 rp = &zp->z_rules[k];
3212 eats(zp->z_filename, zp->z_linenum,
3213 rp->r_filename, rp->r_linenum);
3214 error("%s", dup_rules_msg);
3215 }
3216 }
3217 if (k < 0)
3218 break; /* go on to next year */
3219 rp = &zp->z_rules[k];
3220 rp->r_todo = false;
3221 if (useuntil && ktime >= untiltime)
3222 break;
3223 save = rp->r_save;
3224 if (usestart && ktime == starttime)
3225 usestart = false;
3226 if (usestart)
3227 {
3228 if (ktime < starttime)
3229 {
3230 startoff = oadd(zp->z_stdoff,
3231 save);
3232 doabbr(startbuf, zp,
3233 rp->r_abbrvar,
3234 rp->r_isdst,
3235 rp->r_save,
3236 false);
3237 continue;
3238 }
3239 if (*startbuf == '\0'
3240 && startoff == oadd(zp->z_stdoff,
3241 save))
3242 {
3243 doabbr(startbuf,
3244 zp,
3245 rp->r_abbrvar,
3246 rp->r_isdst,
3247 rp->r_save,
3248 false);
3249 }
3250 }
3251 eats(zp->z_filename, zp->z_linenum,
3252 rp->r_filename, rp->r_linenum);
3253 doabbr(ab, zp, rp->r_abbrvar,
3254 rp->r_isdst, rp->r_save, false);
3255 offset = oadd(zp->z_stdoff, rp->r_save);
3256 if (!want_bloat() && !useuntil && !do_extend
3257 && prevrp
3258 && rp->r_hiyear == ZIC_MAX
3259 && prevrp->r_hiyear == ZIC_MAX)
3260 break;
3261 type = addtype(offset, ab, rp->r_isdst,
3262 rp->r_todisstd, rp->r_todisut);
3263 if (defaulttype < 0 && !rp->r_isdst)
3264 defaulttype = type;
3265 if (rp->r_hiyear == ZIC_MAX
3266 && !(0 <= lastatmax
3267 && ktime < attypes[lastatmax].at))
3268 lastatmax = timecnt;
3269 addtt(ktime, type);
3270 prevrp = rp;
3271 }
3272 }
3273 if (usestart)
3274 {
3275 if (*startbuf == '\0' &&
3276 zp->z_format != NULL &&
3277 strchr(zp->z_format, '%') == NULL &&
3278 strchr(zp->z_format, '/') == NULL)
3279 strcpy(startbuf, zp->z_format);
3280 eat(zp->z_filename, zp->z_linenum);
3281 if (*startbuf == '\0')
3282 error(_("cannot determine time zone abbreviation to use just after until time"));
3283 else
3284 {
3285 bool isdst = startoff != zp->z_stdoff;
3286
3287 type = addtype(startoff, startbuf, isdst,
3288 startttisstd, startttisut);
3289 if (defaulttype < 0 && !isdst)
3290 defaulttype = type;
3291 addtt(starttime, type);
3292 }
3293 }
3294
3295 /*
3296 * Now we may get to set starttime for the next zone line.
3297 */
3298 if (useuntil)
3299 {
3300 startttisstd = zp->z_untilrule.r_todisstd;
3301 startttisut = zp->z_untilrule.r_todisut;
3302 starttime = zp->z_untiltime;
3303 if (!startttisstd)
3304 starttime = tadd(starttime, -save);
3305 if (!startttisut)
3306 starttime = tadd(starttime, -stdoff);
3307 }
3308 }
3309 if (defaulttype < 0)
3310 defaulttype = 0;
3311 if (0 <= lastatmax)
3312 attypes[lastatmax].dontmerge = true;
3313 if (do_extend)
3314 {
3315 /*
3316 * If we're extending the explicitly listed observations for 400 years
3317 * because we can't fill the POSIX-TZ field, check whether we actually
3318 * ended up explicitly listing observations through that period. If
3319 * there aren't any near the end of the 400-year period, add a
3320 * redundant one at the end of the final year, to make it clear that
3321 * we are claiming to have definite knowledge of the lack of
3322 * transitions up to that point.
3323 */
3324 struct rule xr;
3325 struct attype *lastat;
3326
3327 xr.r_month = TM_JANUARY;
3328 xr.r_dycode = DC_DOM;
3329 xr.r_dayofmonth = 1;
3330 xr.r_tod = 0;
3331 for (lastat = attypes, i = 1; i < timecnt; i++)
3332 if (attypes[i].at > lastat->at)
3333 lastat = &attypes[i];
3334 if (!lastat || lastat->at < rpytime(&xr, max_year - 1))
3335 {
3336 addtt(rpytime(&xr, max_year + 1),
3337 lastat ? lastat->type : defaulttype);
3338 attypes[timecnt - 1].dontmerge = true;
3339 }
3340 }
3341 writezone(zpfirst->z_name, envvar, version, defaulttype);
3342 free(startbuf);
3343 free(ab);
3344 free(envvar);
3345}
enum COMPAT_MODE compat
Definition: ecpg.c:26
#define INITIALIZE(x)
Definition: private.h:88
#define YEARSPERREPEAT
Definition: private.h:95
bool r_todo
Definition: zic.c:81
bool r_todisut
Definition: zic.c:76
zic_t r_hiyear
Definition: zic.c:64
bool r_isdst
Definition: zic.c:77
bool r_lowasnum
Definition: zic.c:65
zic_t r_temp
Definition: zic.c:82
zic_t r_loyear
Definition: zic.c:63
zic_t r_save
Definition: zic.c:78
bool r_hiwasnum
Definition: zic.c:66
bool r_todisstd
Definition: zic.c:75
const char * r_abbrvar
Definition: zic.c:79
struct rule z_untilrule
Definition: zic.c:110
zic_t z_stdoff
Definition: zic.c:99
const char * z_format
Definition: zic.c:101
#define ZIC_VERSION
Definition: zic.c:23
static zic_t min_year
Definition: zic.c:187
#define DC_DOM
Definition: zic.c:89
#define ZIC_VERSION_PRE_2013
Definition: zic.c:22
static zic_t max_year
Definition: zic.c:186
static int addtype(zic_t utoff, char const *abbr, bool isdst, bool ttisstd, bool ttisut)
Definition: zic.c:3358
static int stringzone(char *result, struct zone const *zpfirst, ptrdiff_t zonecount)
Definition: zic.c:2811
static void writezone(const char *const name, const char *const string, char version, int defaulttype)
Definition: zic.c:2082
static void addtt(zic_t starttime, int type)
Definition: zic.c:3348
static void updateminmax(const zic_t x)
Definition: zic.c:2673
static size_t doabbr(char *abbr, struct zone const *zp, char const *letters, bool isdst, zic_t save, bool doquotes)
Definition: zic.c:2630

References _, addtt(), addtype(), attype::at, attypes, charcnt, compat, DC_DOM, doabbr(), attype::dontmerge, eat(), eats(), emalloc(), EPOCH_YEAR, error(), free, i, INITIALIZE, j, leapmaxyear, leapminyear, leapseen, max_abbrvar_len, max_format_len, max_time, max_year, min_time, min_year, noise, oadd(), rule::r_abbrvar, rule::r_dayofmonth, rule::r_dycode, rule::r_filename, rule::r_hiwasnum, rule::r_hiyear, rule::r_isdst, rule::r_linenum, rule::r_lowasnum, rule::r_loyear, rule::r_month, rule::r_save, rule::r_temp, rule::r_tod, rule::r_todisstd, rule::r_todisut, rule::r_todo, rpytime(), stringzone(), tadd(), timecnt, TM_JANUARY, type, attype::type, typecnt, updateminmax(), want_bloat(), warning(), writezone(), YEARSPERREPEAT, zone::z_filename, zone::z_format, zone::z_isdst, zone::z_linenum, zone::z_name, zone::z_nrules, zone::z_rules, zone::z_save, zone::z_stdoff, zone::z_untilrule, zone::z_untiltime, ZIC_MAX, ZIC_MIN, ZIC_VERSION, and ZIC_VERSION_PRE_2013.

Referenced by main().

◆ puttzcode()

static void puttzcode ( const int32  val,
FILE *const  fp 
)
static

Definition at line 2014 of file zic.c.

2015{
2016 char buf[4];
2017
2018 convert(val, buf);
2019 fwrite(buf, sizeof buf, 1, fp);
2020}
static void convert(const int32 val, char *const buf)
Definition: zic.c:1992

References buf, convert(), and val.

Referenced by puttzcodepass(), and writezone().

◆ puttzcodepass()

static void puttzcodepass ( zic_t  val,
FILE *  fp,
int  pass 
)
static

Definition at line 2023 of file zic.c.

2024{
2025 if (pass == 1)
2026 puttzcode(val, fp);
2027 else
2028 {
2029 char buf[8];
2030
2031 convert64(val, buf);
2032 fwrite(buf, sizeof buf, 1, fp);
2033 }
2034}
static void convert64(const zic_t val, char *const buf)
Definition: zic.c:2003
static void puttzcode(const int32 val, FILE *const fp)
Definition: zic.c:2014

References buf, convert64(), puttzcode(), and val.

Referenced by writezone().

◆ rcomp()

static int rcomp ( const void *  cp1,
const void *  cp2 
)
static

Definition at line 1151 of file zic.c.

1152{
1153 return strcmp(((const struct rule *) cp1)->r_name,
1154 ((const struct rule *) cp2)->r_name);
1155}

Referenced by associate().

◆ relname()

static char * relname ( char const *  target,
char const *  linkname 
)
static

Definition at line 951 of file zic.c.

952{
953 size_t i,
954 taillen,
955 dotdotetcsize;
956 size_t dir_len = 0,
957 dotdots = 0,
958 linksize = SIZE_MAX;
959 char const *f = target;
960 char *result = NULL;
961
962 if (*linkname == '/')
963 {
964 /* Make F absolute too. */
965 size_t len = strlen(directory);
966 bool needslash = len && directory[len - 1] != '/';
967
968 linksize = len + needslash + strlen(target) + 1;
969 f = result = emalloc(linksize);
970 strcpy(result, directory);
971 result[len] = '/';
972 strcpy(result + len + needslash, target);
973 }
974 for (i = 0; f[i] && f[i] == linkname[i]; i++)
975 if (f[i] == '/')
976 dir_len = i + 1;
977 for (; linkname[i]; i++)
978 dotdots += linkname[i] == '/' && linkname[i - 1] != '/';
979 taillen = strlen(f + dir_len);
980 dotdotetcsize = 3 * dotdots + taillen + 1;
981 if (dotdotetcsize <= linksize)
982 {
983 if (!result)
984 result = emalloc(dotdotetcsize);
985 for (i = 0; i < dotdots; i++)
986 memcpy(result + 3 * i, "../", 3);
987 memmove(result + 3 * dotdots, f + dir_len, taillen + 1);
988 }
989 return result;
990}

References directory, emalloc(), i, and len.

Referenced by dolink().

◆ rpytime()

static zic_t rpytime ( const struct rule rp,
zic_t  wantedy 
)
static

Definition at line 3801 of file zic.c.

3802{
3803 int m,
3804 i;
3805 zic_t dayoff; /* with a nod to Margaret O. */
3806 zic_t t,
3807 y;
3808
3809 if (wantedy == ZIC_MIN)
3810 return min_time;
3811 if (wantedy == ZIC_MAX)
3812 return max_time;
3813 dayoff = 0;
3814 m = TM_JANUARY;
3815 y = EPOCH_YEAR;
3816 if (y < wantedy)
3817 {
3818 wantedy -= y;
3819 dayoff = (wantedy / YEARSPERREPEAT) * (SECSPERREPEAT / SECSPERDAY);
3820 wantedy %= YEARSPERREPEAT;
3821 wantedy += y;
3822 }
3823 else if (wantedy < 0)
3824 {
3825 dayoff = (wantedy / YEARSPERREPEAT) * (SECSPERREPEAT / SECSPERDAY);
3826 wantedy %= YEARSPERREPEAT;
3827 }
3828 while (wantedy != y)
3829 {
3830 if (wantedy > y)
3831 {
3832 i = len_years[isleap(y)];
3833 ++y;
3834 }
3835 else
3836 {
3837 --y;
3838 i = -len_years[isleap(y)];
3839 }
3840 dayoff = oadd(dayoff, i);
3841 }
3842 while (m != rp->r_month)
3843 {
3844 i = len_months[isleap(y)][m];
3845 dayoff = oadd(dayoff, i);
3846 ++m;
3847 }
3848 i = rp->r_dayofmonth;
3849 if (m == TM_FEBRUARY && i == 29 && !isleap(y))
3850 {
3851 if (rp->r_dycode == DC_DOWLEQ)
3852 --i;
3853 else
3854 {
3855 error(_("use of 2/29 in non leap-year"));
3857 }
3858 }
3859 --i;
3860 dayoff = oadd(dayoff, i);
3861 if (rp->r_dycode == DC_DOWGEQ || rp->r_dycode == DC_DOWLEQ)
3862 {
3863 zic_t wday;
3864
3865#define LDAYSPERWEEK ((zic_t) DAYSPERWEEK)
3866 wday = EPOCH_WDAY;
3867
3868 /*
3869 * Don't trust mod of negative numbers.
3870 */
3871 if (dayoff >= 0)
3872 wday = (wday + dayoff) % LDAYSPERWEEK;
3873 else
3874 {
3875 wday -= ((-dayoff) % LDAYSPERWEEK);
3876 if (wday < 0)
3877 wday += LDAYSPERWEEK;
3878 }
3879 while (wday != rp->r_wday)
3880 if (rp->r_dycode == DC_DOWGEQ)
3881 {
3882 dayoff = oadd(dayoff, 1);
3883 if (++wday >= LDAYSPERWEEK)
3884 wday = 0;
3885 ++i;
3886 }
3887 else
3888 {
3889 dayoff = oadd(dayoff, -1);
3890 if (--wday < 0)
3891 wday = LDAYSPERWEEK - 1;
3892 --i;
3893 }
3894 if (i < 0 || i >= len_months[isleap(y)][m])
3895 {
3896 if (noise)
3897 warning(_("rule goes past start/end of month; \
3898will not work with pre-2004 versions of zic"));
3899 }
3900 }
3901 if (dayoff < min_time / SECSPERDAY)
3902 return min_time;
3903 if (dayoff > max_time / SECSPERDAY)
3904 return max_time;
3905 t = (zic_t) dayoff * SECSPERDAY;
3906 return tadd(t, rp->r_tod);
3907}
int y
Definition: isn.c:71
#define SECSPERREPEAT
Definition: private.h:155
#define EPOCH_WDAY
Definition: private.h:131
#define TM_FEBRUARY
Definition: private.h:116
int r_dycode
Definition: zic.c:70
int r_dayofmonth
Definition: zic.c:71
int r_wday
Definition: zic.c:72
int r_month
Definition: zic.c:68
zic_t r_tod
Definition: zic.c:74
#define LDAYSPERWEEK
#define DC_DOWGEQ
Definition: zic.c:90
#define DC_DOWLEQ
Definition: zic.c:91

References _, DC_DOWGEQ, DC_DOWLEQ, EPOCH_WDAY, EPOCH_YEAR, error(), exit(), EXIT_FAILURE, i, isleap, LDAYSPERWEEK, len_months, len_years, max_time, min_time, noise, oadd(), rule::r_dayofmonth, rule::r_dycode, rule::r_month, rule::r_tod, rule::r_wday, SECSPERDAY, SECSPERREPEAT, tadd(), TM_FEBRUARY, TM_JANUARY, warning(), y, YEARSPERREPEAT, ZIC_MAX, and ZIC_MIN.

Referenced by inzsub(), and outzone().

◆ rule_cmp()

static int rule_cmp ( struct rule const *  a,
struct rule const *  b 
)
static

Definition at line 2797 of file zic.c.

2798{
2799 if (!a)
2800 return -!!b;
2801 if (!b)
2802 return 1;
2803 if (a->r_hiyear != b->r_hiyear)
2804 return a->r_hiyear < b->r_hiyear ? -1 : 1;
2805 if (a->r_month - b->r_month != 0)
2806 return a->r_month - b->r_month;
2807 return a->r_dayofmonth - b->r_dayofmonth;
2808}

References a, and b.

Referenced by stringzone().

◆ rulesub()

static void rulesub ( struct rule rp,
const char *  loyearp,
const char *  hiyearp,
const char *  typep,
const char *  monthp,
const char *  dayp,
const char *  timep 
)
static

Definition at line 1823 of file zic.c.

1826{
1827 const struct lookup *lp;
1828 const char *cp;
1829 char *dp;
1830 char *ep;
1831 char xs;
1832
1833 /* PG: year_tmp is to avoid sscanf portability issues */
1834 int year_tmp;
1835
1836 if ((lp = byword(monthp, mon_names)) == NULL)
1837 {
1838 error(_("invalid month name"));
1839 return;
1840 }
1841 rp->r_month = lp->l_value;
1842 rp->r_todisstd = false;
1843 rp->r_todisut = false;
1844 dp = ecpyalloc(timep);
1845 if (*dp != '\0')
1846 {
1847 ep = dp + strlen(dp) - 1;
1848 switch (lowerit(*ep))
1849 {
1850 case 's': /* Standard */
1851 rp->r_todisstd = true;
1852 rp->r_todisut = false;
1853 *ep = '\0';
1854 break;
1855 case 'w': /* Wall */
1856 rp->r_todisstd = false;
1857 rp->r_todisut = false;
1858 *ep = '\0';
1859 break;
1860 case 'g': /* Greenwich */
1861 case 'u': /* Universal */
1862 case 'z': /* Zulu */
1863 rp->r_todisstd = true;
1864 rp->r_todisut = true;
1865 *ep = '\0';
1866 break;
1867 }
1868 }
1869 rp->r_tod = gethms(dp, _("invalid time of day"));
1870 free(dp);
1871
1872 /*
1873 * Year work.
1874 */
1875 cp = loyearp;
1876 lp = byword(cp, begin_years);
1877 rp->r_lowasnum = lp == NULL;
1878 if (!rp->r_lowasnum)
1879 switch (lp->l_value)
1880 {
1881 case YR_MINIMUM:
1882 rp->r_loyear = ZIC_MIN;
1883 break;
1884 case YR_MAXIMUM:
1885 rp->r_loyear = ZIC_MAX;
1886 break;
1887 default: /* "cannot happen" */
1888 fprintf(stderr,
1889 _("%s: panic: Invalid l_value %d\n"),
1890 progname, lp->l_value);
1892 }
1893 else if (sscanf(cp, "%d%c", &year_tmp, &xs) == 1)
1894 rp->r_loyear = year_tmp;
1895 else
1896 {
1897 error(_("invalid starting year"));
1898 return;
1899 }
1900 cp = hiyearp;
1901 lp = byword(cp, end_years);
1902 rp->r_hiwasnum = lp == NULL;
1903 if (!rp->r_hiwasnum)
1904 switch (lp->l_value)
1905 {
1906 case YR_MINIMUM:
1907 rp->r_hiyear = ZIC_MIN;
1908 break;
1909 case YR_MAXIMUM:
1910 rp->r_hiyear = ZIC_MAX;
1911 break;
1912 case YR_ONLY:
1913 rp->r_hiyear = rp->r_loyear;
1914 break;
1915 default: /* "cannot happen" */
1916 fprintf(stderr,
1917 _("%s: panic: Invalid l_value %d\n"),
1918 progname, lp->l_value);
1920 }
1921 else if (sscanf(cp, "%d%c", &year_tmp, &xs) == 1)
1922 rp->r_hiyear = year_tmp;
1923 else
1924 {
1925 error(_("invalid ending year"));
1926 return;
1927 }
1928 if (rp->r_loyear > rp->r_hiyear)
1929 {
1930 error(_("starting year greater than ending year"));
1931 return;
1932 }
1933 if (*typep != '\0')
1934 {
1935 error(_("year type \"%s\" is unsupported; use \"-\" instead"),
1936 typep);
1937 return;
1938 }
1939
1940 /*
1941 * Day work. Accept things such as: 1 lastSunday last-Sunday
1942 * (undocumented; warn about this) Sun<=20 Sun>=7
1943 */
1944 dp = ecpyalloc(dayp);
1945 if ((lp = byword(dp, lasts)) != NULL)
1946 {
1947 rp->r_dycode = DC_DOWLEQ;
1948 rp->r_wday = lp->l_value;
1949 rp->r_dayofmonth = len_months[1][rp->r_month];
1950 }
1951 else
1952 {
1953 if ((ep = strchr(dp, '<')) != NULL)
1954 rp->r_dycode = DC_DOWLEQ;
1955 else if ((ep = strchr(dp, '>')) != NULL)
1956 rp->r_dycode = DC_DOWGEQ;
1957 else
1958 {
1959 ep = dp;
1960 rp->r_dycode = DC_DOM;
1961 }
1962 if (rp->r_dycode != DC_DOM)
1963 {
1964 *ep++ = 0;
1965 if (*ep++ != '=')
1966 {
1967 error(_("invalid day of month"));
1968 free(dp);
1969 return;
1970 }
1971 if ((lp = byword(dp, wday_names)) == NULL)
1972 {
1973 error(_("invalid weekday name"));
1974 free(dp);
1975 return;
1976 }
1977 rp->r_wday = lp->l_value;
1978 }
1979 if (sscanf(ep, "%d%c", &rp->r_dayofmonth, &xs) != 1 ||
1980 rp->r_dayofmonth <= 0 ||
1981 (rp->r_dayofmonth > len_months[1][rp->r_month]))
1982 {
1983 error(_("invalid day of month"));
1984 free(dp);
1985 return;
1986 }
1987 }
1988 free(dp);
1989}
#define YR_MAXIMUM
Definition: zic.c:280
#define YR_ONLY
Definition: zic.c:281
static struct lookup const begin_years[]
Definition: zic.c:362
#define YR_MINIMUM
Definition: zic.c:279
static struct lookup const end_years[]
Definition: zic.c:368

References _, begin_years, byword(), DC_DOM, DC_DOWGEQ, DC_DOWLEQ, ecpyalloc(), end_years, error(), exit(), EXIT_FAILURE, fprintf, free, gethms(), lookup::l_value, lasts, len_months, lowerit(), mon_names, progname, rule::r_dayofmonth, rule::r_dycode, rule::r_hiwasnum, rule::r_hiyear, rule::r_lowasnum, rule::r_loyear, rule::r_month, rule::r_tod, rule::r_todisstd, rule::r_todisut, rule::r_wday, wday_names, YR_MAXIMUM, YR_MINIMUM, YR_ONLY, ZIC_MAX, and ZIC_MIN.

Referenced by inrule(), and inzsub().

◆ size_product()

static size_t size_product ( size_t  nitems,
size_t  itemsize 
)
static

Definition at line 418 of file zic.c.

419{
420 if (SIZE_MAX / itemsize < nitems)
421 memory_exhausted(_("size overflow"));
422 return nitems * itemsize;
423}

References _, memory_exhausted(), and nitems.

Referenced by getfields(), growalloc(), and writezone().

◆ stringoffset()

static int stringoffset ( char *  result,
zic_t  offset 
)
static

Definition at line 2682 of file zic.c.

2683{
2684 int hours;
2685 int minutes;
2686 int seconds;
2687 bool negative = offset < 0;
2688 int len = negative;
2689
2690 if (negative)
2691 {
2692 offset = -offset;
2693 result[0] = '-';
2694 }
2695 seconds = offset % SECSPERMIN;
2696 offset /= SECSPERMIN;
2697 minutes = offset % MINSPERHOUR;
2698 offset /= MINSPERHOUR;
2699 hours = offset;
2700 if (hours >= HOURSPERDAY * DAYSPERWEEK)
2701 {
2702 result[0] = '\0';
2703 return 0;
2704 }
2705 len += sprintf(result + len, "%d", hours);
2706 if (minutes != 0 || seconds != 0)
2707 {
2708 len += sprintf(result + len, ":%02d", minutes);
2709 if (seconds != 0)
2710 len += sprintf(result + len, ":%02d", seconds);
2711 }
2712 return len;
2713}
#define DAYSPERWEEK
Definition: private.h:100

References DAYSPERWEEK, HOURSPERDAY, len, MINSPERHOUR, SECSPERMIN, and sprintf.

Referenced by stringrule(), and stringzone().

◆ stringrule()

static int stringrule ( char *  result,
struct rule *const  rp,
zic_t  save,
zic_t  stdoff 
)
static

Definition at line 2716 of file zic.c.

2717{
2718 zic_t tod = rp->r_tod;
2719 int compat = 0;
2720
2721 if (rp->r_dycode == DC_DOM)
2722 {
2723 int month,
2724 total;
2725
2726 if (rp->r_dayofmonth == 29 && rp->r_month == TM_FEBRUARY)
2727 return -1;
2728 total = 0;
2729 for (month = 0; month < rp->r_month; ++month)
2730 total += len_months[0][month];
2731 /* Omit the "J" in Jan and Feb, as that's shorter. */
2732 if (rp->r_month <= 1)
2733 result += sprintf(result, "%d", total + rp->r_dayofmonth - 1);
2734 else
2735 result += sprintf(result, "J%d", total + rp->r_dayofmonth);
2736 }
2737 else
2738 {
2739 int week;
2740 int wday = rp->r_wday;
2741 int wdayoff;
2742
2743 if (rp->r_dycode == DC_DOWGEQ)
2744 {
2745 wdayoff = (rp->r_dayofmonth - 1) % DAYSPERWEEK;
2746 if (wdayoff)
2747 compat = 2013;
2748 wday -= wdayoff;
2749 tod += wdayoff * SECSPERDAY;
2750 week = 1 + (rp->r_dayofmonth - 1) / DAYSPERWEEK;
2751 }
2752 else if (rp->r_dycode == DC_DOWLEQ)
2753 {
2754 if (rp->r_dayofmonth == len_months[1][rp->r_month])
2755 week = 5;
2756 else
2757 {
2758 wdayoff = rp->r_dayofmonth % DAYSPERWEEK;
2759 if (wdayoff)
2760 compat = 2013;
2761 wday -= wdayoff;
2762 tod += wdayoff * SECSPERDAY;
2763 week = rp->r_dayofmonth / DAYSPERWEEK;
2764 }
2765 }
2766 else
2767 return -1; /* "cannot happen" */
2768 if (wday < 0)
2769 wday += DAYSPERWEEK;
2770 result += sprintf(result, "M%d.%d.%d",
2771 rp->r_month + 1, week, wday);
2772 }
2773 if (rp->r_todisut)
2774 tod += stdoff;
2775 if (rp->r_todisstd && !rp->r_isdst)
2776 tod += save;
2777 if (tod != 2 * SECSPERMIN * MINSPERHOUR)
2778 {
2779 *result++ = '/';
2780 if (!stringoffset(result, tod))
2781 return -1;
2782 if (tod < 0)
2783 {
2784 if (compat < 2013)
2785 compat = 2013;
2786 }
2787 else if (SECSPERDAY <= tod)
2788 {
2789 if (compat < 1994)
2790 compat = 1994;
2791 }
2792 }
2793 return compat;
2794}
static int stringoffset(char *result, zic_t offset)
Definition: zic.c:2682

References compat, DAYSPERWEEK, DC_DOM, DC_DOWGEQ, DC_DOWLEQ, len_months, MINSPERHOUR, rule::r_dayofmonth, rule::r_dycode, rule::r_isdst, rule::r_month, rule::r_tod, rule::r_todisstd, rule::r_todisut, rule::r_wday, SECSPERDAY, SECSPERMIN, sprintf, stringoffset(), and TM_FEBRUARY.

Referenced by stringzone().

◆ stringzone()

static int stringzone ( char *  result,
struct zone const *  zpfirst,
ptrdiff_t  zonecount 
)
static

Definition at line 2811 of file zic.c.

2812{
2813 const struct zone *zp;
2814 struct rule *rp;
2815 struct rule *stdrp;
2816 struct rule *dstrp;
2817 ptrdiff_t i;
2818 const char *abbrvar;
2819 int compat = 0;
2820 int c;
2821 size_t len;
2822 int offsetlen;
2823 struct rule stdr,
2824 dstr;
2825
2826 result[0] = '\0';
2827
2828 /*
2829 * Internet RFC 8536 section 5.1 says to use an empty TZ string if future
2830 * timestamps are truncated.
2831 */
2832 if (hi_time < max_time)
2833 return -1;
2834
2835 zp = zpfirst + zonecount - 1;
2836 stdrp = dstrp = NULL;
2837 for (i = 0; i < zp->z_nrules; ++i)
2838 {
2839 rp = &zp->z_rules[i];
2840 if (rp->r_hiwasnum || rp->r_hiyear != ZIC_MAX)
2841 continue;
2842 if (!rp->r_isdst)
2843 {
2844 if (stdrp == NULL)
2845 stdrp = rp;
2846 else
2847 return -1;
2848 }
2849 else
2850 {
2851 if (dstrp == NULL)
2852 dstrp = rp;
2853 else
2854 return -1;
2855 }
2856 }
2857 if (stdrp == NULL && dstrp == NULL)
2858 {
2859 /*
2860 * There are no rules running through "max". Find the latest std rule
2861 * in stdabbrrp and latest rule of any type in stdrp.
2862 */
2863 struct rule *stdabbrrp = NULL;
2864
2865 for (i = 0; i < zp->z_nrules; ++i)
2866 {
2867 rp = &zp->z_rules[i];
2868 if (!rp->r_isdst && rule_cmp(stdabbrrp, rp) < 0)
2869 stdabbrrp = rp;
2870 if (rule_cmp(stdrp, rp) < 0)
2871 stdrp = rp;
2872 }
2873 if (stdrp != NULL && stdrp->r_isdst)
2874 {
2875 /* Perpetual DST. */
2876 dstr.r_month = TM_JANUARY;
2877 dstr.r_dycode = DC_DOM;
2878 dstr.r_dayofmonth = 1;
2879 dstr.r_tod = 0;
2880 dstr.r_todisstd = dstr.r_todisut = false;
2881 dstr.r_isdst = stdrp->r_isdst;
2882 dstr.r_save = stdrp->r_save;
2883 dstr.r_abbrvar = stdrp->r_abbrvar;
2884 stdr.r_month = TM_DECEMBER;
2885 stdr.r_dycode = DC_DOM;
2886 stdr.r_dayofmonth = 31;
2887 stdr.r_tod = SECSPERDAY + stdrp->r_save;
2888 stdr.r_todisstd = stdr.r_todisut = false;
2889 stdr.r_isdst = false;
2890 stdr.r_save = 0;
2891 stdr.r_abbrvar
2892 = (stdabbrrp ? stdabbrrp->r_abbrvar : "");
2893 dstrp = &dstr;
2894 stdrp = &stdr;
2895 }
2896 }
2897 if (stdrp == NULL && (zp->z_nrules != 0 || zp->z_isdst))
2898 return -1;
2899 abbrvar = (stdrp == NULL) ? "" : stdrp->r_abbrvar;
2900 len = doabbr(result, zp, abbrvar, false, 0, true);
2901 offsetlen = stringoffset(result + len, -zp->z_stdoff);
2902 if (!offsetlen)
2903 {
2904 result[0] = '\0';
2905 return -1;
2906 }
2907 len += offsetlen;
2908 if (dstrp == NULL)
2909 return compat;
2910 len += doabbr(result + len, zp, dstrp->r_abbrvar,
2911 dstrp->r_isdst, dstrp->r_save, true);
2912 if (dstrp->r_save != SECSPERMIN * MINSPERHOUR)
2913 {
2914 offsetlen = stringoffset(result + len,
2915 -(zp->z_stdoff + dstrp->r_save));
2916 if (!offsetlen)
2917 {
2918 result[0] = '\0';
2919 return -1;
2920 }
2921 len += offsetlen;
2922 }
2923 result[len++] = ',';
2924 c = stringrule(result + len, dstrp, dstrp->r_save, zp->z_stdoff);
2925 if (c < 0)
2926 {
2927 result[0] = '\0';
2928 return -1;
2929 }
2930 if (compat < c)
2931 compat = c;
2932 len += strlen(result + len);
2933 result[len++] = ',';
2934 c = stringrule(result + len, stdrp, dstrp->r_save, zp->z_stdoff);
2935 if (c < 0)
2936 {
2937 result[0] = '\0';
2938 return -1;
2939 }
2940 if (compat < c)
2941 compat = c;
2942 return compat;
2943}
#define TM_DECEMBER
Definition: private.h:126
static int stringrule(char *result, struct rule *const rp, zic_t save, zic_t stdoff)
Definition: zic.c:2716
static int rule_cmp(struct rule const *a, struct rule const *b)
Definition: zic.c:2797

References compat, DC_DOM, doabbr(), hi_time, i, len, max_time, MINSPERHOUR, rule::r_abbrvar, rule::r_dayofmonth, rule::r_dycode, rule::r_hiwasnum, rule::r_hiyear, rule::r_isdst, rule::r_month, rule::r_save, rule::r_tod, rule::r_todisstd, rule::r_todisut, rule_cmp(), SECSPERDAY, SECSPERMIN, stringoffset(), stringrule(), TM_DECEMBER, TM_JANUARY, zone::z_isdst, zone::z_nrules, zone::z_rules, zone::z_stdoff, and ZIC_MAX.

Referenced by outzone().

◆ tadd()

static zic_t tadd ( zic_t  t1,
zic_t  t2 
)
static

Definition at line 3772 of file zic.c.

3773{
3774 if (t1 < 0)
3775 {
3776 if (t2 < min_time - t1)
3777 {
3778 if (t1 != min_time)
3779 time_overflow();
3780 return min_time;
3781 }
3782 }
3783 else
3784 {
3785 if (max_time - t1 < t2)
3786 {
3787 if (t1 != max_time)
3788 time_overflow();
3789 return max_time;
3790 }
3791 }
3792 return t1 + t2;
3793}

References max_time, min_time, and time_overflow().

Referenced by adjleap(), getleapdatetime(), outzone(), rpytime(), and writezone().

◆ time_overflow()

static void time_overflow ( void  )
static

Definition at line 3757 of file zic.c.

3758{
3759 error(_("time overflow"));
3761}

References _, error(), exit(), and EXIT_FAILURE.

Referenced by oadd(), and tadd().

◆ timerange_option()

static bool timerange_option ( char *  timerange)
static

Definition at line 602 of file zic.c.

603{
604 int64 lo = min_time,
605 hi = max_time;
606 char *lo_end = timerange,
607 *hi_end;
608
609 if (*timerange == '@')
610 {
611 errno = 0;
612 lo = strtoimax(timerange + 1, &lo_end, 10);
613 if (lo_end == timerange + 1 || (lo == PG_INT64_MAX && errno == ERANGE))
614 return false;
615 }
616 hi_end = lo_end;
617 if (lo_end[0] == '/' && lo_end[1] == '@')
618 {
619 errno = 0;
620 hi = strtoimax(lo_end + 2, &hi_end, 10);
621 if (hi_end == lo_end + 2 || hi == PG_INT64_MIN)
622 return false;
623 hi -= !(hi == PG_INT64_MAX && errno == ERANGE);
624 }
625 if (*hi_end || hi < lo || max_time < lo || hi < min_time)
626 return false;
627 lo_time = lo < min_time ? min_time : lo;
628 hi_time = max_time < hi ? max_time : hi;
629 return true;
630}
int64_t int64
Definition: c.h:485
#define PG_INT64_MAX
Definition: c.h:549
#define PG_INT64_MIN
Definition: c.h:548
#define strtoimax
Definition: private.h:49
static zic_t lo_time
Definition: zic.c:590

References hi_time, lo_time, max_time, min_time, PG_INT64_MAX, PG_INT64_MIN, and strtoimax.

Referenced by main().

◆ updateminmax()

static void updateminmax ( const zic_t  x)
static

Definition at line 2673 of file zic.c.

2674{
2675 if (min_year > x)
2676 min_year = x;
2677 if (max_year < x)
2678 max_year = x;
2679}
int x
Definition: isn.c:70

References max_year, min_year, and x.

Referenced by outzone().

◆ usage()

static void usage ( FILE *  stream,
int  status 
)
static

Definition at line 543 of file zic.c.

544{
545 fprintf(stream,
546 _("%s: usage is %s [ --version ] [ --help ] [ -v ] [ -P ] \\\n"
547 "\t[ -b {slim|fat} ] [ -d directory ] [ -l localtime ]"
548 " [ -L leapseconds ] \\\n"
549 "\t[ -p posixrules ] [ -r '[@lo][/@hi]' ] [ -t localtime-link ] \\\n"
550 "\t[ filename ... ]\n\n"
551 "Report bugs to %s.\n"),
552 progname, progname, PACKAGE_BUGREPORT);
553 if (status == EXIT_SUCCESS)
554 close_file(stream, NULL, NULL);
555 exit(status);
556}

References _, close_file(), exit(), EXIT_SUCCESS, fprintf, and progname.

Referenced by main().

◆ verror()

static void verror ( const char *  string,
va_list  args 
)
static

Definition at line 488 of file zic.c.

489{
490 /*
491 * Match the format of "cc" to allow sh users to zic ... 2>&1 | error -t
492 * "*" -v on BSD systems.
493 */
494 if (filename)
495 fprintf(stderr, _("\"%s\", line %d: "), filename, linenum);
496 vfprintf(stderr, string, args);
497 if (rfilename != NULL)
498 fprintf(stderr, _(" (rule from \"%s\", line %d)"),
500 fprintf(stderr, "\n");
501}
vfprintf(stderr, fmt, args)

References _, generate_unaccent_rules::args, filename, fprintf, linenum, rfilename, rlinenum, and vfprintf().

Referenced by error(), and warning().

◆ want_bloat()

static bool want_bloat ( void  )
static

Definition at line 644 of file zic.c.

645{
646 return 0 <= bloat;
647}

References bloat.

Referenced by addtype(), outzone(), and writezone().

◆ warning()

static void warning ( const char *  string,
  ... 
)
static

Definition at line 515 of file zic.c.

516{
517 va_list args;
518
519 fprintf(stderr, _("warning: "));
520 va_start(args, string);
521 verror(string, args);
522 va_end(args);
523 warnings = true;
524}

References _, generate_unaccent_rules::args, fprintf, va_end(), va_start(), verror(), and warnings.

Referenced by adjleap(), associate(), byword(), componentcheck(), dolink(), gethms(), inzsub(), main(), namecheck(), newabbr(), outzone(), rpytime(), and writezone().

◆ writezone()

static void writezone ( const char *const  name,
const char *const  string,
char  version,
int  defaulttype 
)
static

Definition at line 2082 of file zic.c.

2084{
2085 FILE *fp;
2086 ptrdiff_t i,
2087 j;
2088 int pass;
2089 static const struct tzhead tzh0;
2090 static struct tzhead tzh;
2091 bool dir_checked = false;
2092 zic_t one = 1;
2093 zic_t y2038_boundary = one << 31;
2094 ptrdiff_t nats = timecnt + WORK_AROUND_QTBUG_53071;
2095
2096 /*
2097 * Allocate the ATS and TYPES arrays via a single malloc, as this is a bit
2098 * faster.
2099 */
2100 zic_t *ats = emalloc(MAXALIGN(size_product(nats, sizeof *ats + 1)));
2101 void *typesptr = ats + nats;
2102 unsigned char *types = typesptr;
2103 struct timerange rangeall,
2104 range32,
2105 range64;
2106
2107 /*
2108 * Sort.
2109 */
2110 if (timecnt > 1)
2111 qsort(attypes, timecnt, sizeof *attypes, atcomp);
2112
2113 /*
2114 * Optimize.
2115 */
2116 {
2117 ptrdiff_t fromi,
2118 toi;
2119
2120 toi = 0;
2121 fromi = 0;
2122 for (; fromi < timecnt; ++fromi)
2123 {
2124 if (toi != 0
2125 && ((attypes[fromi].at
2126 + utoffs[attypes[toi - 1].type])
2127 <= (attypes[toi - 1].at
2128 + utoffs[toi == 1 ? 0
2129 : attypes[toi - 2].type])))
2130 {
2131 attypes[toi - 1].type =
2132 attypes[fromi].type;
2133 continue;
2134 }
2135 if (toi == 0
2136 || attypes[fromi].dontmerge
2137 || (utoffs[attypes[toi - 1].type]
2138 != utoffs[attypes[fromi].type])
2139 || (isdsts[attypes[toi - 1].type]
2140 != isdsts[attypes[fromi].type])
2141 || (desigidx[attypes[toi - 1].type]
2142 != desigidx[attypes[fromi].type]))
2143 attypes[toi++] = attypes[fromi];
2144 }
2145 timecnt = toi;
2146 }
2147
2148 if (noise && timecnt > 1200)
2149 {
2150 if (timecnt > TZ_MAX_TIMES)
2151 warning(_("reference clients mishandle"
2152 " more than %d transition times"),
2153 TZ_MAX_TIMES);
2154 else
2155 warning(_("pre-2014 clients may mishandle"
2156 " more than 1200 transition times"));
2157 }
2158
2159 /*
2160 * Transfer.
2161 */
2162 for (i = 0; i < timecnt; ++i)
2163 {
2164 ats[i] = attypes[i].at;
2165 types[i] = attypes[i].type;
2166 }
2167
2168 /*
2169 * Correct for leap seconds.
2170 */
2171 for (i = 0; i < timecnt; ++i)
2172 {
2173 j = leapcnt;
2174 while (--j >= 0)
2175 if (ats[i] > trans[j] - corr[j])
2176 {
2177 ats[i] = tadd(ats[i], corr[j]);
2178 break;
2179 }
2180 }
2181
2182 /*
2183 * Work around QTBUG-53071 for timestamps less than y2038_boundary - 1, by
2184 * inserting a no-op transition at time y2038_boundary - 1. This works
2185 * only for timestamps before the boundary, which should be good enough in
2186 * practice as QTBUG-53071 should be long-dead by 2038. Do this after
2187 * correcting for leap seconds, as the idea is to insert a transition just
2188 * before 32-bit pg_time_t rolls around, and this occurs at a slightly
2189 * different moment if transitions are leap-second corrected.
2190 */
2192 && ats[timecnt - 1] < y2038_boundary - 1 && strchr(string, '<'))
2193 {
2194 ats[timecnt] = y2038_boundary - 1;
2195 types[timecnt] = types[timecnt - 1];
2196 timecnt++;
2197 }
2198
2199 rangeall.defaulttype = defaulttype;
2200 rangeall.base = rangeall.leapbase = 0;
2201 rangeall.count = timecnt;
2202 rangeall.leapcount = leapcnt;
2203 range64 = limitrange(rangeall, lo_time, hi_time, ats, types);
2204 range32 = limitrange(range64, PG_INT32_MIN, PG_INT32_MAX, ats, types);
2205
2206 /*
2207 * Remove old file, if any, to snap links.
2208 */
2209 if (remove(name) == 0)
2210 dir_checked = true;
2211 else if (errno != ENOENT)
2212 {
2213 const char *e = strerror(errno);
2214
2215 fprintf(stderr, _("%s: Cannot remove %s/%s: %s\n"),
2218 }
2219 fp = fopen(name, "wb");
2220 if (!fp)
2221 {
2222 int fopen_errno = errno;
2223
2224 if (fopen_errno == ENOENT && !dir_checked)
2225 {
2226 mkdirs(name, true);
2227 fp = fopen(name, "wb");
2228 fopen_errno = errno;
2229 }
2230 if (!fp)
2231 {
2232 fprintf(stderr, _("%s: Cannot create %s/%s: %s\n"),
2233 progname, directory, name, strerror(fopen_errno));
2235 }
2236 }
2237 for (pass = 1; pass <= 2; ++pass)
2238 {
2239 ptrdiff_t thistimei,
2240 thistimecnt,
2241 thistimelim;
2242 int thisleapi,
2243 thisleapcnt,
2244 thisleaplim;
2245 int currenttype,
2246 thisdefaulttype;
2247 bool locut,
2248 hicut;
2249 zic_t lo;
2250 int old0;
2251 char omittype[TZ_MAX_TYPES];
2252 int typemap[TZ_MAX_TYPES];
2253 int thistypecnt,
2254 stdcnt,
2255 utcnt;
2256 char thischars[TZ_MAX_CHARS];
2257 int thischarcnt;
2258 bool toomanytimes;
2259 int indmap[TZ_MAX_CHARS];
2260
2261 if (pass == 1)
2262 {
2263 /*
2264 * Arguably the default time type in the 32-bit data should be
2265 * range32.defaulttype, which is suited for timestamps just before
2266 * PG_INT32_MIN. However, zic traditionally used the time type of
2267 * the indefinite past instead. Internet RFC 8532 says readers
2268 * should ignore 32-bit data, so this discrepancy matters only to
2269 * obsolete readers where the traditional type might be more
2270 * appropriate even if it's "wrong". So, use the historical zic
2271 * value, unless -r specifies a low cutoff that excludes some
2272 * 32-bit timestamps.
2273 */
2274 thisdefaulttype = (lo_time <= PG_INT32_MIN
2275 ? range64.defaulttype
2276 : range32.defaulttype);
2277
2278 thistimei = range32.base;
2279 thistimecnt = range32.count;
2280 toomanytimes = thistimecnt >> 31 >> 1 != 0;
2281 thisleapi = range32.leapbase;
2282 thisleapcnt = range32.leapcount;
2283 locut = PG_INT32_MIN < lo_time;
2284 hicut = hi_time < PG_INT32_MAX;
2285 }
2286 else
2287 {
2288 thisdefaulttype = range64.defaulttype;
2289 thistimei = range64.base;
2290 thistimecnt = range64.count;
2291 toomanytimes = thistimecnt >> 31 >> 31 >> 2 != 0;
2292 thisleapi = range64.leapbase;
2293 thisleapcnt = range64.leapcount;
2294 locut = min_time < lo_time;
2295 hicut = hi_time < max_time;
2296 }
2297 if (toomanytimes)
2298 error(_("too many transition times"));
2299
2300 /*
2301 * Keep the last too-low transition if no transition is exactly at LO.
2302 * The kept transition will be output as a LO "transition"; see
2303 * "Output a LO_TIME transition" below. This is needed when the
2304 * output is truncated at the start, and is also useful when catering
2305 * to buggy 32-bit clients that do not use time type 0 for timestamps
2306 * before the first transition.
2307 */
2308 if (0 < thistimei && ats[thistimei] != lo_time)
2309 {
2310 thistimei--;
2311 thistimecnt++;
2312 locut = false;
2313 }
2314
2315 thistimelim = thistimei + thistimecnt;
2316 thisleaplim = thisleapi + thisleapcnt;
2317 if (thistimecnt != 0)
2318 {
2319 if (ats[thistimei] == lo_time)
2320 locut = false;
2321 if (hi_time < ZIC_MAX && ats[thistimelim - 1] == hi_time + 1)
2322 hicut = false;
2323 }
2324 memset(omittype, true, typecnt);
2325 omittype[thisdefaulttype] = false;
2326 for (i = thistimei; i < thistimelim; i++)
2327 omittype[types[i]] = false;
2328
2329 /*
2330 * Reorder types to make THISDEFAULTTYPE type 0. Use TYPEMAP to swap
2331 * OLD0 and THISDEFAULTTYPE so that THISDEFAULTTYPE appears as type 0
2332 * in the output instead of OLD0. TYPEMAP also omits unused types.
2333 */
2334 old0 = strlen(omittype);
2335
2336#ifndef LEAVE_SOME_PRE_2011_SYSTEMS_IN_THE_LURCH
2337
2338 /*
2339 * For some pre-2011 systems: if the last-to-be-written standard (or
2340 * daylight) type has an offset different from the most recently used
2341 * offset, append an (unused) copy of the most recently used type (to
2342 * help get global "altzone" and "timezone" variables set correctly).
2343 */
2344 if (want_bloat())
2345 {
2346 int mrudst,
2347 mrustd,
2348 hidst,
2349 histd,
2350 type;
2351
2352 hidst = histd = mrudst = mrustd = -1;
2353 for (i = thistimei; i < thistimelim; ++i)
2354 if (isdsts[types[i]])
2355 mrudst = types[i];
2356 else
2357 mrustd = types[i];
2358 for (i = old0; i < typecnt; i++)
2359 {
2360 int h = (i == old0 ? thisdefaulttype
2361 : i == thisdefaulttype ? old0 : i);
2362
2363 if (!omittype[h])
2364 {
2365 if (isdsts[h])
2366 hidst = i;
2367 else
2368 histd = i;
2369 }
2370 }
2371 if (hidst >= 0 && mrudst >= 0 && hidst != mrudst &&
2372 utoffs[hidst] != utoffs[mrudst])
2373 {
2374 isdsts[mrudst] = -1;
2375 type = addtype(utoffs[mrudst],
2376 &chars[desigidx[mrudst]],
2377 true,
2378 ttisstds[mrudst],
2379 ttisuts[mrudst]);
2380 isdsts[mrudst] = 1;
2381 omittype[type] = false;
2382 }
2383 if (histd >= 0 && mrustd >= 0 && histd != mrustd &&
2384 utoffs[histd] != utoffs[mrustd])
2385 {
2386 isdsts[mrustd] = -1;
2387 type = addtype(utoffs[mrustd],
2388 &chars[desigidx[mrustd]],
2389 false,
2390 ttisstds[mrustd],
2391 ttisuts[mrustd]);
2392 isdsts[mrustd] = 0;
2393 omittype[type] = false;
2394 }
2395 }
2396#endif /* !defined
2397 * LEAVE_SOME_PRE_2011_SYSTEMS_IN_THE_LURCH */
2398 thistypecnt = 0;
2399 for (i = old0; i < typecnt; i++)
2400 if (!omittype[i])
2401 typemap[i == old0 ? thisdefaulttype
2402 : i == thisdefaulttype ? old0 : i]
2403 = thistypecnt++;
2404
2405 for (i = 0; i < sizeof indmap / sizeof indmap[0]; ++i)
2406 indmap[i] = -1;
2407 thischarcnt = stdcnt = utcnt = 0;
2408 for (i = old0; i < typecnt; i++)
2409 {
2410 char *thisabbr;
2411
2412 if (omittype[i])
2413 continue;
2414 if (ttisstds[i])
2415 stdcnt = thistypecnt;
2416 if (ttisuts[i])
2417 utcnt = thistypecnt;
2418 if (indmap[desigidx[i]] >= 0)
2419 continue;
2420 thisabbr = &chars[desigidx[i]];
2421 for (j = 0; j < thischarcnt; ++j)
2422 if (strcmp(&thischars[j], thisabbr) == 0)
2423 break;
2424 if (j == thischarcnt)
2425 {
2426 strcpy(&thischars[thischarcnt], thisabbr);
2427 thischarcnt += strlen(thisabbr) + 1;
2428 }
2429 indmap[desigidx[i]] = j;
2430 }
2431 if (pass == 1 && !want_bloat())
2432 {
2433 utcnt = stdcnt = thisleapcnt = 0;
2434 thistimecnt = -(locut + hicut);
2435 thistypecnt = thischarcnt = 1;
2436 thistimelim = thistimei;
2437 }
2438#define DO(field) fwrite(tzh.field, sizeof tzh.field, 1, fp)
2439 tzh = tzh0;
2440 memcpy(tzh.tzh_magic, TZ_MAGIC, sizeof tzh.tzh_magic);
2441 tzh.tzh_version[0] = version;
2442 convert(utcnt, tzh.tzh_ttisutcnt);
2443 convert(stdcnt, tzh.tzh_ttisstdcnt);
2444 convert(thisleapcnt, tzh.tzh_leapcnt);
2445 convert(locut + thistimecnt + hicut, tzh.tzh_timecnt);
2446 convert(thistypecnt, tzh.tzh_typecnt);
2447 convert(thischarcnt, tzh.tzh_charcnt);
2448 DO(tzh_magic);
2449 DO(tzh_version);
2450 DO(tzh_reserved);
2451 DO(tzh_ttisutcnt);
2452 DO(tzh_ttisstdcnt);
2453 DO(tzh_leapcnt);
2454 DO(tzh_timecnt);
2455 DO(tzh_typecnt);
2456 DO(tzh_charcnt);
2457#undef DO
2458 if (pass == 1 && !want_bloat())
2459 {
2460 /* Output a minimal data block with just one time type. */
2461 puttzcode(0, fp); /* utoff */
2462 putc(0, fp); /* dst */
2463 putc(0, fp); /* index of abbreviation */
2464 putc(0, fp); /* empty-string abbreviation */
2465 continue;
2466 }
2467
2468 /* PG: print current timezone abbreviations if requested */
2469 if (print_abbrevs && pass == 2)
2470 {
2471 /* Print "type" data for periods ending after print_cutoff */
2472 for (i = thistimei; i < thistimelim; ++i)
2473 {
2474 if (i == thistimelim - 1 || ats[i + 1] > print_cutoff)
2475 {
2476 unsigned char tm = types[i];
2477 char *thisabbrev = &thischars[indmap[desigidx[tm]]];
2478
2479 fprintf(stdout, "%s\t" INT64_FORMAT "%s\n",
2480 thisabbrev,
2481 utoffs[tm],
2482 isdsts[tm] ? "\tD" : "");
2483 }
2484 }
2485 /* Print the default type if we have no transitions at all */
2486 if (thistimei >= thistimelim)
2487 {
2488 unsigned char tm = defaulttype;
2489 char *thisabbrev = &thischars[indmap[desigidx[tm]]];
2490
2491 fprintf(stdout, "%s\t" INT64_FORMAT "%s\n",
2492 thisabbrev,
2493 utoffs[tm],
2494 isdsts[tm] ? "\tD" : "");
2495 }
2496 }
2497
2498 /*
2499 * Output a LO_TIME transition if needed; see limitrange. But do not
2500 * go below the minimum representable value for this pass.
2501 */
2502 lo = pass == 1 && lo_time < PG_INT32_MIN ? PG_INT32_MIN : lo_time;
2503
2504 if (locut)
2505 puttzcodepass(lo, fp, pass);
2506 for (i = thistimei; i < thistimelim; ++i)
2507 {
2508 zic_t at = ats[i] < lo ? lo : ats[i];
2509
2510 puttzcodepass(at, fp, pass);
2511 }
2512 if (hicut)
2513 puttzcodepass(hi_time + 1, fp, pass);
2514 currenttype = 0;
2515 if (locut)
2516 putc(currenttype, fp);
2517 for (i = thistimei; i < thistimelim; ++i)
2518 {
2519 currenttype = typemap[types[i]];
2520 putc(currenttype, fp);
2521 }
2522 if (hicut)
2523 putc(currenttype, fp);
2524
2525 for (i = old0; i < typecnt; i++)
2526 {
2527 int h = (i == old0 ? thisdefaulttype
2528 : i == thisdefaulttype ? old0 : i);
2529
2530 if (!omittype[h])
2531 {
2532 puttzcode(utoffs[h], fp);
2533 putc(isdsts[h], fp);
2534 putc(indmap[desigidx[h]], fp);
2535 }
2536 }
2537 if (thischarcnt != 0)
2538 fwrite(thischars, sizeof thischars[0],
2539 thischarcnt, fp);
2540 for (i = thisleapi; i < thisleaplim; ++i)
2541 {
2542 zic_t todo;
2543
2544 if (roll[i])
2545 {
2546 if (timecnt == 0 || trans[i] < ats[0])
2547 {
2548 j = 0;
2549 while (isdsts[j])
2550 if (++j >= typecnt)
2551 {
2552 j = 0;
2553 break;
2554 }
2555 }
2556 else
2557 {
2558 j = 1;
2559 while (j < timecnt &&
2560 trans[i] >= ats[j])
2561 ++j;
2562 j = types[j - 1];
2563 }
2564 todo = tadd(trans[i], -utoffs[j]);
2565 }
2566 else
2567 todo = trans[i];
2568 puttzcodepass(todo, fp, pass);
2569 puttzcode(corr[i], fp);
2570 }
2571 if (stdcnt != 0)
2572 for (i = old0; i < typecnt; i++)
2573 if (!omittype[i])
2574 putc(ttisstds[i], fp);
2575 if (utcnt != 0)
2576 for (i = old0; i < typecnt; i++)
2577 if (!omittype[i])
2578 putc(ttisuts[i], fp);
2579 }
2580 fprintf(fp, "\n%s\n", string);
2582 free(ats);
2583}
#define PG_INT32_MAX
Definition: c.h:546
#define MAXALIGN(LEN)
Definition: c.h:768
#define INT64_FORMAT
Definition: c.h:506
#define PG_INT32_MIN
Definition: c.h:545
static struct pg_tm tm
Definition: localtime.c:104
Definition: tzfile.h:40
#define TZ_MAGIC
Definition: tzfile.h:37
#define TZ_MAX_TIMES
Definition: tzfile.h:100
#define DO(field)
static int atcomp(const void *avp, const void *bvp)
Definition: zic.c:2037
static void puttzcodepass(zic_t val, FILE *fp, int pass)
Definition: zic.c:2023
static struct timerange limitrange(struct timerange r, zic_t lo, zic_t hi, zic_t const *ats, unsigned char const *types)
Definition: zic.c:2055

References _, addtype(), attype::at, atcomp(), attypes, timerange::base, chars, close_file(), convert(), corr, timerange::count, timerange::defaulttype, desigidx, directory, DO, emalloc(), error(), exit(), EXIT_FAILURE, fprintf, free, hi_time, i, INT64_FORMAT, isdsts, j, timerange::leapbase, leapcnt, timerange::leapcount, limitrange(), lo_time, max_time, MAXALIGN, min_time, mkdirs(), name, noise, PG_INT32_MAX, PG_INT32_MIN, print_abbrevs, print_cutoff, progname, puttzcode(), puttzcodepass(), qsort, roll, size_product(), generate_unaccent_rules::stdout, strerror, tadd(), timecnt, tm, trans, ttisstds, ttisuts, type, attype::type, typecnt, types, TZ_MAGIC, TZ_MAX_CHARS, TZ_MAX_TIMES, TZ_MAX_TYPES, tzhead::tzh_charcnt, tzhead::tzh_leapcnt, tzhead::tzh_magic, tzhead::tzh_timecnt, tzhead::tzh_ttisstdcnt, tzhead::tzh_ttisutcnt, tzhead::tzh_typecnt, tzhead::tzh_version, utoffs, want_bloat(), warning(), WORK_AROUND_QTBUG_53071, and ZIC_MAX.

Referenced by outzone().

Variable Documentation

◆ attypes

struct attype * attypes
static

Referenced by addtt(), outzone(), and writezone().

◆ begin_years

struct lookup const begin_years[]
static
Initial value:
= {
{"minimum", YR_MINIMUM},
{"maximum", YR_MAXIMUM},
{NULL, 0}
}

Definition at line 362 of file zic.c.

Referenced by rulesub().

◆ bloat

int bloat
static

Definition at line 641 of file zic.c.

Referenced by main(), and want_bloat().

◆ charcnt

int charcnt
static

◆ chars

char chars[TZ_MAX_CHARS]
static

◆ comment_leapexpires

zic_t comment_leapexpires = -1
static

Definition at line 597 of file zic.c.

Referenced by adjleap(), and infile().

◆ corr

zic_t corr[TZ_MAX_LEAPS]
static

Definition at line 403 of file zic.c.

Referenced by adjleap(), leapadd(), timesub(), tzloadbody(), and writezone().

◆ desigidx

unsigned char desigidx[TZ_MAX_TYPES]
static

Definition at line 398 of file zic.c.

Referenced by addtype(), init_ttinfo(), tzloadbody(), and writezone().

◆ directory

◆ end_years

struct lookup const end_years[]
static
Initial value:
= {
{"minimum", YR_MINIMUM},
{"maximum", YR_MAXIMUM},
{"only", YR_ONLY},
{NULL, 0}
}

Definition at line 368 of file zic.c.

Referenced by rulesub().

◆ errors

bool errors
static

Definition at line 176 of file zic.c.

Referenced by associate(), error(), and main().

◆ filename

const char* filename
static

Definition at line 178 of file zic.c.

Referenced by eats(), infile(), inlink(), inrule(), inzsub(), and verror().

◆ hi_time

zic_t hi_time = MAXVAL(zic_t, TIME_T_BITS_IN_FILE)
static

Definition at line 591 of file zic.c.

Referenced by adjleap(), stringzone(), timerange_option(), and writezone().

◆ isdsts

char isdsts[TZ_MAX_TYPES]
static

Definition at line 397 of file zic.c.

Referenced by addtype(), and writezone().

◆ lasts

struct lookup const lasts[]
static
Initial value:
= {
{"last-Sunday", TM_SUNDAY},
{"last-Monday", TM_MONDAY},
{"last-Tuesday", TM_TUESDAY},
{"last-Wednesday", TM_WEDNESDAY},
{"last-Thursday", TM_THURSDAY},
{"last-Friday", TM_FRIDAY},
{"last-Saturday", TM_SATURDAY},
{NULL, 0}
}
#define TM_THURSDAY
Definition: private.h:111
#define TM_TUESDAY
Definition: private.h:109
#define TM_FRIDAY
Definition: private.h:112
#define TM_SATURDAY
Definition: private.h:113
#define TM_WEDNESDAY
Definition: private.h:110
#define TM_MONDAY
Definition: private.h:108
#define TM_SUNDAY
Definition: private.h:107

Definition at line 351 of file zic.c.

Referenced by byword(), and rulesub().

◆ lcltime

const char* lcltime
static

Definition at line 633 of file zic.c.

Referenced by inzone(), and main().

◆ leap_line_codes

struct lookup const leap_line_codes[]
static
Initial value:
= {
{"Leap", LC_LEAP},
{"Expires", LC_EXPIRES},
{NULL, 0}
}

Definition at line 318 of file zic.c.

Referenced by infile().

◆ leap_types

struct lookup const leap_types[]
static
Initial value:
= {
{"Rolling", true},
{"Stationary", false},
{NULL, 0}
}

Definition at line 375 of file zic.c.

Referenced by inleap().

◆ leapcnt

int leapcnt
static

Definition at line 179 of file zic.c.

Referenced by adjleap(), leapadd(), tzloadbody(), and writezone().

◆ leapexpires

zic_t leapexpires = -1
static

Definition at line 594 of file zic.c.

Referenced by adjleap(), and inexpires().

◆ leapmaxyear

zic_t leapmaxyear
static

Definition at line 182 of file zic.c.

Referenced by getleapdatetime(), and outzone().

◆ leapminyear

zic_t leapminyear
static

Definition at line 181 of file zic.c.

Referenced by getleapdatetime(), and outzone().

◆ leapsec

const char* leapsec
static

Definition at line 635 of file zic.c.

Referenced by infile(), and main().

◆ leapseen

bool leapseen
static

Definition at line 180 of file zic.c.

Referenced by getleapdatetime(), and outzone().

◆ len_months

const int len_months[2][MONSPERYEAR]
static
Initial value:
= {
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
}

Definition at line 381 of file zic.c.

Referenced by getleapdatetime(), rpytime(), rulesub(), and stringrule().

◆ len_years

const int len_years[2]
static
Initial value:
= {
}
#define DAYSPERNYEAR
Definition: private.h:101
#define DAYSPERLYEAR
Definition: private.h:102

Definition at line 386 of file zic.c.

Referenced by getleapdatetime(), and rpytime().

◆ linenum

lineno_t linenum
static

Definition at line 183 of file zic.c.

Referenced by eats(), inlink(), inrule(), inzsub(), and verror().

◆ links

◆ lo_time

zic_t lo_time = MINVAL(zic_t, TIME_T_BITS_IN_FILE)
static

Definition at line 590 of file zic.c.

Referenced by timerange_option(), and writezone().

◆ max_abbrvar_len

int max_abbrvar_len = PERCENT_Z_LEN_BOUND
static

Definition at line 184 of file zic.c.

Referenced by inrule(), and outzone().

◆ max_format_len

int max_format_len
static

Definition at line 185 of file zic.c.

Referenced by inzsub(), and outzone().

◆ max_time

zic_t const max_time = MAXVAL(zic_t, TIME_T_BITS_IN_FILE)
static

◆ max_year

zic_t max_year
static

Definition at line 186 of file zic.c.

Referenced by outzone(), and updateminmax().

◆ min_time

zic_t const min_time = MINVAL(zic_t, TIME_T_BITS_IN_FILE)
static

Definition at line 585 of file zic.c.

Referenced by getleapdatetime(), inzsub(), outzone(), rpytime(), tadd(), timerange_option(), and writezone().

◆ min_year

zic_t min_year
static

Definition at line 187 of file zic.c.

Referenced by outzone(), and updateminmax().

◆ mon_names

struct lookup const mon_names[]
static
Initial value:
= {
{"January", TM_JANUARY},
{"February", TM_FEBRUARY},
{"March", TM_MARCH},
{"April", TM_APRIL},
{"May", TM_MAY},
{"June", TM_JUNE},
{"July", TM_JULY},
{"August", TM_AUGUST},
{"September", TM_SEPTEMBER},
{"October", TM_OCTOBER},
{"November", TM_NOVEMBER},
{"December", TM_DECEMBER},
{NULL, 0}
}
#define TM_AUGUST
Definition: private.h:122
#define TM_SEPTEMBER
Definition: private.h:123
#define TM_MARCH
Definition: private.h:117
#define TM_NOVEMBER
Definition: private.h:125
#define TM_JULY
Definition: private.h:121
#define TM_APRIL
Definition: private.h:118
#define TM_OCTOBER
Definition: private.h:124
#define TM_MAY
Definition: private.h:119
#define TM_JUNE
Definition: private.h:120

Definition at line 324 of file zic.c.

Referenced by getleapdatetime(), and rulesub().

◆ nlinks

ptrdiff_t nlinks
static

Definition at line 300 of file zic.c.

Referenced by inlink(), and main().

◆ nlinks_alloc

ptrdiff_t nlinks_alloc
static

Definition at line 301 of file zic.c.

Referenced by inlink().

◆ noise

bool noise
static

Definition at line 188 of file zic.c.

Referenced by byword(), componentcheck(), gethms(), inzsub(), main(), namecheck(), newabbr(), outzone(), rpytime(), and writezone().

◆ nrules

ptrdiff_t nrules
static

Definition at line 284 of file zic.c.

Referenced by associate(), and inrule().

◆ nrules_alloc

ptrdiff_t nrules_alloc
static

Definition at line 285 of file zic.c.

Referenced by inrule().

◆ nzones

ptrdiff_t nzones
static

Definition at line 288 of file zic.c.

Referenced by associate(), inzone(), inzsub(), and main().

◆ nzones_alloc

ptrdiff_t nzones_alloc
static

Definition at line 289 of file zic.c.

Referenced by inzsub().

◆ print_abbrevs

bool print_abbrevs
static

Definition at line 189 of file zic.c.

Referenced by main(), and writezone().

◆ print_cutoff

zic_t print_cutoff
static

Definition at line 190 of file zic.c.

Referenced by main(), and writezone().

◆ progname

const char* progname
static

◆ psxrules

const char* psxrules
static

Definition at line 632 of file zic.c.

Referenced by inzone(), and main().

◆ PTRDIFF_MAX

ptrdiff_t const PTRDIFF_MAX = MAXVAL(ptrdiff_t, TYPE_BIT(ptrdiff_t))
static

Definition at line 47 of file zic.c.

Referenced by growalloc().

◆ rfilename

const char* rfilename
static

Definition at line 191 of file zic.c.

Referenced by eats(), and verror().

◆ rlinenum

lineno_t rlinenum
static

Definition at line 192 of file zic.c.

Referenced by eats(), and verror().

◆ roll

char roll[TZ_MAX_LEAPS]
static

Definition at line 404 of file zic.c.

Referenced by leapadd(), and writezone().

◆ rules

struct rule* rules
static

Definition at line 283 of file zic.c.

Referenced by associate(), fireRIRrules(), inrule(), and RelationBuildRuleLock().

◆ timecnt

ptrdiff_t timecnt
static

Definition at line 194 of file zic.c.

Referenced by addtt(), outzone(), tzloadbody(), tzparse(), and writezone().

◆ timecnt_alloc

ptrdiff_t timecnt_alloc
static

Definition at line 195 of file zic.c.

Referenced by addtt().

◆ trans

◆ ttisstds

bool ttisstds[TZ_MAX_TYPES]
static

Definition at line 399 of file zic.c.

Referenced by addtype(), and writezone().

◆ ttisuts

bool ttisuts[TZ_MAX_TYPES]
static

Definition at line 400 of file zic.c.

Referenced by addtype(), and writezone().

◆ typecnt

int typecnt
static

Definition at line 196 of file zic.c.

Referenced by addtype(), outzone(), tzloadbody(), and writezone().

◆ tzdefault

const char* tzdefault
static

Definition at line 636 of file zic.c.

Referenced by inzone(), and main().

◆ utoffs

zic_t utoffs[TZ_MAX_TYPES]
static

Definition at line 396 of file zic.c.

Referenced by addtype(), and writezone().

◆ warnings

bool warnings
static

Definition at line 177 of file zic.c.

Referenced by main(), and warning().

◆ wday_names

struct