PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
zic.c File Reference
#include "postgres_fe.h"
#include <fcntl.h>
#include <locale.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.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
 

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 linkat(fromdir, from, todir, to, flag)   (itssymlink(from) ? (errno = ENOTSUP, -1) : link(from, to))
 
#define PRIdLINENO   "d"
 
#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 LC_RULE   0
 
#define LC_ZONE   1
 
#define LC_LINK   2
 
#define LC_LEAP   3
 
#define ZF_NAME   1
 
#define ZF_GMTOFF   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_GMTOFF   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_STDOFF   8
 
#define RF_ABBRVAR   9
 
#define RULE_FIELDS   10
 
#define LF_FROM   1
 
#define LF_TO   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 YR_MINIMUM   0
 
#define YR_MAXIMUM   1
 
#define YR_ONLY   2
 
#define TIME_T_BITS_IN_FILE   64
 
#define BIG_BANG   (- (((zic_t) 1) << 59))
 
#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 }
 
enum  { WORK_AROUND_GNOME_BUG_730332 = true }
 
enum  { YEAR_BY_YEAR_ZONE = 1 }
 

Functions

int link (const char *fromname, const char *toname)
 
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, char const *, bool, bool, bool)
 
static void leapadd (zic_t, bool, int, int)
 
static void adjleap (void)
 
static void associate (void)
 
static void dolink (const char *, const char *, bool)
 
static char ** getfields (char *buf)
 
static zic_t gethms (const char *string, const char *errstring, bool)
 
static void infile (const char *filename)
 
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 **, int, bool)
 
static bool itsdir (char const *)
 
static bool itssymlink (char const *)
 
static bool is_alpha (char a)
 
static char lowerit (char)
 
static void mkdirs (char const *, bool)
 
static void newabbr (const char *abbr)
 
static zic_t oadd (zic_t t1, zic_t t2)
 
static void outzone (const struct zone *zp, ptrdiff_t ntzones)
 
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 bool yearistype (zic_t year, const char *type)
 
static struct lookup const * byword (const char *string, const struct lookup *lp)
 
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)
 
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 int hardlinkerr (char const *from, char const *to)
 
static int rcomp (const void *cp1, const void *cp2)
 
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 puttzcode64 (const zic_t val, FILE *const fp)
 
static int atcomp (const void *avp, const void *bvp)
 
static bool is32 (const zic_t x)
 
static void writezone (const char *const name, const char *const string, char version)
 
static char const * abbroffset (char *buf, zic_t offset)
 
static size_t doabbr (char *abbr, struct zone const *zp, char const *letters, zic_t stdoff, bool doquotes)
 
static void updateminmax (const zic_t x)
 
static int stringoffset (char *result, zic_t offset)
 
static int stringrule (char *result, const struct rule *const rp, const zic_t dstoff, const zic_t gmtoff)
 
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 char * shellquote (char *b, char const *s)
 
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 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 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 gmtoffs [TZ_MAX_TYPES]
 
static char isdsts [TZ_MAX_TYPES]
 
static unsigned char abbrinds [TZ_MAX_TYPES]
 
static bool ttisstds [TZ_MAX_TYPES]
 
static bool ttisgmts [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 const char * psxrules
 
static const char * lcltime
 
static const char * directory
 
static const char * leapsec
 
static const char * yitcommand
 
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 const zic_t early_time
 

Macro Definition Documentation

#define BIG_BANG   (- (((zic_t) 1) << 59))

Definition at line 992 of file zic.c.

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

Definition at line 87 of file zic.c.

Referenced by outzone(), rulesub(), stringrule(), and stringzone().

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

Definition at line 88 of file zic.c.

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

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

Definition at line 89 of file zic.c.

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

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

Referenced by writezone().

#define LC_LEAP   3

Definition at line 194 of file zic.c.

Referenced by infile().

#define LC_LINK   2

Definition at line 193 of file zic.c.

Referenced by infile().

#define LC_RULE   0

Definition at line 191 of file zic.c.

Referenced by infile().

#define LC_ZONE   1

Definition at line 192 of file zic.c.

Referenced by infile().

#define LDAYSPERWEEK   ((zic_t) DAYSPERWEEK)

Referenced by rpytime().

#define LEAP_FIELDS   7

Definition at line 258 of file zic.c.

Referenced by inleap().

#define LF_FROM   1

Definition at line 244 of file zic.c.

Referenced by inlink().

#define LF_TO   2

Definition at line 245 of file zic.c.

Referenced by inlink().

#define LINK_FIELDS   3

Definition at line 246 of file zic.c.

Referenced by inlink().

#define linkat (   fromdir,
  from,
  todir,
  to,
  flag 
)    (itssymlink(from) ? (errno = ENOTSUP, -1) : link(from, to))

Definition at line 41 of file zic.c.

Referenced by hardlinkerr().

#define LP_CORR   5

Definition at line 256 of file zic.c.

Referenced by inleap().

#define LP_DAY   3

Definition at line 254 of file zic.c.

Referenced by inleap().

#define LP_MONTH   2

Definition at line 253 of file zic.c.

Referenced by inleap().

#define LP_ROLL   6

Definition at line 257 of file zic.c.

Referenced by inleap().

#define LP_TIME   4

Definition at line 255 of file zic.c.

Referenced by inleap().

#define LP_YEAR   1

Definition at line 252 of file zic.c.

Referenced by inleap().

#define MKDIR_UMASK   0755

Definition at line 37 of file zic.c.

Referenced by mkdirs().

#define PRIdLINENO   "d"

Definition at line 52 of file zic.c.

Referenced by inzone(), and verror().

#define RF_ABBRVAR   9

Definition at line 237 of file zic.c.

Referenced by inrule().

#define RF_COMMAND   4

Definition at line 232 of file zic.c.

Referenced by inrule().

#define RF_DAY   6

Definition at line 234 of file zic.c.

Referenced by inrule().

#define RF_HIYEAR   3

Definition at line 231 of file zic.c.

Referenced by inrule().

#define RF_LOYEAR   2

Definition at line 230 of file zic.c.

Referenced by inrule().

#define RF_MONTH   5

Definition at line 233 of file zic.c.

Referenced by inrule().

#define RF_NAME   1

Definition at line 229 of file zic.c.

Referenced by inrule().

#define RF_STDOFF   8

Definition at line 236 of file zic.c.

Referenced by inrule().

#define RF_TOD   7

Definition at line 235 of file zic.c.

Referenced by inrule().

#define RULE_FIELDS   10

Definition at line 238 of file zic.c.

Referenced by inrule().

#define TIME_T_BITS_IN_FILE   64

Definition at line 964 of file zic.c.

#define YR_MAXIMUM   1

Definition at line 265 of file zic.c.

Referenced by rulesub().

#define YR_MINIMUM   0

Definition at line 264 of file zic.c.

Referenced by rulesub().

#define YR_ONLY   2

Definition at line 266 of file zic.c.

Referenced by rulesub().

#define ZF_FORMAT   4

Definition at line 203 of file zic.c.

Referenced by inzsub().

#define ZF_GMTOFF   2

Definition at line 201 of file zic.c.

Referenced by inzsub().

#define ZF_NAME   1

Definition at line 200 of file zic.c.

Referenced by inzone(), and inzsub().

#define ZF_RULE   3

Definition at line 202 of file zic.c.

Referenced by inzsub().

#define ZF_TILDAY   7

Definition at line 206 of file zic.c.

Referenced by inzsub().

#define ZF_TILMONTH   6

Definition at line 205 of file zic.c.

Referenced by inzsub().

#define ZF_TILTIME   8

Definition at line 207 of file zic.c.

Referenced by inzsub().

#define ZF_TILYEAR   5

Definition at line 204 of file zic.c.

Referenced by inzsub().

#define ZFC_FORMAT   2

Definition at line 217 of file zic.c.

Referenced by inzsub().

#define ZFC_GMTOFF   0

Definition at line 215 of file zic.c.

Referenced by inzsub().

#define ZFC_RULE   1

Definition at line 216 of file zic.c.

Referenced by inzsub().

#define ZFC_TILDAY   5

Definition at line 220 of file zic.c.

Referenced by inzsub().

#define ZFC_TILMONTH   4

Definition at line 219 of file zic.c.

Referenced by inzsub().

#define ZFC_TILTIME   6

Definition at line 221 of file zic.c.

Referenced by inzsub().

#define ZFC_TILYEAR   3

Definition at line 218 of file zic.c.

Referenced by inzsub().

#define ZIC_MAX   PG_INT64_MAX

Definition at line 27 of file zic.c.

Referenced by gethms(), oadd(), outzone(), rpytime(), rulesub(), and stringzone().

#define ZIC_MAX_ABBR_LEN_WO_WARN   6

Definition at line 30 of file zic.c.

Referenced by newabbr().

#define ZIC_MIN   PG_INT64_MIN

Definition at line 26 of file zic.c.

Referenced by oadd(), outzone(), rpytime(), and rulesub().

#define ZIC_VERSION   '3'

Definition at line 23 of file zic.c.

Referenced by outzone().

#define ZIC_VERSION_PRE_2013   '2'

Definition at line 22 of file zic.c.

Referenced by outzone().

#define ZONE_MAXFIELDS   9

Definition at line 209 of file zic.c.

Referenced by inzone().

#define ZONE_MINFIELDS   5

Definition at line 208 of file zic.c.

#define ZONEC_MAXFIELDS   7

Definition at line 223 of file zic.c.

Referenced by inzcont().

#define ZONEC_MINFIELDS   3

Definition at line 222 of file zic.c.

Typedef Documentation

Definition at line 51 of file zic.c.

typedef int64 zic_t

Definition at line 25 of file zic.c.

Enumeration Type Documentation

anonymous enum
Enumerator
WORK_AROUND_QTBUG_53071 

Definition at line 160 of file zic.c.

anonymous enum
Enumerator
WORK_AROUND_GNOME_BUG_730332 

Definition at line 1003 of file zic.c.

anonymous enum
Enumerator
YEAR_BY_YEAR_ZONE 

Definition at line 2508 of file zic.c.

2509 {
2510 YEAR_BY_YEAR_ZONE = 1};
anonymous enum
Enumerator
PERCENT_Z_LEN_BOUND 

Definition at line 151 of file zic.c.

152 {
153 PERCENT_Z_LEN_BOUND = sizeof "+995959" - 1};

Function Documentation

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

Definition at line 2283 of file zic.c.

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

Referenced by doabbr().

2284 {
2285  char sign = '+';
2286  int seconds,
2287  minutes;
2288 
2289  if (offset < 0)
2290  {
2291  offset = -offset;
2292  sign = '-';
2293  }
2294 
2295  seconds = offset % SECSPERMIN;
2296  offset /= SECSPERMIN;
2297  minutes = offset % MINSPERHOUR;
2298  offset /= MINSPERHOUR;
2299  if (100 <= offset)
2300  {
2301  error(_("%%z UTC offset magnitude exceeds 99:59:59"));
2302  return "%z";
2303  }
2304  else
2305  {
2306  char *p = buf;
2307 
2308  *p++ = sign;
2309  *p++ = '0' + offset / 10;
2310  *p++ = '0' + offset % 10;
2311  if (minutes | seconds)
2312  {
2313  *p++ = '0' + minutes / 10;
2314  *p++ = '0' + minutes % 10;
2315  if (seconds)
2316  {
2317  *p++ = '0' + seconds / 10;
2318  *p++ = '0' + seconds % 10;
2319  }
2320  }
2321  *p = '\0';
2322  return buf;
2323  }
2324 }
char sign
Definition: informix.c:693
static char * buf
Definition: pg_test_fsync.c:65
#define MINSPERHOUR
Definition: tzfile.h:104
#define SECSPERMIN
Definition: tzfile.h:103
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
#define _(x)
Definition: elog.c:84
static void addtt ( zic_t  starttime,
int  type 
)
static

Definition at line 3015 of file zic.c.

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

Referenced by outzone().

3016 {
3017  if (starttime <= early_time
3018  || (timecnt == 1 && attypes[0].at < early_time))
3019  {
3020  gmtoffs[0] = gmtoffs[type];
3021  isdsts[0] = isdsts[type];
3022  ttisstds[0] = ttisstds[type];
3023  ttisgmts[0] = ttisgmts[type];
3024  if (abbrinds[type] != 0)
3025  strcpy(chars, &chars[abbrinds[type]]);
3026  abbrinds[0] = 0;
3027  charcnt = strlen(chars) + 1;
3028  typecnt = 1;
3029  timecnt = 0;
3030  type = 0;
3031  }
3033  attypes[timecnt].at = starttime;
3034  attypes[timecnt].dontmerge = false;
3035  attypes[timecnt].type = type;
3036  ++timecnt;
3037 }
static bool ttisstds[TZ_MAX_TYPES]
Definition: zic.c:380
static int typecnt
Definition: zic.c:185
static zic_t gmtoffs[TZ_MAX_TYPES]
Definition: zic.c:377
static unsigned char abbrinds[TZ_MAX_TYPES]
Definition: zic.c:379
unsigned char type
Definition: zic.c:375
static char isdsts[TZ_MAX_TYPES]
Definition: zic.c:378
static bool ttisgmts[TZ_MAX_TYPES]
Definition: zic.c:381
static const zic_t early_time
Definition: zic.c:1007
static void * growalloc(void *ptr, size_t itemsize, ptrdiff_t nitems, ptrdiff_t *nitems_alloc)
Definition: zic.c:433
static struct attype * attypes
zic_t at
Definition: zic.c:373
static ptrdiff_t timecnt_alloc
Definition: zic.c:184
static ptrdiff_t timecnt
Definition: zic.c:183
static int charcnt
Definition: zic.c:164
bool dontmerge
Definition: zic.c:374
static char chars[TZ_MAX_CHARS]
Definition: zic.c:382
static int addtype ( zic_t  gmtoff,
char const *  abbr,
bool  isdst,
bool  ttisstd,
bool  ttisgmt 
)
static

Definition at line 3040 of file zic.c.

References _, charcnt, error(), EXIT_FAILURE, i, newabbr(), typecnt, and TZ_MAX_TYPES.

Referenced by outzone(), and writezone().

3041 {
3042  int i,
3043  j;
3044 
3045  /*
3046  * See if there's already an entry for this zone type. If so, just return
3047  * its index.
3048  */
3049  for (i = 0; i < typecnt; ++i)
3050  {
3051  if (gmtoff == gmtoffs[i] && isdst == isdsts[i] &&
3052  strcmp(abbr, &chars[abbrinds[i]]) == 0 &&
3053  ttisstd == ttisstds[i] &&
3054  ttisgmt == ttisgmts[i])
3055  return i;
3056  }
3057 
3058  /*
3059  * There isn't one; add a new one, unless there are already too many.
3060  */
3061  if (typecnt >= TZ_MAX_TYPES)
3062  {
3063  error(_("too many local time types"));
3064  exit(EXIT_FAILURE);
3065  }
3066  if (!(-1L - 2147483647L <= gmtoff && gmtoff <= 2147483647L))
3067  {
3068  error(_("UT offset out of range"));
3069  exit(EXIT_FAILURE);
3070  }
3071  gmtoffs[i] = gmtoff;
3072  isdsts[i] = isdst;
3073  ttisstds[i] = ttisstd;
3074  ttisgmts[i] = ttisgmt;
3075 
3076  for (j = 0; j < charcnt; ++j)
3077  if (strcmp(&chars[j], abbr) == 0)
3078  break;
3079  if (j == charcnt)
3080  newabbr(abbr);
3081  abbrinds[i] = j;
3082  ++typecnt;
3083  return i;
3084 }
static bool ttisstds[TZ_MAX_TYPES]
Definition: zic.c:380
static int typecnt
Definition: zic.c:185
static zic_t gmtoffs[TZ_MAX_TYPES]
Definition: zic.c:377
static unsigned char abbrinds[TZ_MAX_TYPES]
Definition: zic.c:379
static char isdsts[TZ_MAX_TYPES]
Definition: zic.c:378
static bool ttisgmts[TZ_MAX_TYPES]
Definition: zic.c:381
static int charcnt
Definition: zic.c:164
#define TZ_MAX_TYPES
Definition: tzfile.h:96
static void newabbr(const char *abbr)
Definition: zic.c:3571
int i
#define EXIT_FAILURE
Definition: settings.h:150
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
static char chars[TZ_MAX_CHARS]
Definition: zic.c:382
#define _(x)
Definition: elog.c:84
static void adjleap ( void  )
static

Definition at line 3123 of file zic.c.

References i, leapcnt, and tadd().

Referenced by main().

3124 {
3125  int i;
3126  zic_t last = 0;
3127 
3128  /*
3129  * propagate leap seconds forward
3130  */
3131  for (i = 0; i < leapcnt; ++i)
3132  {
3133  trans[i] = tadd(trans[i], last);
3134  last = corr[i] += last;
3135  }
3136 }
static zic_t corr[TZ_MAX_LEAPS]
Definition: zic.c:384
static zic_t tadd(zic_t t1, zic_t t2)
Definition: zic.c:3444
static int leapcnt
Definition: zic.c:168
int64 zic_t
Definition: zic.c:25
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:383
int i
static void associate ( void  )
static

Definition at line 1065 of file zic.c.

References _, eat(), error(), EXIT_FAILURE, gethms(), i, nrules, NULL, nzones, qsort, rule::r_filename, rule::r_linenum, rule::r_name, rcomp(), warning(), zone::z_filename, zone::z_format_specifier, zone::z_linenum, zone::z_nrules, zone::z_rule, zone::z_rules, and zone::z_stdoff.

Referenced by main().

1066 {
1067  struct zone *zp;
1068  struct rule *rp;
1069  ptrdiff_t i,
1070  j,
1071  base,
1072  out;
1073 
1074  if (nrules != 0)
1075  {
1076  qsort(rules, nrules, sizeof *rules, rcomp);
1077  for (i = 0; i < nrules - 1; ++i)
1078  {
1079  if (strcmp(rules[i].r_name,
1080  rules[i + 1].r_name) != 0)
1081  continue;
1082  if (strcmp(rules[i].r_filename,
1083  rules[i + 1].r_filename) == 0)
1084  continue;
1085  eat(rules[i].r_filename, rules[i].r_linenum);
1086  warning(_("same rule name in multiple files"));
1087  eat(rules[i + 1].r_filename, rules[i + 1].r_linenum);
1088  warning(_("same rule name in multiple files"));
1089  for (j = i + 2; j < nrules; ++j)
1090  {
1091  if (strcmp(rules[i].r_name,
1092  rules[j].r_name) != 0)
1093  break;
1094  if (strcmp(rules[i].r_filename,
1095  rules[j].r_filename) == 0)
1096  continue;
1097  if (strcmp(rules[i + 1].r_filename,
1098  rules[j].r_filename) == 0)
1099  continue;
1100  break;
1101  }
1102  i = j - 1;
1103  }
1104  }
1105  for (i = 0; i < nzones; ++i)
1106  {
1107  zp = &zones[i];
1108  zp->z_rules = NULL;
1109  zp->z_nrules = 0;
1110  }
1111  for (base = 0; base < nrules; base = out)
1112  {
1113  rp = &rules[base];
1114  for (out = base + 1; out < nrules; ++out)
1115  if (strcmp(rp->r_name, rules[out].r_name) != 0)
1116  break;
1117  for (i = 0; i < nzones; ++i)
1118  {
1119  zp = &zones[i];
1120  if (strcmp(zp->z_rule, rp->r_name) != 0)
1121  continue;
1122  zp->z_rules = rp;
1123  zp->z_nrules = out - base;
1124  }
1125  }
1126  for (i = 0; i < nzones; ++i)
1127  {
1128  zp = &zones[i];
1129  if (zp->z_nrules == 0)
1130  {
1131  /*
1132  * Maybe we have a local standard time offset.
1133  */
1134  eat(zp->z_filename, zp->z_linenum);
1135  zp->z_stdoff = gethms(zp->z_rule, _("unruly zone"),
1136  true);
1137 
1138  /*
1139  * Note, though, that if there's no rule, a '%s' in the format is
1140  * a bad thing.
1141  */
1142  if (zp->z_format_specifier == 's')
1143  error("%s", _("%s in ruleless zone"));
1144  }
1145  }
1146  if (errors)
1147  exit(EXIT_FAILURE);
1148 }
lineno_t r_linenum
Definition: zic.c:57
static int rcomp(const void *cp1, const void *cp2)
Definition: zic.c:1058
const char * z_rule
Definition: zic.c:98
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:495
static bool errors
Definition: zic.c:165
static ptrdiff_t nzones
Definition: zic.c:273
Definition: localtime.c:74
char z_format_specifier
Definition: zic.c:100
const char * r_name
Definition: zic.c:58
const char * z_filename
Definition: zic.c:93
static struct rule * rules
Definition: zic.c:268
const char * r_filename
Definition: zic.c:56
static zic_t gethms(const char *string, const char *errstring, bool)
Definition: zic.c:1254
static void eat(char const *name, lineno_t num)
Definition: zic.c:462
ptrdiff_t z_nrules
Definition: zic.c:105
lineno_t z_linenum
Definition: zic.c:94
#define NULL
Definition: c.h:226
static ptrdiff_t nrules
Definition: zic.c:269
static struct zone * zones
Definition: zic.c:272
struct rule * z_rules
Definition: zic.c:104
Definition: zic.c:91
int i
#define EXIT_FAILURE
Definition: settings.h:150
#define qsort(a, b, c, d)
Definition: port.h:440
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
#define _(x)
Definition: elog.c:84
zic_t z_stdoff
Definition: zic.c:102
static int atcomp ( const void *  avp,
const void *  bvp 
)
static

Definition at line 1851 of file zic.c.

Referenced by writezone().

1852 {
1853  const zic_t a = ((const struct attype *) avp)->at;
1854  const zic_t b = ((const struct attype *) bvp)->at;
1855 
1856  return (a < b) ? -1 : (a > b);
1857 }
Definition: zic.c:371
int64 zic_t
Definition: zic.c:25
static const struct lookup * byword ( const char *  string,
const struct lookup lp 
)
static

Definition at line 3358 of file zic.c.

References ciequal(), itsabbr(), lookup::l_word, and NULL.

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

3359 {
3360  const struct lookup *foundlp;
3361  const struct lookup *lp;
3362 
3363  if (word == NULL || table == NULL)
3364  return NULL;
3365 
3366  /*
3367  * Look for exact match.
3368  */
3369  for (lp = table; lp->l_word != NULL; ++lp)
3370  if (ciequal(word, lp->l_word))
3371  return lp;
3372 
3373  /*
3374  * Look for inexact match.
3375  */
3376  foundlp = NULL;
3377  for (lp = table; lp->l_word != NULL; ++lp)
3378  if (itsabbr(word, lp->l_word))
3379  {
3380  if (foundlp == NULL)
3381  foundlp = lp;
3382  else
3383  return NULL; /* multiple inexact matches */
3384  }
3385  return foundlp;
3386 }
Definition: zic.c:288
static bool ciequal(const char *ap, const char *bp)
Definition: zic.c:3334
const char * l_word
Definition: zic.c:290
#define NULL
Definition: c.h:226
static void word(struct vars *, int, struct state *, struct state *)
Definition: regcomp.c:1245
static bool itsabbr(const char *abbr, const char *word)
Definition: zic.c:3343
static void change_directory ( char const *  dir)
static

Definition at line 540 of file zic.c.

References _, EXIT_FAILURE, mkdirs(), and strerror().

Referenced by main().

541 {
542  if (chdir(dir) != 0)
543  {
544  int chdir_errno = errno;
545 
546  if (chdir_errno == ENOENT)
547  {
548  mkdirs(dir, false);
549  chdir_errno = chdir(dir) == 0 ? 0 : errno;
550  }
551  if (chdir_errno != 0)
552  {
553  fprintf(stderr, _("%s: Can't chdir to %s: %s\n"),
554  progname, dir, strerror(chdir_errno));
555  exit(EXIT_FAILURE);
556  }
557  }
558 }
static void mkdirs(char const *, bool)
Definition: zic.c:3609
static const char * progname
Definition: zic.c:182
const char * strerror(int errnum)
Definition: strerror.c:19
#define EXIT_FAILURE
Definition: settings.h:150
#define _(x)
Definition: elog.c:84
static bool ciequal ( const char *  ap,
const char *  bp 
)
static

Definition at line 3334 of file zic.c.

References lowerit().

Referenced by byword().

3335 {
3336  while (lowerit(*ap) == lowerit(*bp++))
3337  if (*ap++ == '\0')
3338  return true;
3339  return false;
3340 }
static char lowerit(char)
Definition: zic.c:3271
static void close_file ( FILE *  stream,
char const *  dir,
char const *  name 
)
static

Definition at line 507 of file zic.c.

References _, EXIT_FAILURE, NULL, and strerror().

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

508 {
509  char const *e = (ferror(stream) ? _("I/O error")
510  : fclose(stream) != 0 ? strerror(errno) : NULL);
511 
512  if (e)
513  {
514  fprintf(stderr, "%s: %s%s%s%s%s\n", progname,
515  dir ? dir : "", dir ? "/" : "",
516  name ? name : "", name ? ": " : "",
517  e);
518  exit(EXIT_FAILURE);
519  }
520 }
static const char * progname
Definition: zic.c:182
#define NULL
Definition: c.h:226
const char * name
Definition: encode.c:521
e
Definition: preproc-init.c:82
const char * strerror(int errnum)
Definition: strerror.c:19
#define EXIT_FAILURE
Definition: settings.h:150
#define _(x)
Definition: elog.c:84
static bool componentcheck ( char const *  name,
char const *  component,
char const *  component_end 
)
static

Definition at line 724 of file zic.c.

References _, error(), and warning().

Referenced by namecheck().

726 {
727  enum
728  {
729  component_len_max = 14};
730  ptrdiff_t component_len = component_end - component;
731 
732  if (component_len == 0)
733  {
734  if (!*name)
735  error(_("empty file name"));
736  else
737  error(_(component == name
738  ? "file name '%s' begins with '/'"
739  : *component_end
740  ? "file name '%s' contains '//'"
741  : "file name '%s' ends with '/'"),
742  name);
743  return false;
744  }
745  if (0 < component_len && component_len <= 2
746  && component[0] == '.' && component_end[-1] == '.')
747  {
748  int len = component_len;
749 
750  error(_("file name '%s' contains '%.*s' component"),
751  name, len, component);
752  return false;
753  }
754  if (noise)
755  {
756  if (0 < component_len && component[0] == '-')
757  warning(_("file name '%s' component contains leading '-'"),
758  name);
759  if (component_len_max < component_len)
760  warning(_("file name '%s' contains overlength component"
761  " '%.*s...'"),
762  name, component_len_max, component);
763  }
764  return true;
765 }
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:495
static bool noise
Definition: zic.c:177
const char * name
Definition: encode.c:521
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
#define _(x)
Definition: elog.c:84
static void convert ( const int32  val,
char *const  buf 
)
static

Definition at line 1811 of file zic.c.

References i.

Referenced by ExecEvalConvertRowtype(), ExecInitExpr(), fmtfloat(), fmtint(), fmtptr(), get_rule_expr(), puttzcode(), and writezone().

1812 {
1813  int i;
1814  int shift;
1815  unsigned char *const b = (unsigned char *) buf;
1816 
1817  for (i = 0, shift = 24; i < 4; ++i, shift -= 8)
1818  b[i] = val >> shift;
1819 }
static char * buf
Definition: pg_test_fsync.c:65
int i
long val
Definition: informix.c:689
static void convert64 ( const zic_t  val,
char *const  buf 
)
static

Definition at line 1822 of file zic.c.

References i.

Referenced by puttzcode64().

1823 {
1824  int i;
1825  int shift;
1826  unsigned char *const b = (unsigned char *) buf;
1827 
1828  for (i = 0, shift = 56; i < 8; ++i, shift -= 8)
1829  b[i] = val >> shift;
1830 }
static char * buf
Definition: pg_test_fsync.c:65
int i
long val
Definition: informix.c:689
static size_t doabbr ( char *  abbr,
struct zone const *  zp,
char const *  letters,
zic_t  stdoff,
bool  doquotes 
)
static

Definition at line 2327 of file zic.c.

References abbroffset(), format, is_alpha(), memmove, NULL, PERCENT_Z_LEN_BOUND, zone::z_format, zone::z_format_specifier, and zone::z_gmtoff.

Referenced by outzone(), and stringzone().

2329 {
2330  char *cp;
2331  char *slashp;
2332  size_t len;
2333  char const *format = zp->z_format;
2334 
2335  slashp = strchr(format, '/');
2336  if (slashp == NULL)
2337  {
2338  char letterbuf[PERCENT_Z_LEN_BOUND + 1];
2339 
2340  if (zp->z_format_specifier == 'z')
2341  letters = abbroffset(letterbuf, zp->z_gmtoff + stdoff);
2342  else if (!letters)
2343  letters = "%s";
2344  sprintf(abbr, format, letters);
2345  }
2346  else if (stdoff != 0)
2347  {
2348  strcpy(abbr, slashp + 1);
2349  }
2350  else
2351  {
2352  memcpy(abbr, format, slashp - format);
2353  abbr[slashp - format] = '\0';
2354  }
2355  len = strlen(abbr);
2356  if (!doquotes)
2357  return len;
2358  for (cp = abbr; is_alpha(*cp); cp++)
2359  continue;
2360  if (len > 0 && *cp == '\0')
2361  return len;
2362  abbr[len + 2] = '\0';
2363  abbr[len + 1] = '>';
2364  memmove(abbr + 1, abbr, len);
2365  abbr[0] = '<';
2366  return len + 2;
2367 }
static char const * abbroffset(char *buf, zic_t offset)
Definition: zic.c:2283
static bool is_alpha(char a)
Definition: zic.c:3206
#define memmove(d, s, c)
Definition: c.h:1058
#define NULL
Definition: c.h:226
static char format
Definition: pg_basebackup.c:83
static void dolink ( const char *  fromfield,
const char *  tofield,
bool  staysymlink 
)
static

Definition at line 869 of file zic.c.

References _, close_file(), ENOTSUP, EXIT_FAILURE, free, hardlinkerr(), itsdir(), itssymlink(), mkdirs(), NULL, strerror(), and warning().

Referenced by main().

870 {
871  bool todirs_made = false;
872  int link_errno;
873 
874  /*
875  * We get to be careful here since there's a fair chance of root running
876  * us.
877  */
878  if (itsdir(fromfield))
879  {
880  fprintf(stderr, _("%s: link from %s/%s failed: %s\n"),
881  progname, directory, fromfield, strerror(EPERM));
882  exit(EXIT_FAILURE);
883  }
884  if (staysymlink)
885  staysymlink = itssymlink(tofield);
886  if (remove(tofield) == 0)
887  todirs_made = true;
888  else if (errno != ENOENT)
889  {
890  char const *e = strerror(errno);
891 
892  fprintf(stderr, _("%s: Can't remove %s/%s: %s\n"),
893  progname, directory, tofield, e);
894  exit(EXIT_FAILURE);
895  }
896  link_errno = staysymlink ? ENOTSUP : hardlinkerr(fromfield, tofield);
897  if (link_errno == ENOENT && !todirs_made)
898  {
899  mkdirs(tofield, true);
900  todirs_made = true;
901  link_errno = hardlinkerr(fromfield, tofield);
902  }
903  if (link_errno != 0)
904  {
905 #ifdef HAVE_SYMLINK
906  bool absolute = *fromfield == '/';
907  char *linkalloc = absolute ? NULL : relname(fromfield, tofield);
908  char const *contents = absolute ? fromfield : linkalloc;
909  int symlink_errno = symlink(contents, tofield) == 0 ? 0 : errno;
910 
911  if (symlink_errno == ENOENT && !todirs_made)
912  {
913  mkdirs(tofield, true);
914  symlink_errno = symlink(contents, tofield) == 0 ? 0 : errno;
915  }
916  free(linkalloc);
917  if (symlink_errno == 0)
918  {
919  if (link_errno != ENOTSUP)
920  warning(_("symbolic link used because hard link failed: %s"),
921  strerror(link_errno));
922  }
923  else
924 #endif /* HAVE_SYMLINK */
925  {
926  FILE *fp,
927  *tp;
928  int c;
929 
930  fp = fopen(fromfield, "rb");
931  if (!fp)
932  {
933  char const *e = strerror(errno);
934 
935  fprintf(stderr, _("%s: Can't read %s/%s: %s\n"),
936  progname, directory, fromfield, e);
937  exit(EXIT_FAILURE);
938  }
939  tp = fopen(tofield, "wb");
940  if (!tp)
941  {
942  char const *e = strerror(errno);
943 
944  fprintf(stderr, _("%s: Can't create %s/%s: %s\n"),
945  progname, directory, tofield, e);
946  exit(EXIT_FAILURE);
947  }
948  while ((c = getc(fp)) != EOF)
949  putc(c, tp);
950  close_file(fp, directory, fromfield);
951  close_file(tp, directory, tofield);
952  if (link_errno != ENOTSUP)
953  warning(_("copy used because hard link failed: %s"),
954  strerror(link_errno));
955 #ifdef HAVE_SYMLINK
956  else if (symlink_errno != ENOTSUP)
957  warning(_("copy used because symbolic link failed: %s"),
958  strerror(symlink_errno));
959 #endif
960  }
961  }
962 }
static int hardlinkerr(char const *from, char const *to)
Definition: zic.c:861
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:495
#define ENOTSUP
Definition: private.h:35
static void mkdirs(char const *, bool)
Definition: zic.c:3609
static bool itsdir(char const *)
Definition: zic.c:1013
char * c
static bool itssymlink(char const *)
Definition: zic.c:1038
static const char * progname
Definition: zic.c:182
#define free(a)
Definition: header.h:60
#define NULL
Definition: c.h:226
static const char * directory
Definition: zic.c:562
static void close_file(FILE *stream, char const *dir, char const *name)
Definition: zic.c:507
e
Definition: preproc-init.c:82
const char * strerror(int errnum)
Definition: strerror.c:19
#define EXIT_FAILURE
Definition: settings.h:150
#define _(x)
Definition: elog.c:84
static void eat ( char const *  name,
lineno_t  num 
)
static

Definition at line 462 of file zic.c.

References eats(), and NULL.

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

463 {
464  eats(name, num, NULL, -1);
465 }
#define NULL
Definition: c.h:226
const char * name
Definition: encode.c:521
static void eats(char const *name, lineno_t num, char const *rname, lineno_t rnum)
Definition: zic.c:453
static void eats ( char const *  name,
lineno_t  num,
char const *  rname,
lineno_t  rnum 
)
static

Definition at line 453 of file zic.c.

References name.

Referenced by eat(), and outzone().

454 {
455  filename = name;
456  linenum = num;
457  rfilename = rname;
458  rlinenum = rnum;
459 }
static lineno_t rlinenum
Definition: zic.c:181
static const char * filename
Definition: zic.c:167
static lineno_t linenum
Definition: zic.c:172
static const char * rfilename
Definition: zic.c:180
const char * name
Definition: encode.c:521
static char* ecpyalloc ( char const *  str)
static

Definition at line 427 of file zic.c.

References memcheck().

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

428 {
429  return memcheck(strdup(str));
430 }
static void * memcheck(void *ptr)
Definition: zic.c:407
static void* emalloc ( size_t  size)
static

Definition at line 415 of file zic.c.

References malloc, and memcheck().

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

416 {
417  return memcheck(malloc(size));
418 }
#define malloc(a)
Definition: header.h:45
static void * memcheck(void *ptr)
Definition: zic.c:407
static void* erealloc ( void *  ptr,
size_t  size 
)
static

Definition at line 421 of file zic.c.

References memcheck(), and realloc.

Referenced by growalloc().

422 {
423  return memcheck(realloc(ptr, size));
424 }
#define realloc(a, b)
Definition: header.h:55
static void * memcheck(void *ptr)
Definition: zic.c:407
static void error ( const char *  string,
  ... 
)
static

Definition at line 484 of file zic.c.

References generate_unaccent_rules::args, and verror().

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

485 {
486  va_list args;
487 
488  va_start(args, string);
489  verror(string, args);
490  va_end(args);
491  errors = true;
492 }
static bool errors
Definition: zic.c:165
static void verror(const char *string, va_list args) pg_attribute_printf(1
Definition: zic.c:468
static char ** getfields ( char *  buf)
static

Definition at line 3389 of file zic.c.

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

Referenced by infile().

3390 {
3391  char *dp;
3392  char **array;
3393  int nsubs;
3394 
3395  if (cp == NULL)
3396  return NULL;
3397  array = emalloc(size_product(strlen(cp) + 1, sizeof *array));
3398  nsubs = 0;
3399  for (;;)
3400  {
3401  while (is_space(*cp))
3402  ++cp;
3403  if (*cp == '\0' || *cp == '#')
3404  break;
3405  array[nsubs++] = dp = cp;
3406  do
3407  {
3408  if ((*dp = *cp++) != '"')
3409  ++dp;
3410  else
3411  while ((*dp = *cp++) != '"')
3412  if (*dp != '\0')
3413  ++dp;
3414  else
3415  {
3416  error(_("Odd number of quotation marks"));
3417  exit(EXIT_FAILURE);
3418  }
3419  } while (*cp && *cp != '#' && !is_space(*cp));
3420  if (is_space(*cp))
3421  ++cp;
3422  *dp = '\0';
3423  }
3424  array[nsubs] = NULL;
3425  return array;
3426 }
static bool is_space(char a)
Definition: zic.c:3188
#define NULL
Definition: c.h:226
#define EXIT_FAILURE
Definition: settings.h:150
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
#define _(x)
Definition: elog.c:84
static size_t size_product(size_t nitems, size_t itemsize)
Definition: zic.c:399
static void * emalloc(size_t size)
Definition: zic.c:415
static zic_t gethms ( const char *  string,
const char *  errstring,
bool  signable 
)
static

Definition at line 1254 of file zic.c.

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

Referenced by associate(), inleap(), inrule(), inzsub(), and rulesub().

1255 {
1256  /* PG: make hh be int not zic_t to avoid sscanf portability issues */
1257  int hh;
1258  int mm,
1259  ss,
1260  sign;
1261  char xs;
1262 
1263  if (string == NULL || *string == '\0')
1264  return 0;
1265  if (!signable)
1266  sign = 1;
1267  else if (*string == '-')
1268  {
1269  sign = -1;
1270  ++string;
1271  }
1272  else
1273  sign = 1;
1274  if (sscanf(string, "%d%c", &hh, &xs) == 1)
1275  mm = ss = 0;
1276  else if (sscanf(string, "%d:%d%c", &hh, &mm, &xs) == 2)
1277  ss = 0;
1278  else if (sscanf(string, "%d:%d:%d%c", &hh, &mm, &ss, &xs)
1279  != 3)
1280  {
1281  error("%s", errstring);
1282  return 0;
1283  }
1284  if (hh < 0 ||
1285  mm < 0 || mm >= MINSPERHOUR ||
1286  ss < 0 || ss > SECSPERMIN)
1287  {
1288  error("%s", errstring);
1289  return 0;
1290  }
1291  /* Some compilers warn that this test is unsatisfiable for 32-bit ints */
1292 #if INT_MAX > PG_INT32_MAX
1293  if (ZIC_MAX / SECSPERHOUR < hh)
1294  {
1295  error(_("time overflow"));
1296  return 0;
1297  }
1298 #endif
1299  if (noise && (hh > HOURSPERDAY ||
1300  (hh == HOURSPERDAY && (mm != 0 || ss != 0))))
1301  warning(_("values over 24 hours not handled by pre-2007 versions of zic"));
1302  return oadd(sign * (zic_t) hh * SECSPERHOUR,
1303  sign * (mm * SECSPERMIN + ss));
1304 }
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:495
#define HOURSPERDAY
Definition: tzfile.h:105
#define ZIC_MAX
Definition: zic.c:27
char sign
Definition: informix.c:693
char string[11]
Definition: preproc-type.c:46
int64 zic_t
Definition: zic.c:25
#define MINSPERHOUR
Definition: tzfile.h:104
static bool noise
Definition: zic.c:177
#define NULL
Definition: c.h:226
#define SECSPERMIN
Definition: tzfile.h:103
#define SECSPERHOUR
Definition: tzfile.h:109
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
#define _(x)
Definition: elog.c:84
static zic_t oadd(zic_t t1, zic_t t2)
Definition: zic.c:3436
static void* growalloc ( void *  ptr,
size_t  itemsize,
ptrdiff_t  nitems,
ptrdiff_t *  nitems_alloc 
)
static

Definition at line 433 of file zic.c.

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

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

434 {
435  if (nitems < *nitems_alloc)
436  return ptr;
437  else
438  {
439  ptrdiff_t amax = PTRDIFF_MAX - WORK_AROUND_QTBUG_53071;
440 
441  if ((amax - 1) / 3 * 2 < *nitems_alloc)
442  memory_exhausted(_("integer overflow"));
443  *nitems_alloc += (*nitems_alloc >> 1) + 1;
444  return erealloc(ptr, size_product(*nitems_alloc, itemsize));
445  }
446 }
static ptrdiff_t const PTRDIFF_MAX
Definition: zic.c:47
static void memory_exhausted(const char *msg) pg_attribute_noreturn()
Definition: zic.c:392
#define _(x)
Definition: elog.c:84
static size_t size_product(size_t nitems, size_t itemsize)
Definition: zic.c:399
static void * erealloc(void *ptr, size_t size)
Definition: zic.c:421
static int hardlinkerr ( char const *  from,
char const *  to 
)
static

Definition at line 861 of file zic.c.

References linkat.

Referenced by dolink().

862 {
863  int r = linkat(AT_FDCWD, from, AT_FDCWD, to, AT_SYMLINK_FOLLOW);
864 
865  return r == 0 ? 0 : errno;
866 }
#define linkat(fromdir, from, todir, to, flag)
Definition: zic.c:41
static void infile ( const char *  filename)
static

Definition at line 1151 of file zic.c.

References _, buf, byword(), close_file(), eat(), error(), EXIT_FAILURE, free, getfields(), inleap(), inlink(), inrule(), inzcont(), inzone(), lookup::l_value, LC_LEAP, LC_LINK, LC_RULE, LC_ZONE, NULL, strerror(), and warning().

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

1152 {
1153  FILE *fp;
1154  char **fields;
1155  char *cp;
1156  const struct lookup *lp;
1157  int nfields;
1158  bool wantcont;
1159  lineno_t num;
1160  char buf[BUFSIZ];
1161 
1162  if (strcmp(name, "-") == 0)
1163  {
1164  name = _("standard input");
1165  fp = stdin;
1166  }
1167  else if ((fp = fopen(name, "r")) == NULL)
1168  {
1169  const char *e = strerror(errno);
1170 
1171  fprintf(stderr, _("%s: Cannot open %s: %s\n"),
1172  progname, name, e);
1173  exit(EXIT_FAILURE);
1174  }
1175  wantcont = false;
1176  for (num = 1;; ++num)
1177  {
1178  eat(name, num);
1179  if (fgets(buf, sizeof buf, fp) != buf)
1180  break;
1181  cp = strchr(buf, '\n');
1182  if (cp == NULL)
1183  {
1184  error(_("line too long"));
1185  exit(EXIT_FAILURE);
1186  }
1187  *cp = '\0';
1188  fields = getfields(buf);
1189  nfields = 0;
1190  while (fields[nfields] != NULL)
1191  {
1192  static char nada;
1193 
1194  if (strcmp(fields[nfields], "-") == 0)
1195  fields[nfields] = &nada;
1196  ++nfields;
1197  }
1198  if (nfields == 0)
1199  {
1200  /* nothing to do */
1201  }
1202  else if (wantcont)
1203  wantcont = inzcont(fields, nfields);
1204  else
1205  {
1206  lp = byword(fields[0], line_codes);
1207  if (lp == NULL)
1208  error(_("input line of unknown type"));
1209  else
1210  switch (lp->l_value)
1211  {
1212  case LC_RULE:
1213  inrule(fields, nfields);
1214  wantcont = false;
1215  break;
1216  case LC_ZONE:
1217  wantcont = inzone(fields, nfields);
1218  break;
1219  case LC_LINK:
1220  inlink(fields, nfields);
1221  wantcont = false;
1222  break;
1223  case LC_LEAP:
1224  if (name != leapsec)
1225  warning(_("%s: Leap line in non leap"
1226  " seconds file %s"),
1227  progname, name);
1228  else
1229  inleap(fields, nfields);
1230  wantcont = false;
1231  break;
1232  default: /* "cannot happen" */
1233  fprintf(stderr,
1234  _("%s: panic: Invalid l_value %d\n"),
1235  progname, lp->l_value);
1236  exit(EXIT_FAILURE);
1237  }
1238  }
1239  free(fields);
1240  }
1241  close_file(fp, NULL, filename);
1242  if (wantcont)
1243  error(_("expected continuation line not found"));
1244 }
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:495
static void inrule(char **fields, int nfields)
Definition: zic.c:1307
#define LC_LEAP
Definition: zic.c:194
static const char * leapsec
Definition: zic.c:563
const int l_value
Definition: zic.c:291
static const char * filename
Definition: zic.c:167
static void inleap(char **fields, int nfields)
Definition: zic.c:1483
static char ** getfields(char *buf)
Definition: zic.c:3389
static bool inzcont(char **fields, int nfields)
Definition: zic.c:1373
static char * buf
Definition: pg_test_fsync.c:65
Definition: zic.c:288
#define LC_LINK
Definition: zic.c:193
static void eat(char const *name, lineno_t num)
Definition: zic.c:462
#define LC_ZONE
Definition: zic.c:192
static const char * progname
Definition: zic.c:182
#define free(a)
Definition: header.h:60
static bool inzone(char **fields, int nfields)
Definition: zic.c:1335
#define NULL
Definition: c.h:226
static void inlink(char **fields, int nfields)
Definition: zic.c:1613
static void close_file(FILE *stream, char const *dir, char const *name)
Definition: zic.c:507
static struct lookup const * byword(const char *string, const struct lookup *lp)
Definition: zic.c:3358
static struct lookup const line_codes[]
Definition: zic.c:297
const char * name
Definition: encode.c:521
e
Definition: preproc-init.c:82
const char * strerror(int errnum)
Definition: strerror.c:19
#define EXIT_FAILURE
Definition: settings.h:150
int lineno_t
Definition: zic.c:51
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
#define LC_RULE
Definition: zic.c:191
#define _(x)
Definition: elog.c:84
static void inleap ( char **  fields,
int  nfields 
)
static

Definition at line 1483 of file zic.c.

References _, byword(), EPOCH_YEAR, error(), gethms(), i, isleap, lookup::l_value, LEAP_FIELDS, leapadd(), LP_CORR, LP_DAY, LP_MONTH, LP_ROLL, LP_TIME, LP_YEAR, NULL, oadd(), SECSPERDAY, tadd(), and TM_JANUARY.

Referenced by infile().

1484 {
1485  const char *cp;
1486  const struct lookup *lp;
1487  zic_t i,
1488  j;
1489 
1490  /* PG: make year be int not zic_t to avoid sscanf portability issues */
1491  int year;
1492  int month,
1493  day;
1494  zic_t dayoff,
1495  tod;
1496  zic_t t;
1497  char xs;
1498 
1499  if (nfields != LEAP_FIELDS)
1500  {
1501  error(_("wrong number of fields on Leap line"));
1502  return;
1503  }
1504  dayoff = 0;
1505  cp = fields[LP_YEAR];
1506  if (sscanf(cp, "%d%c", &year, &xs) != 1)
1507  {
1508  /*
1509  * Leapin' Lizards!
1510  */
1511  error(_("invalid leaping year"));
1512  return;
1513  }
1514  if (!leapseen || leapmaxyear < year)
1515  leapmaxyear = year;
1516  if (!leapseen || leapminyear > year)
1517  leapminyear = year;
1518  leapseen = true;
1519  j = EPOCH_YEAR;
1520  while (j != year)
1521  {
1522  if (year > j)
1523  {
1524  i = len_years[isleap(j)];
1525  ++j;
1526  }
1527  else
1528  {
1529  --j;
1530  i = -len_years[isleap(j)];
1531  }
1532  dayoff = oadd(dayoff, i);
1533  }
1534  if ((lp = byword(fields[LP_MONTH], mon_names)) == NULL)
1535  {
1536  error(_("invalid month name"));
1537  return;
1538  }
1539  month = lp->l_value;
1540  j = TM_JANUARY;
1541  while (j != month)
1542  {
1543  i = len_months[isleap(year)][j];
1544  dayoff = oadd(dayoff, i);
1545  ++j;
1546  }
1547  cp = fields[LP_DAY];
1548  if (sscanf(cp, "%d%c", &day, &xs) != 1 ||
1549  day <= 0 || day > len_months[isleap(year)][month])
1550  {
1551  error(_("invalid day of month"));
1552  return;
1553  }
1554  dayoff = oadd(dayoff, day - 1);
1555  if (dayoff < min_time / SECSPERDAY)
1556  {
1557  error(_("time too small"));
1558  return;
1559  }
1560  if (dayoff > max_time / SECSPERDAY)
1561  {
1562  error(_("time too large"));
1563  return;
1564  }
1565  t = dayoff * SECSPERDAY;
1566  tod = gethms(fields[LP_TIME], _("invalid time of day"), false);
1567  cp = fields[LP_CORR];
1568  {
1569  bool positive;
1570  int count;
1571 
1572  if (strcmp(cp, "") == 0)
1573  { /* infile() turns "-" into "" */
1574  positive = false;
1575  count = 1;
1576  }
1577  else if (strcmp(cp, "--") == 0)
1578  {
1579  positive = false;
1580  count = 2;
1581  }
1582  else if (strcmp(cp, "+") == 0)
1583  {
1584  positive = true;
1585  count = 1;
1586  }
1587  else if (strcmp(cp, "++") == 0)
1588  {
1589  positive = true;
1590  count = 2;
1591  }
1592  else
1593  {
1594  error(_("illegal CORRECTION field on Leap line"));
1595  return;
1596  }
1597  if ((lp = byword(fields[LP_ROLL], leap_types)) == NULL)
1598  {
1599  error(_("illegal Rolling/Stationary field on Leap line"));
1600  return;
1601  }
1602  t = tadd(t, tod);
1603  if (t < early_time)
1604  {
1605  error(_("leap second precedes Big Bang"));
1606  return;
1607  }
1608  leapadd(t, positive, lp->l_value, count);
1609  }
1610 }
#define LP_CORR
Definition: zic.c:256
static zic_t leapmaxyear
Definition: zic.c:171
#define isleap(y)
Definition: datetime.h:273
static const int len_months[2][MONSPERYEAR]
Definition: zic.c:362
const int l_value
Definition: zic.c:291
#define LP_ROLL
Definition: zic.c:257
static const zic_t early_time
Definition: zic.c:1007
static zic_t tadd(zic_t t1, zic_t t2)
Definition: zic.c:3444
#define LEAP_FIELDS
Definition: zic.c:258
static struct lookup const mon_names[]
Definition: zic.c:305
#define SECSPERDAY
Definition: tzfile.h:110
#define LP_DAY
Definition: zic.c:254
static bool leapseen
Definition: zic.c:169
int64 zic_t
Definition: zic.c:25
Definition: zic.c:288
static void leapadd(zic_t, bool, int, int)
Definition: zic.c:3087
#define LP_TIME
Definition: zic.c:255
static zic_t gethms(const char *string, const char *errstring, bool)
Definition: zic.c:1254
static zic_t const max_time
Definition: zic.c:967
#define NULL
Definition: c.h:226
static struct lookup const * byword(const char *string, const struct lookup *lp)
Definition: zic.c:3358
#define TM_JANUARY
Definition: tzfile.h:121
static zic_t leapminyear
Definition: zic.c:170
#define LP_YEAR
Definition: zic.c:252
int i
static struct lookup const leap_types[]
Definition: zic.c:356
#define EPOCH_YEAR
Definition: tzfile.h:136
static const int len_years[2]
Definition: zic.c:367
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
static zic_t const min_time
Definition: zic.c:966
#define LP_MONTH
Definition: zic.c:253
#define _(x)
Definition: elog.c:84
static zic_t oadd(zic_t t1, zic_t t2)
Definition: zic.c:3436
static void inlink ( char **  fields,
int  nfields 
)
static

Definition at line 1613 of file zic.c.

References _, ecpyalloc(), error(), filename, growalloc(), link::l_filename, link::l_from, link::l_linenum, link::l_to, LF_FROM, LF_TO, linenum, LINK_FIELDS, and namecheck().

Referenced by infile().

1614 {
1615  struct link l;
1616 
1617  if (nfields != LINK_FIELDS)
1618  {
1619  error(_("wrong number of fields on Link line"));
1620  return;
1621  }
1622  if (*fields[LF_FROM] == '\0')
1623  {
1624  error(_("blank FROM field on Link line"));
1625  return;
1626  }
1627  if (!namecheck(fields[LF_TO]))
1628  return;
1629  l.l_filename = filename;
1630  l.l_linenum = linenum;
1631  l.l_from = ecpyalloc(fields[LF_FROM]);
1632  l.l_to = ecpyalloc(fields[LF_TO]);
1633  links = growalloc(links, sizeof *links, nlinks, &nlinks_alloc);
1634  links[nlinks++] = l;
1635 }
static ptrdiff_t nlinks
Definition: zic.c:285
static char * ecpyalloc(char const *str)
Definition: zic.c:427
#define LF_TO
Definition: zic.c:245
static const char * filename
Definition: zic.c:167
static lineno_t linenum
Definition: zic.c:172
static void * growalloc(void *ptr, size_t itemsize, ptrdiff_t nitems, ptrdiff_t *nitems_alloc)
Definition: zic.c:433
static ptrdiff_t nlinks_alloc
Definition: zic.c:286
#define LF_FROM
Definition: zic.c:244
static struct link * links
Definition: zic.c:284
#define LINK_FIELDS
Definition: zic.c:246
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
#define _(x)
Definition: elog.c:84
static bool namecheck(const char *name)
Definition: zic.c:768
static void inrule ( char **  fields,
int  nfields 
)
static

Definition at line 1307 of file zic.c.

References _, ecpyalloc(), error(), filename, gethms(), growalloc(), linenum, rule::r_abbrvar, rule::r_filename, rule::r_linenum, rule::r_name, rule::r_stdoff, RF_ABBRVAR, RF_COMMAND, RF_DAY, RF_HIYEAR, RF_LOYEAR, RF_MONTH, RF_NAME, RF_STDOFF, RF_TOD, RULE_FIELDS, and rulesub().

Referenced by infile().

1308 {
1309  static struct rule r;
1310 
1311  if (nfields != RULE_FIELDS)
1312  {
1313  error(_("wrong number of fields on Rule line"));
1314  return;
1315  }
1316  if (*fields[RF_NAME] == '\0')
1317  {
1318  error(_("nameless rule"));
1319  return;
1320  }
1321  r.r_filename = filename;
1322  r.r_linenum = linenum;
1323  r.r_stdoff = gethms(fields[RF_STDOFF], _("invalid saved time"), true);
1324  rulesub(&r, fields[RF_LOYEAR], fields[RF_HIYEAR], fields[RF_COMMAND],
1325  fields[RF_MONTH], fields[RF_DAY], fields[RF_TOD]);
1326  r.r_name = ecpyalloc(fields[RF_NAME]);
1327  r.r_abbrvar = ecpyalloc(fields[RF_ABBRVAR]);
1328  if (max_abbrvar_len < strlen(r.r_abbrvar))
1329  max_abbrvar_len = strlen(r.r_abbrvar);
1330  rules = growalloc(rules, sizeof *rules, nrules, &nrules_alloc);
1331  rules[nrules++] = r;
1332 }
static char * ecpyalloc(char const *str)
Definition: zic.c:427
#define RF_COMMAND
Definition: zic.c:232
Definition: localtime.c:74
static const char * filename
Definition: zic.c:167
static lineno_t linenum
Definition: zic.c:172
static int max_abbrvar_len
Definition: zic.c:173
static struct rule * rules
Definition: zic.c:268
static void * growalloc(void *ptr, size_t itemsize, ptrdiff_t nitems, ptrdiff_t *nitems_alloc)
Definition: zic.c:433
static zic_t gethms(const char *string, const char *errstring, bool)
Definition: zic.c:1254
#define RF_HIYEAR
Definition: zic.c:231
#define RF_NAME
Definition: zic.c:229
static ptrdiff_t nrules_alloc
Definition: zic.c:270
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:1638
static ptrdiff_t nrules
Definition: zic.c:269
#define RF_TOD
Definition: zic.c:235
#define RF_ABBRVAR
Definition: zic.c:237
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
#define RF_LOYEAR
Definition: zic.c:230
#define _(x)
Definition: elog.c:84
#define RULE_FIELDS
Definition: zic.c:238
#define RF_MONTH
Definition: zic.c:233
#define RF_STDOFF
Definition: zic.c:236
#define RF_DAY
Definition: zic.c:234
static bool inzcont ( char **  fields,
int  nfields 
)
static

Definition at line 1373 of file zic.c.

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

Referenced by infile().

1374 {
1375  if (nfields < ZONEC_MINFIELDS || nfields > ZONEC_MAXFIELDS)
1376  {
1377  error(_("wrong number of fields on Zone continuation line"));
1378  return false;
1379  }
1380  return inzsub(fields, nfields, true);
1381 }
#define ZONEC_MAXFIELDS
Definition: zic.c:223
static bool inzsub(char **, int, bool)
Definition: zic.c:1384
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
#define _(x)
Definition: elog.c:84
static bool inzone ( char **  fields,
int  nfields 
)
static

Definition at line 1335 of file zic.c.

References _, error(), i, inzsub(), NULL, nzones, PRIdLINENO, TZDEFAULT, TZDEFRULES, ZF_NAME, and ZONE_MAXFIELDS.

Referenced by infile().

1336 {
1337  ptrdiff_t i;
1338 
1339  if (nfields < ZONE_MINFIELDS || nfields > ZONE_MAXFIELDS)
1340  {
1341  error(_("wrong number of fields on Zone line"));
1342  return false;
1343  }
1344  if (strcmp(fields[ZF_NAME], TZDEFAULT) == 0 && lcltime != NULL)
1345  {
1346  error(
1347  _("\"Zone %s\" line and -l option are mutually exclusive"),
1348  TZDEFAULT);
1349  return false;
1350  }
1351  if (strcmp(fields[ZF_NAME], TZDEFRULES) == 0 && psxrules != NULL)
1352  {
1353  error(
1354  _("\"Zone %s\" line and -p option are mutually exclusive"),
1355  TZDEFRULES);
1356  return false;
1357  }
1358  for (i = 0; i < nzones; ++i)
1359  if (zones[i].z_name != NULL &&
1360  strcmp(zones[i].z_name, fields[ZF_NAME]) == 0)
1361  {
1362  error(_("duplicate zone name %s"
1363  " (file \"%s\", line %" PRIdLINENO ")"),
1364  fields[ZF_NAME],
1365  zones[i].z_filename,
1366  zones[i].z_linenum);
1367  return false;
1368  }
1369  return inzsub(fields, nfields, false);
1370 }
#define TZDEFAULT
Definition: tzfile.h:24
#define PRIdLINENO
Definition: zic.c:52
#define ZF_NAME
Definition: zic.c:200
static ptrdiff_t nzones
Definition: zic.c:273
static const char * psxrules
Definition: zic.c:560
static bool inzsub(char **, int, bool)
Definition: zic.c:1384
#define ZONE_MAXFIELDS
Definition: zic.c:209
static const char * lcltime
Definition: zic.c:561
#define NULL
Definition: c.h:226
#define TZDEFRULES
Definition: tzfile.h:25
static struct zone * zones
Definition: zic.c:272
int i
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
#define _(x)
Definition: elog.c:84
static bool inzsub ( char **  fields,
int  nfields,
bool  iscont 
)
static

Definition at line 1384 of file zic.c.

References _, ecpyalloc(), error(), filename, gethms(), growalloc(), linenum, namecheck(), NULL, rule::r_filename, rule::r_linenum, rule::r_loyear, rpytime(), rulesub(), warning(), zone::z_filename, zone::z_format, zone::z_format_specifier, zone::z_gmtoff, zone::z_linenum, zone::z_name, zone::z_rule, zone::z_untilrule, zone::z_untiltime, ZF_FORMAT, ZF_GMTOFF, ZF_NAME, ZF_RULE, ZF_TILDAY, ZF_TILMONTH, ZF_TILTIME, ZF_TILYEAR, ZFC_FORMAT, ZFC_GMTOFF, ZFC_RULE, ZFC_TILDAY, ZFC_TILMONTH, ZFC_TILTIME, and ZFC_TILYEAR.

Referenced by inzcont(), and inzone().

1385 {
1386  char *cp;
1387  char *cp1;
1388  static struct zone z;
1389  int i_gmtoff,
1390  i_rule,
1391  i_format;
1392  int i_untilyear,
1393  i_untilmonth;
1394  int i_untilday,
1395  i_untiltime;
1396  bool hasuntil;
1397 
1398  if (iscont)
1399  {
1400  i_gmtoff = ZFC_GMTOFF;
1401  i_rule = ZFC_RULE;
1402  i_format = ZFC_FORMAT;
1403  i_untilyear = ZFC_TILYEAR;
1404  i_untilmonth = ZFC_TILMONTH;
1405  i_untilday = ZFC_TILDAY;
1406  i_untiltime = ZFC_TILTIME;
1407  z.z_name = NULL;
1408  }
1409  else if (!namecheck(fields[ZF_NAME]))
1410  return false;
1411  else
1412  {
1413  i_gmtoff = ZF_GMTOFF;
1414  i_rule = ZF_RULE;
1415  i_format = ZF_FORMAT;
1416  i_untilyear = ZF_TILYEAR;
1417  i_untilmonth = ZF_TILMONTH;
1418  i_untilday = ZF_TILDAY;
1419  i_untiltime = ZF_TILTIME;
1420  z.z_name = ecpyalloc(fields[ZF_NAME]);
1421  }
1422  z.z_filename = filename;
1423  z.z_linenum = linenum;
1424  z.z_gmtoff = gethms(fields[i_gmtoff], _("invalid UT offset"), true);
1425  if ((cp = strchr(fields[i_format], '%')) != NULL)
1426  {
1427  if ((*++cp != 's' && *cp != 'z') || strchr(cp, '%')
1428  || strchr(fields[i_format], '/'))
1429  {
1430  error(_("invalid abbreviation format"));
1431  return false;
1432  }
1433  }
1434  z.z_rule = ecpyalloc(fields[i_rule]);
1435  z.z_format = cp1 = ecpyalloc(fields[i_format]);
1436  z.z_format_specifier = cp ? *cp : '\0';
1437  if (z.z_format_specifier == 'z')
1438  {
1439  if (noise)
1440  warning(_("format '%s' not handled by pre-2015 versions of zic"),
1441  z.z_format);
1442  cp1[cp - fields[i_format]] = 's';
1443  }
1444  if (max_format_len < strlen(z.z_format))
1445  max_format_len = strlen(z.z_format);
1446  hasuntil = nfields > i_untilyear;
1447  if (hasuntil)
1448  {
1449  z.z_untilrule.r_filename = filename;
1450  z.z_untilrule.r_linenum = linenum;
1451  rulesub(&z.z_untilrule,
1452  fields[i_untilyear],
1453  "only",
1454  "",
1455  (nfields > i_untilmonth) ?
1456  fields[i_untilmonth] : "Jan",
1457  (nfields > i_untilday) ? fields[i_untilday] : "1",
1458  (nfields > i_untiltime) ? fields[i_untiltime] : "0");
1459  z.z_untiltime = rpytime(&z.z_untilrule,
1460  z.z_untilrule.r_loyear);
1461  if (iscont && nzones > 0 &&
1462  z.z_untiltime > min_time &&
1463  z.z_untiltime < max_time &&
1464  zones[nzones - 1].z_untiltime > min_time &&
1465  zones[nzones - 1].z_untiltime < max_time &&
1466  zones[nzones - 1].z_untiltime >= z.z_untiltime)
1467  {
1468  error(_("Zone continuation line end time is not after end time of previous line"));
1469  return false;
1470  }
1471  }
1472  zones = growalloc(zones, sizeof *zones, nzones, &nzones_alloc);
1473  zones[nzones++] = z;
1474 
1475  /*
1476  * If there was an UNTIL field on this line, there's more information
1477  * about the zone on the next line.
1478  */
1479  return hasuntil;
1480 }
#define ZF_TILMONTH
Definition: zic.c:205
#define ZF_TILTIME
Definition: zic.c:207
#define ZF_TILYEAR
Definition: zic.c:204
#define ZF_NAME
Definition: zic.c:200
#define ZFC_TILMONTH
Definition: zic.c:219
static char * ecpyalloc(char const *str)
Definition: zic.c:427
#define ZF_RULE
Definition: zic.c:202
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:495
zic_t z_untiltime
Definition: zic.c:108
static ptrdiff_t nzones
Definition: zic.c:273
#define ZF_GMTOFF
Definition: zic.c:201
#define ZFC_FORMAT
Definition: zic.c:217
static int max_format_len
Definition: zic.c:174
static const char * filename
Definition: zic.c:167
#define ZF_FORMAT
Definition: zic.c:203
static lineno_t linenum
Definition: zic.c:172
static ptrdiff_t nzones_alloc
Definition: zic.c:274
#define ZFC_TILTIME
Definition: zic.c:221
static void * growalloc(void *ptr, size_t itemsize, ptrdiff_t nitems, ptrdiff_t *nitems_alloc)
Definition: zic.c:433
#define ZFC_RULE
Definition: zic.c:216
static zic_t rpytime(const struct rule *rp, zic_t wantedy)
Definition: zic.c:3473
static zic_t gethms(const char *string, const char *errstring, bool)
Definition: zic.c:1254
#define ZF_TILDAY
Definition: zic.c:206
static zic_t const max_time
Definition: zic.c:967
static bool noise
Definition: zic.c:177
#define NULL
Definition: c.h:226
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:1638
static struct zone * zones
Definition: zic.c:272
Definition: zic.c:91
#define ZFC_TILDAY
Definition: zic.c:220
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
static zic_t const min_time
Definition: zic.c:966
#define ZFC_TILYEAR
Definition: zic.c:218
#define _(x)
Definition: elog.c:84
#define ZFC_GMTOFF
Definition: zic.c:215
static bool namecheck(const char *name)
Definition: zic.c:768
static bool is32 ( const zic_t  x)
static

Definition at line 1860 of file zic.c.

Referenced by writezone().

1861 {
1862  return x == ((zic_t) ((int32) x));
1863 }
signed int int32
Definition: c.h:253
int64 zic_t
Definition: zic.c:25
static bool is_alpha ( char  a)
static

Definition at line 3206 of file zic.c.

Referenced by doabbr(), mkdirs(), and newabbr().

3207 {
3208  switch (a)
3209  {
3210  default:
3211  return false;
3212  case 'A':
3213  case 'B':
3214  case 'C':
3215  case 'D':
3216  case 'E':
3217  case 'F':
3218  case 'G':
3219  case 'H':
3220  case 'I':
3221  case 'J':
3222  case 'K':
3223  case 'L':
3224  case 'M':
3225  case 'N':
3226  case 'O':
3227  case 'P':
3228  case 'Q':
3229  case 'R':
3230  case 'S':
3231  case 'T':
3232  case 'U':
3233  case 'V':
3234  case 'W':
3235  case 'X':
3236  case 'Y':
3237  case 'Z':
3238  case 'a':
3239  case 'b':
3240  case 'c':
3241  case 'd':
3242  case 'e':
3243  case 'f':
3244  case 'g':
3245  case 'h':
3246  case 'i':
3247  case 'j':
3248  case 'k':
3249  case 'l':
3250  case 'm':
3251  case 'n':
3252  case 'o':
3253  case 'p':
3254  case 'q':
3255  case 'r':
3256  case 's':
3257  case 't':
3258  case 'u':
3259  case 'v':
3260  case 'w':
3261  case 'x':
3262  case 'y':
3263  case 'z':
3264  return true;
3265  }
3266 }
static bool is_space ( char  a)
static

Definition at line 3188 of file zic.c.

Referenced by getfields().

3189 {
3190  switch (a)
3191  {
3192  default:
3193  return false;
3194  case ' ':
3195  case '\f':
3196  case '\n':
3197  case '\r':
3198  case '\t':
3199  case '\v':
3200  return true;
3201  }
3202 }
static bool itsabbr ( const char *  abbr,
const char *  word 
)
static

Definition at line 3343 of file zic.c.

References lowerit(), and word().

Referenced by byword().

3344 {
3345  if (lowerit(*abbr) != lowerit(*word))
3346  return false;
3347  ++word;
3348  while (*++abbr != '\0')
3349  do
3350  {
3351  if (*word == '\0')
3352  return false;
3353  } while (lowerit(*word++) != lowerit(*abbr));
3354  return true;
3355 }
static char lowerit(char)
Definition: zic.c:3271
static void word(struct vars *, int, struct state *, struct state *)
Definition: regcomp.c:1245
static bool itsdir ( char const *  name)
static

Definition at line 1013 of file zic.c.

References emalloc(), EOVERFLOW, and free.

Referenced by dolink(), and mkdirs().

1014 {
1015  struct stat st;
1016  int res = stat(name, &st);
1017 #ifdef S_ISDIR
1018  if (res == 0)
1019  return S_ISDIR(st.st_mode) != 0;
1020 #endif
1021  if (res == 0 || errno == EOVERFLOW)
1022  {
1023  size_t n = strlen(name);
1024  char *nameslashdot = emalloc(n + 3);
1025  bool dir;
1026 
1027  memcpy(nameslashdot, name, n);
1028  strcpy(&nameslashdot[n], &"/."[!(n && name[n - 1] != '/')]);
1029  dir = stat(nameslashdot, &st) == 0 || errno == EOVERFLOW;
1030  free(nameslashdot);
1031  return dir;
1032  }
1033  return false;
1034 }
#define free(a)
Definition: header.h:60
const char * name
Definition: encode.c:521
#define EOVERFLOW
Definition: private.h:38
static void * emalloc(size_t size)
Definition: zic.c:415
static bool itssymlink ( char const *  name)
static

Definition at line 1038 of file zic.c.

Referenced by dolink().

1039 {
1040 #ifdef HAVE_SYMLINK
1041  char c;
1042 
1043  return 0 <= readlink(name, &c, 1);
1044 #else
1045  return false;
1046 #endif
1047 }
char * c
const char * name
Definition: encode.c:521
static void leapadd ( zic_t  t,
bool  positive,
int  rolling,
int  count 
)
static

Definition at line 3087 of file zic.c.

References _, error(), EXIT_FAILURE, i, leapcnt, and TZ_MAX_LEAPS.

Referenced by inleap().

3088 {
3089  int i,
3090  j;
3091 
3092  if (leapcnt + (positive ? count : 1) > TZ_MAX_LEAPS)
3093  {
3094  error(_("too many leap seconds"));
3095  exit(EXIT_FAILURE);
3096  }
3097  for (i = 0; i < leapcnt; ++i)
3098  if (t <= trans[i])
3099  {
3100  if (t == trans[i])
3101  {
3102  error(_("repeated leap second moment"));
3103  exit(EXIT_FAILURE);
3104  }
3105  break;
3106  }
3107  do
3108  {
3109  for (j = leapcnt; j > i; --j)
3110  {
3111  trans[j] = trans[j - 1];
3112  corr[j] = corr[j - 1];
3113  roll[j] = roll[j - 1];
3114  }
3115  trans[i] = t;
3116  corr[i] = positive ? 1 : -count;
3117  roll[i] = rolling;
3118  ++leapcnt;
3119  } while (positive && --count != 0);
3120 }
static zic_t corr[TZ_MAX_LEAPS]
Definition: zic.c:384
#define TZ_MAX_LEAPS
Definition: tzfile.h:101
static int leapcnt
Definition: zic.c:168
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:383
int i
#define EXIT_FAILURE
Definition: settings.h:150
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
#define _(x)
Definition: elog.c:84
static char roll[TZ_MAX_LEAPS]
Definition: zic.c:385
int link ( const char *  fromname,
const char *  toname 
)
static char lowerit ( char  a)
static

Definition at line 3271 of file zic.c.

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

3272 {
3273  switch (a)
3274  {
3275  default:
3276  return a;
3277  case 'A':
3278  return 'a';
3279  case 'B':
3280  return 'b';
3281  case 'C':
3282  return 'c';
3283  case 'D':
3284  return 'd';
3285  case 'E':
3286  return 'e';
3287  case 'F':
3288  return 'f';
3289  case 'G':
3290  return 'g';
3291  case 'H':
3292  return 'h';
3293  case 'I':
3294  return 'i';
3295  case 'J':
3296  return 'j';
3297  case 'K':
3298  return 'k';
3299  case 'L':
3300  return 'l';
3301  case 'M':
3302  return 'm';
3303  case 'N':
3304  return 'n';
3305  case 'O':
3306  return 'o';
3307  case 'P':
3308  return 'p';
3309  case 'Q':
3310  return 'q';
3311  case 'R':
3312  return 'r';
3313  case 'S':
3314  return 's';
3315  case 'T':
3316  return 't';
3317  case 'U':
3318  return 'u';
3319  case 'V':
3320  return 'v';
3321  case 'W':
3322  return 'w';
3323  case 'X':
3324  return 'x';
3325  case 'Y':
3326  return 'y';
3327  case 'Z':
3328  return 'z';
3329  }
3330 }
int main ( int  argc,
char *  argv[] 
)

Definition at line 567 of file zic.c.

References _, adjleap(), associate(), change_directory(), close_file(), dolink(), eat(), EXIT_FAILURE, EXIT_SUCCESS, getopt(), i, infile(), nlinks, NULL, nzones, optarg, optind, outzone(), S_IWGRP, S_IWOTH, TYPE_BIT, TZDEFAULT, TZDEFRULES, usage(), warning(), and zone::z_name.

568 {
569  int c,
570  k;
571  ptrdiff_t i,
572  j;
573 
574 #ifndef WIN32
575  umask(umask(S_IWGRP | S_IWOTH) | (S_IWGRP | S_IWOTH));
576 #endif /* !WIN32 */
577  progname = argv[0];
578  if (TYPE_BIT(zic_t) <64)
579  {
580  fprintf(stderr, "%s: %s\n", progname,
581  _("wild compilation-time specification of zic_t"));
582  return EXIT_FAILURE;
583  }
584  for (k = 1; k < argc; k++)
585  if (strcmp(argv[k], "--version") == 0)
586  {
587  printf("zic %s\n", PG_VERSION);
588  close_file(stdout, NULL, NULL);
589  return EXIT_SUCCESS;
590  }
591  else if (strcmp(argv[k], "--help") == 0)
592  {
593  usage(stdout, EXIT_SUCCESS);
594  }
595  while ((c = getopt(argc, argv, "d:l:p:L:vPsy:")) != EOF && c != -1)
596  switch (c)
597  {
598  default:
599  usage(stderr, EXIT_FAILURE);
600  case 'd':
601  if (directory == NULL)
602  directory = strdup(optarg);
603  else
604  {
605  fprintf(stderr,
606  _("%s: More than one -d option specified\n"),
607  progname);
608  return EXIT_FAILURE;
609  }
610  break;
611  case 'l':
612  if (lcltime == NULL)
613  lcltime = strdup(optarg);
614  else
615  {
616  fprintf(stderr,
617  _("%s: More than one -l option specified\n"),
618  progname);
619  return EXIT_FAILURE;
620  }
621  break;
622  case 'p':
623  if (psxrules == NULL)
624  psxrules = strdup(optarg);
625  else
626  {
627  fprintf(stderr,
628  _("%s: More than one -p option specified\n"),
629  progname);
630  return EXIT_FAILURE;
631  }
632  break;
633  case 'y':
634  if (yitcommand == NULL)
635  yitcommand = strdup(optarg);
636  else
637  {
638  fprintf(stderr,
639  _("%s: More than one -y option specified\n"),
640  progname);
641  return EXIT_FAILURE;
642  }
643  break;
644  case 'L':
645  if (leapsec == NULL)
646  leapsec = strdup(optarg);
647  else
648  {
649  fprintf(stderr,
650  _("%s: More than one -L option specified\n"),
651  progname);
652  return EXIT_FAILURE;
653  }
654  break;
655  case 'v':
656  noise = true;
657  break;
658  case 'P':
659  print_abbrevs = true;
660  print_cutoff = time(NULL);
661  break;
662  case 's':
663  warning(_("-s ignored"));
664  break;
665  }
666  if (optind == argc - 1 && strcmp(argv[optind], "=") == 0)
667  usage(stderr, EXIT_FAILURE); /* usage message by request */
668  if (directory == NULL)
669  directory = "data";
670  if (yitcommand == NULL)
671  yitcommand = "yearistype";
672 
673  if (optind < argc && leapsec != NULL)
674  {
675  infile(leapsec);
676  adjleap();
677  }
678 
679  for (k = optind; k < argc; k++)
680  infile(argv[k]);
681  if (errors)
682  return EXIT_FAILURE;
683  associate();
685  for (i = 0; i < nzones; i = j)
686  {
687  /*
688  * Find the next non-continuation zone entry.
689  */
690  for (j = i + 1; j < nzones && zones[j].z_name == NULL; ++j)
691  continue;
692  outzone(&zones[i], j - i);
693  }
694 
695  /*
696  * Make links.
697  */
698  for (i = 0; i < nlinks; ++i)
699  {
700  eat(links[i].l_filename, links[i].l_linenum);
701  dolink(links[i].l_from, links[i].l_to, false);
702  if (noise)
703  for (j = 0; j < nlinks; ++j)
704  if (strcmp(links[i].l_to,
705  links[j].l_from) == 0)
706  warning(_("link to link"));
707  }
708  if (lcltime != NULL)
709  {
710  eat(_("command line"), 1);
711  dolink(lcltime, TZDEFAULT, true);
712  }
713  if (psxrules != NULL)
714  {
715  eat(_("command line"), 1);
716  dolink(psxrules, TZDEFRULES, true);
717  }
718  if (warnings && (ferror(stderr) || fclose(stderr) != 0))
719  return EXIT_FAILURE;
720  return errors ? EXIT_FAILURE : EXIT_SUCCESS;
721 }
#define TZDEFAULT
Definition: tzfile.h:24
static ptrdiff_t nlinks
Definition: zic.c:285
static bool print_abbrevs
Definition: zic.c:178
static zic_t print_cutoff
Definition: zic.c:179
static void change_directory(char const *dir)
Definition: zic.c:540
#define EXIT_SUCCESS
Definition: settings.h:146
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:495
static bool errors
Definition: zic.c:165
static void associate(void)
Definition: zic.c:1065
static ptrdiff_t nzones
Definition: zic.c:273
static const char * yitcommand
Definition: zic.c:564
static bool warnings
Definition: zic.c:166
static const char * leapsec
Definition: zic.c:563
int getopt(int nargc, char *const *nargv, const char *ostr)
Definition: getopt.c:72
static const char * psxrules
Definition: zic.c:560
static void static void static void static void usage(FILE *stream, int status) pg_attribute_noreturn()
Definition: zic.c:523
static void dolink(const char *, const char *, bool)
Definition: zic.c:869
int optind
Definition: getopt.c:51
#define S_IWGRP
Definition: win32.h:478
char * c
static void adjleap(void)
Definition: zic.c:3123
static const char * lcltime
Definition: zic.c:561
int64 zic_t
Definition: zic.c:25
#define S_IWOTH
Definition: win32.h:482
static void eat(char const *name, lineno_t num)
Definition: zic.c:462
static bool noise
Definition: zic.c:177
static struct link * links
Definition: zic.c:284
static void infile(const char *filename)
Definition: zic.c:1151
static const char * progname
Definition: zic.c:182
#define NULL
Definition: c.h:226
#define TZDEFRULES
Definition: tzfile.h:25
static const char * directory
Definition: zic.c:562
const char * z_name
Definition: zic.c:96
static void close_file(FILE *stream, char const *dir, char const *name)
Definition: zic.c:507
static struct zone * zones
Definition: zic.c:272
static void outzone(const struct zone *zp, ptrdiff_t ntzones)
Definition: zic.c:2648
char * optarg
Definition: getopt.c:53
#define TYPE_BIT(type)
Definition: private.h:71
int i
#define EXIT_FAILURE
Definition: settings.h:150
#define _(x)
Definition: elog.c:84
static void* memcheck ( void *  ptr)
static

Definition at line 407 of file zic.c.

References memory_exhausted(), NULL, and strerror().

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

408 {
409  if (ptr == NULL)
410  memory_exhausted(strerror(errno));
411  return ptr;
412 }
#define NULL
Definition: c.h:226
const char * strerror(int errnum)
Definition: strerror.c:19
static void memory_exhausted(const char *msg) pg_attribute_noreturn()
Definition: zic.c:392
static void memory_exhausted ( const char *  msg)
static

Definition at line 392 of file zic.c.

References _, and EXIT_FAILURE.

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

393 {
394  fprintf(stderr, _("%s: Memory exhausted: %s\n"), progname, msg);
395  exit(EXIT_FAILURE);
396 }
static const char * progname
Definition: zic.c:182
#define EXIT_FAILURE
Definition: settings.h:150
#define _(x)
Definition: elog.c:84
static void mkdirs ( char const *  argname,
bool  ancestors 
)
static

Definition at line 3609 of file zic.c.

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

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

3610 {
3611  char *name;
3612  char *cp;
3613 
3614  cp = name = ecpyalloc(argname);
3615 
3616  /* Do not mkdir a root directory, as it must exist. */
3617 #ifdef WIN32
3618  if (is_alpha(name[0]) && name[1] == ':')
3619  cp += 2;
3620 #endif
3621  while (*cp == '/')
3622  cp++;
3623 
3624  while (cp && ((cp = strchr(cp, '/')) || !ancestors))
3625  {
3626  if (cp)
3627  *cp = '\0';
3628 
3629  /*
3630  * Try to create it. It's OK if creation fails because the directory
3631  * already exists, perhaps because some other process just created it.
3632  * For simplicity do not check first whether it already exists, as
3633  * that is checked anyway if the mkdir fails.
3634  */
3635  if (mkdir(name, MKDIR_UMASK) != 0)
3636  {
3637  /*
3638  * For speed, skip itsdir if errno == EEXIST. Since mkdirs is
3639  * called only after open fails with ENOENT on a subfile, EEXIST
3640  * implies itsdir here.
3641  */
3642  int err = errno;
3643 
3644  if (err != EEXIST && !itsdir(name))
3645  {
3646  error(_("%s: Cannot create directory %s: %s"),
3647  progname, name, strerror(err));
3648  exit(EXIT_FAILURE);
3649  }
3650  }
3651  if (cp)
3652  *cp++ = '/';
3653  }
3654  free(name);
3655 }
static char * ecpyalloc(char const *str)
Definition: zic.c:427
#define mkdir(a, b)
Definition: win32.h:65
static bool itsdir(char const *)
Definition: zic.c:1013
static bool is_alpha(char a)
Definition: zic.c:3206
static const char * progname
Definition: zic.c:182
#define free(a)
Definition: header.h:60
#define MKDIR_UMASK
Definition: zic.c:37
const char * name
Definition: encode.c:521
const char * strerror(int errnum)
Definition: strerror.c:19
#define EXIT_FAILURE
Definition: settings.h:150
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
#define _(x)
Definition: elog.c:84
static bool namecheck ( const char *  name)
static

Definition at line 768 of file zic.c.

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

Referenced by inlink(), and inzsub().

769 {
770  char const *cp;
771 
772  /* Benign characters in a portable file name. */
773  static char const benign[] =
774  "-/_"
775  "abcdefghijklmnopqrstuvwxyz"
776  "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
777 
778  /*
779  * Non-control chars in the POSIX portable character set, excluding the
780  * benign characters.
781  */
782  static char const printable_and_not_benign[] =
783  " !\"#$%&'()*+,.0123456789:;<=>?@[\\]^`{|}~";
784 
785  char const *component = name;
786 
787  for (cp = name; *cp; cp++)
788  {
789  unsigned char c = *cp;
790 
791  if (noise && !strchr(benign, c))
792  {
793  warning((strchr(printable_and_not_benign, c)
794  ? _("file name '%s' contains byte '%c'")
795  : _("file name '%s' contains byte '\\%o'")),
796  name, c);
797  }
798  if (c == '/')
799  {
800  if (!componentcheck(name, component, cp))
801  return false;
802  component = cp + 1;
803  }
804  }
805  return componentcheck(name, component, cp);
806 }
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:495
static bool componentcheck(char const *name, char const *component, char const *component_end)
Definition: zic.c:724
char * c
static bool noise
Definition: zic.c:177
const char * name
Definition: encode.c:521
#define _(x)
Definition: elog.c:84
static void newabbr ( const char *  abbr)
static

Definition at line 3571 of file zic.c.

References _, error(), EXIT_FAILURE, GRANDPARENTED, i, is_alpha(), NULL, TZ_MAX_CHARS, warning(), and ZIC_MAX_ABBR_LEN_WO_WARN.

Referenced by addtype().

3572 {
3573  int i;
3574 
3575  if (strcmp(string, GRANDPARENTED) != 0)
3576  {
3577  const char *cp;
3578  const char *mp;
3579 
3580  cp = string;
3581  mp = NULL;
3582  while (is_alpha(*cp) || ('0' <= *cp && *cp <= '9')
3583  || *cp == '-' || *cp == '+')
3584  ++cp;
3585  if (noise && cp - string < 3)
3586  mp = _("time zone abbreviation has fewer than 3 characters");
3587  if (cp - string > ZIC_MAX_ABBR_LEN_WO_WARN)
3588  mp = _("time zone abbreviation has too many characters");
3589  if (*cp != '\0')
3590  mp = _("time zone abbreviation differs from POSIX standard");
3591  if (mp != NULL)
3592  warning("%s (%s)", mp, string);
3593  }
3594  i = strlen(string) + 1;
3595  if (charcnt + i > TZ_MAX_CHARS)
3596  {
3597  error(_("too many, or too long, time zone abbreviations"));
3598  exit(EXIT_FAILURE);
3599  }
3600  strcpy(&chars[charcnt], string);
3601  charcnt += i;
3602 }
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:495
#define GRANDPARENTED
Definition: private.h:27
static bool is_alpha(char a)
Definition: zic.c:3206
char string[11]
Definition: preproc-type.c:46
#define ZIC_MAX_ABBR_LEN_WO_WARN
Definition: zic.c:30
#define TZ_MAX_CHARS
Definition: tzfile.h:98
static bool noise
Definition: zic.c:177
#define NULL
Definition: c.h:226
static int charcnt
Definition: zic.c:164
int i
#define EXIT_FAILURE
Definition: settings.h:150
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
static char chars[TZ_MAX_CHARS]
Definition: zic.c:382
#define _(x)
Definition: elog.c:84
static zic_t oadd ( zic_t  t1,
zic_t  t2 
)
static

Definition at line 3436 of file zic.c.

References time_overflow(), ZIC_MAX, and ZIC_MIN.

Referenced by gethms(), inleap(), outzone(), and rpytime().

3437 {
3438  if (t1 < 0 ? t2 < ZIC_MIN - t1 : ZIC_MAX - t1 < t2)
3439  time_overflow();
3440  return t1 + t2;
3441 }
#define ZIC_MAX
Definition: zic.c:27
#define ZIC_MIN
Definition: zic.c:26
static void time_overflow(void)
Definition: zic.c:3429
static void outzone ( const struct zone zp,
ptrdiff_t  ntzones 
)
static

Definition at line 2648 of file zic.c.

References _, addtt(), addtype(), attype::at, attypes, compat, DC_DOM, doabbr(), attype::dontmerge, eat(), eats(), emalloc(), EPOCH_YEAR, error(), free, i, INITIALIZE, max_abbrvar_len, max_year, NULL, oadd(), rule::r_abbrvar, rule::r_dayofmonth, rule::r_dycode, rule::r_filename, rule::r_hiwasnum, rule::r_hiyear, rule::r_linenum, rule::r_lowasnum, rule::r_loyear, rule::r_month, rule::r_stdoff, rule::r_temp, rule::r_tod, rule::r_todisgmt, rule::r_todisstd, rule::r_todo, rule::r_yrtype, rpytime(), stringzone(), tadd(), timecnt, TM_JANUARY, updateminmax(), warning(), writezone(), YEAR_BY_YEAR_ZONE, yearistype(), YEARSPERREPEAT, zone::z_filename, zone::z_format, zone::z_gmtoff, zone::z_linenum, zone::z_name, zone::z_nrules, zone::z_rules, zone::z_stdoff, zone::z_untilrule, zone::z_untiltime, ZIC_MAX, ZIC_MIN, ZIC_VERSION, and ZIC_VERSION_PRE_2013.

Referenced by main().

2649 {
2650  const struct zone *zp;
2651  struct rule *rp;
2652  ptrdiff_t i,
2653  j;
2654  bool usestart,
2655  useuntil;
2656  zic_t starttime,
2657  untiltime;
2658  zic_t gmtoff;
2659  zic_t stdoff;
2660  zic_t year;
2661  zic_t startoff;
2662  bool startttisstd;
2663  bool startttisgmt;
2664  int type;
2665  char *startbuf;
2666  char *ab;
2667  char *envvar;
2668  int max_abbr_len;
2669  int max_envvar_len;
2670  bool prodstic; /* all rules are min to max */
2671  int compat;
2672  bool do_extend;
2673  char version;
2674  ptrdiff_t lastatmax = -1;
2675 
2676  max_abbr_len = 2 + max_format_len + max_abbrvar_len;
2677  max_envvar_len = 2 * max_abbr_len + 5 * 9;
2678  startbuf = emalloc(max_abbr_len + 1);
2679  ab = emalloc(max_abbr_len + 1);
2680  envvar = emalloc(max_envvar_len + 1);
2681  INITIALIZE(untiltime);
2682  INITIALIZE(starttime);
2683 
2684  /*
2685  * Now. . .finally. . .generate some useful data!
2686  */
2687  timecnt = 0;
2688  typecnt = 0;
2689  charcnt = 0;
2690  prodstic = zonecount == 1;
2691 
2692  /*
2693  * Thanks to Earl Chew for noting the need to unconditionally initialize
2694  * startttisstd.
2695  */
2696  startttisstd = false;
2697  startttisgmt = false;
2699  if (leapseen)
2700  {
2703  }
2704  for (i = 0; i < zonecount; ++i)
2705  {
2706  zp = &zpfirst[i];
2707  if (i < zonecount - 1)
2709  for (j = 0; j < zp->z_nrules; ++j)
2710  {
2711  rp = &zp->z_rules[j];
2712  if (rp->r_lowasnum)
2713  updateminmax(rp->r_loyear);
2714  if (rp->r_hiwasnum)
2715  updateminmax(rp->r_hiyear);
2716  if (rp->r_lowasnum || rp->r_hiwasnum)
2717  prodstic = false;
2718  }
2719  }
2720 
2721  /*
2722  * Generate lots of data if a rule can't cover all future times.
2723  */
2724  compat = stringzone(envvar, zpfirst, zonecount);
2725  version = compat < 2013 ? ZIC_VERSION_PRE_2013 : ZIC_VERSION;
2726  do_extend = compat < 0 || compat == YEAR_BY_YEAR_ZONE;
2727  if (noise)
2728  {
2729  if (!*envvar)
2730  warning("%s %s",
2731  _("no POSIX environment variable for zone"),
2732  zpfirst->z_name);
2733  else if (compat != 0 && compat != YEAR_BY_YEAR_ZONE)
2734  {
2735  /*
2736  * Circa-COMPAT clients, and earlier clients, might not work for
2737  * this zone when given dates before 1970 or after 2038.
2738  */
2739  warning(_("%s: pre-%d clients may mishandle"
2740  " distant timestamps"),
2741  zpfirst->z_name, compat);
2742  }
2743  }
2744  if (do_extend)
2745  {
2746  /*
2747  * Search through a couple of extra years past the obvious 400, to
2748  * avoid edge cases. For example, suppose a non-POSIX rule applies
2749  * from 2012 onwards and has transitions in March and September, plus
2750  * some one-off transitions in November 2013. If zic looked only at
2751  * the last 400 years, it would set max_year=2413, with the intent
2752  * that the 400 years 2014 through 2413 will be repeated. The last
2753  * transition listed in the tzfile would be in 2413-09, less than 400
2754  * years after the last one-off transition in 2013-11. Two years
2755  * might be overkill, but with the kind of edge cases available we're
2756  * not sure that one year would suffice.
2757  */
2758  enum
2759  {
2760  years_of_observations = YEARSPERREPEAT + 2};
2761 
2762  if (min_year >= ZIC_MIN + years_of_observations)
2763  min_year -= years_of_observations;
2764  else
2765  min_year = ZIC_MIN;
2766  if (max_year <= ZIC_MAX - years_of_observations)
2767  max_year += years_of_observations;
2768  else
2769  max_year = ZIC_MAX;
2770 
2771  /*
2772  * Regardless of any of the above, for a "proDSTic" zone which
2773  * specifies that its rules always have and always will be in effect,
2774  * we only need one cycle to define the zone.
2775  */
2776  if (prodstic)
2777  {
2778  min_year = 1900;
2779  max_year = min_year + years_of_observations;
2780  }
2781  }
2782 
2783  /*
2784  * For the benefit of older systems, generate data from 1900 through 2037.
2785  */
2786  if (min_year > 1900)
2787  min_year = 1900;
2788  if (max_year < 2037)
2789  max_year = 2037;
2790  for (i = 0; i < zonecount; ++i)
2791  {
2792  /*
2793  * A guess that may well be corrected later.
2794  */
2795  stdoff = 0;
2796  zp = &zpfirst[i];
2797  usestart = i > 0 && (zp - 1)->z_untiltime > early_time;
2798  useuntil = i < (zonecount - 1);
2799  if (useuntil && zp->z_untiltime <= early_time)
2800  continue;
2801  gmtoff = zp->z_gmtoff;
2802  eat(zp->z_filename, zp->z_linenum);
2803  *startbuf = '\0';
2804  startoff = zp->z_gmtoff;
2805  if (zp->z_nrules == 0)
2806  {
2807  stdoff = zp->z_stdoff;
2808  doabbr(startbuf, zp, NULL, stdoff, false);
2809  type = addtype(oadd(zp->z_gmtoff, stdoff),
2810  startbuf, stdoff != 0, startttisstd,
2811  startttisgmt);
2812  if (usestart)
2813  {
2814  addtt(starttime, type);
2815  usestart = false;
2816  }
2817  else
2818  addtt(early_time, type);
2819  }
2820  else
2821  for (year = min_year; year <= max_year; ++year)
2822  {
2823  if (useuntil && year > zp->z_untilrule.r_hiyear)
2824  break;
2825 
2826  /*
2827  * Mark which rules to do in the current year. For those to
2828  * do, calculate rpytime(rp, year);
2829  */
2830  for (j = 0; j < zp->z_nrules; ++j)
2831  {
2832  rp = &zp->z_rules[j];
2833  eats(zp->z_filename, zp->z_linenum,
2834  rp->r_filename, rp->r_linenum);
2835  rp->r_todo = year >= rp->r_loyear &&
2836  year <= rp->r_hiyear &&
2837  yearistype(year, rp->r_yrtype);
2838  if (rp->r_todo)
2839  rp->r_temp = rpytime(rp, year);
2840  }
2841  for (;;)
2842  {
2843  ptrdiff_t k;
2844  zic_t jtime,
2845  ktime = 0;
2846  zic_t offset;
2847 
2848  if (useuntil)
2849  {
2850  /*
2851  * Turn untiltime into UT assuming the current gmtoff
2852  * and stdoff values.
2853  */
2854  untiltime = zp->z_untiltime;
2855  if (!zp->z_untilrule.r_todisgmt)
2856  untiltime = tadd(untiltime,
2857  -gmtoff);
2858  if (!zp->z_untilrule.r_todisstd)
2859  untiltime = tadd(untiltime,
2860  -stdoff);
2861  }
2862 
2863  /*
2864  * Find the rule (of those to do, if any) that takes
2865  * effect earliest in the year.
2866  */
2867  k = -1;
2868  for (j = 0; j < zp->z_nrules; ++j)
2869  {
2870  rp = &zp->z_rules[j];
2871  if (!rp->r_todo)
2872  continue;
2873  eats(zp->z_filename, zp->z_linenum,
2874  rp->r_filename, rp->r_linenum);
2875  offset = rp->r_todisgmt ? 0 : gmtoff;
2876  if (!rp->r_todisstd)
2877  offset = oadd(offset, stdoff);
2878  jtime = rp->r_temp;
2879  if (jtime == min_time ||
2880  jtime == max_time)
2881  continue;
2882  jtime = tadd(jtime, -offset);
2883  if (k < 0 || jtime < ktime)
2884  {
2885  k = j;
2886  ktime = jtime;
2887  }
2888  else if (jtime == ktime)
2889  {
2890  char const *dup_rules_msg =
2891  _("two rules for same instant");
2892 
2893  eats(zp->z_filename, zp->z_linenum,
2894  rp->r_filename, rp->r_linenum);
2895  warning("%s", dup_rules_msg);
2896  rp = &zp->z_rules[k];
2897  eats(zp->z_filename, zp->z_linenum,
2898  rp->r_filename, rp->r_linenum);
2899  error("%s", dup_rules_msg);
2900  }
2901  }
2902  if (k < 0)
2903  break; /* go on to next year */
2904  rp = &zp->z_rules[k];
2905  rp->r_todo = false;
2906  if (useuntil && ktime >= untiltime)
2907  break;
2908  stdoff = rp->r_stdoff;
2909  if (usestart && ktime == starttime)
2910  usestart = false;
2911  if (usestart)
2912  {
2913  if (ktime < starttime)
2914  {
2915  startoff = oadd(zp->z_gmtoff,
2916  stdoff);
2917  doabbr(startbuf, zp,
2918  rp->r_abbrvar,
2919  rp->r_stdoff,
2920  false);
2921  continue;
2922  }
2923  if (*startbuf == '\0' &&
2924  startoff == oadd(zp->z_gmtoff, stdoff))
2925  {
2926  doabbr(startbuf,
2927  zp,
2928  rp->r_abbrvar,
2929  rp->r_stdoff,
2930  false);
2931  }
2932  }
2933  eats(zp->z_filename, zp->z_linenum,
2934  rp->r_filename, rp->r_linenum);
2935  doabbr(ab, zp, rp->r_abbrvar,
2936  rp->r_stdoff, false);
2937  offset = oadd(zp->z_gmtoff, rp->r_stdoff);
2938  type = addtype(offset, ab, rp->r_stdoff != 0,
2939  rp->r_todisstd, rp->r_todisgmt);
2940  if (rp->r_hiyear == ZIC_MAX
2941  && !(0 <= lastatmax
2942  && ktime < attypes[lastatmax].at))
2943  lastatmax = timecnt;
2944  addtt(ktime, type);
2945  }
2946  }
2947  if (usestart)
2948  {
2949  if (*startbuf == '\0' &&
2950  zp->z_format != NULL &&
2951  strchr(zp->z_format, '%') == NULL &&
2952  strchr(zp->z_format, '/') == NULL)
2953  strcpy(startbuf, zp->z_format);
2954  eat(zp->z_filename, zp->z_linenum);
2955  if (*startbuf == '\0')
2956  error(_("cannot determine time zone abbreviation to use just after until time"));
2957  else
2958  addtt(starttime,
2959  addtype(startoff, startbuf,
2960  startoff != zp->z_gmtoff,
2961  startttisstd,
2962  startttisgmt));
2963  }
2964 
2965  /*
2966  * Now we may get to set starttime for the next zone line.
2967  */
2968  if (useuntil)
2969  {
2970  startttisstd = zp->z_untilrule.r_todisstd;
2971  startttisgmt = zp->z_untilrule.r_todisgmt;
2972  starttime = zp->z_untiltime;
2973  if (!startttisstd)
2974  starttime = tadd(starttime, -stdoff);
2975  if (!startttisgmt)
2976  starttime = tadd(starttime, -gmtoff);
2977  }
2978  }
2979  if (0 <= lastatmax)
2980  attypes[lastatmax].dontmerge = true;
2981  if (do_extend)
2982  {
2983  /*
2984  * If we're extending the explicitly listed observations for 400 years
2985  * because we can't fill the POSIX-TZ field, check whether we actually
2986  * ended up explicitly listing observations through that period. If
2987  * there aren't any near the end of the 400-year period, add a
2988  * redundant one at the end of the final year, to make it clear that
2989  * we are claiming to have definite knowledge of the lack of
2990  * transitions up to that point.
2991  */
2992  struct rule xr;
2993  struct attype *lastat;
2994 
2995  xr.r_month = TM_JANUARY;
2996  xr.r_dycode = DC_DOM;
2997  xr.r_dayofmonth = 1;
2998  xr.r_tod = 0;
2999  for (lastat = &attypes[0], i = 1; i < timecnt; i++)
3000  if (attypes[i].at > lastat->at)
3001  lastat = &attypes[i];
3002  if (lastat->at < rpytime(&xr, max_year - 1))
3003  {
3004  addtt(rpytime(&xr, max_year + 1), typecnt - 1);
3005  attypes[timecnt - 1].dontmerge = true;
3006  }
3007  }
3008  writezone(zpfirst->z_name, envvar, version);
3009  free(startbuf);
3010  free(ab);
3011  free(envvar);
3012 }
static bool yearistype(zic_t year, const char *type)
Definition: zic.c:3153
static void writezone(const char *const name, const char *const string, char version)
Definition: zic.c:1866
static zic_t leapmaxyear
Definition: zic.c:171
lineno_t r_linenum
Definition: zic.c:57
static int typecnt
Definition: zic.c:185
static int stringzone(char *result, struct zone const *zpfirst, ptrdiff_t zonecount)
Definition: zic.c:2513
Definition: zic.c:371
bool r_todisstd
Definition: zic.c:73
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:495
static void addtt(zic_t starttime, int type)
Definition: zic.c:3015
#define INITIALIZE(x)
Definition: private.h:106
const char * z_format
Definition: zic.c:99
#define DC_DOM
Definition: zic.c:87
zic_t z_untiltime
Definition: zic.c:108
struct rule z_untilrule
Definition: zic.c:107
static zic_t min_year
Definition: zic.c:176
static void updateminmax(const zic_t x)
Definition: zic.c:2370
static int max_format_len
Definition: zic.c:174
Definition: localtime.c:74
static const zic_t early_time
Definition: zic.c:1007
bool r_lowasnum
Definition: zic.c:63
#define ZIC_MAX
Definition: zic.c:27
const char * z_filename
Definition: zic.c:93
static zic_t tadd(zic_t t1, zic_t t2)
Definition: zic.c:3444
static int addtype(zic_t, char const *, bool, bool, bool)
Definition: zic.c:3040
bool r_todo
Definition: zic.c:79
static size_t doabbr(char *abbr, struct zone const *zp, char const *letters, zic_t stdoff, bool doquotes)
Definition: zic.c:2327
#define ZIC_VERSION_PRE_2013
Definition: zic.c:22
static bool leapseen
Definition: zic.c:169
#define ZIC_VERSION
Definition: zic.c:23
static int max_abbrvar_len
Definition: zic.c:173
int64 zic_t
Definition: zic.c:25
zic_t r_hiyear
Definition: zic.c:61
const char * r_yrtype
Definition: zic.c:62
zic_t r_temp
Definition: zic.c:80
#define ZIC_MIN
Definition: zic.c:26
const char * r_filename
Definition: zic.c:56
enum COMPAT_MODE compat
Definition: ecpg.c:25
static struct attype * attypes
zic_t at
Definition: zic.c:373
static zic_t rpytime(const struct rule *rp, zic_t wantedy)
Definition: zic.c:3473
static void eat(char const *name, lineno_t num)
Definition: zic.c:462
const char * r_abbrvar
Definition: zic.c:77
static zic_t const max_time
Definition: zic.c:967
static bool noise
Definition: zic.c:177
ptrdiff_t z_nrules
Definition: zic.c:105
lineno_t z_linenum
Definition: zic.c:94
static zic_t max_year
Definition: zic.c:175
#define free(a)
Definition: header.h:60
zic_t r_stdoff
Definition: zic.c:76
#define NULL
Definition: c.h:226
zic_t z_gmtoff
Definition: zic.c:97
static ptrdiff_t timecnt
Definition: zic.c:183
static int charcnt
Definition: zic.c:164
#define TM_JANUARY
Definition: tzfile.h:121
static zic_t leapminyear
Definition: zic.c:170
#define YEARSPERREPEAT
Definition: private.h:112
struct rule * z_rules
Definition: zic.c:104
Definition: zic.c:91
bool r_hiwasnum
Definition: zic.c:64
int i
#define EPOCH_YEAR
Definition: tzfile.h:136
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
zic_t r_loyear
Definition: zic.c:60
bool r_todisgmt
Definition: zic.c:75
static zic_t const min_time
Definition: zic.c:966
bool dontmerge
Definition: zic.c:374
static void eats(char const *name, lineno_t num, char const *rname, lineno_t rnum)
Definition: zic.c:453
#define _(x)
Definition: elog.c:84
static zic_t oadd(zic_t t1, zic_t t2)
Definition: zic.c:3436
zic_t z_stdoff
Definition: zic.c:102
static void * emalloc(size_t size)
Definition: zic.c:415
static void puttzcode ( const int32  val,
FILE *const  fp 
)
static

Definition at line 1833 of file zic.c.

References buf, and convert().

Referenced by writezone().

1834 {
1835  char buf[4];
1836 
1837  convert(val, buf);
1838  fwrite(buf, sizeof buf, 1, fp);
1839 }
static void convert(const int32 val, char *const buf)
Definition: zic.c:1811
static char * buf
Definition: pg_test_fsync.c:65
long val
Definition: informix.c:689
static void puttzcode64 ( const zic_t  val,
FILE *const  fp 
)
static

Definition at line 1842 of file zic.c.

References buf, and convert64().

Referenced by writezone().

1843 {
1844  char buf[8];
1845 
1846  convert64(val, buf);
1847  fwrite(buf, sizeof buf, 1, fp);
1848 }
static char * buf
Definition: pg_test_fsync.c:65
long val
Definition: informix.c:689
static void convert64(const zic_t val, char *const buf)
Definition: zic.c:1822
static int rcomp ( const void *  cp1,
const void *  cp2 
)
static

Definition at line 1058 of file zic.c.

Referenced by associate().

1059 {
1060  return strcmp(((const struct rule *) cp1)->r_name,
1061  ((const struct rule *) cp2)->r_name);
1062 }
Definition: localtime.c:74
static zic_t rpytime ( const struct rule rp,
zic_t  wantedy 
)
static

Definition at line 3473 of file zic.c.

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

Referenced by inzsub(), and outzone().

3474 {
3475  int m,
3476  i;
3477  zic_t dayoff; /* with a nod to Margaret O. */
3478  zic_t t,
3479  y;
3480 
3481  if (wantedy == ZIC_MIN)
3482  return min_time;
3483  if (wantedy == ZIC_MAX)
3484  return max_time;
3485  dayoff = 0;
3486  m = TM_JANUARY;
3487  y = EPOCH_YEAR;
3488  while (wantedy != y)
3489  {
3490  if (wantedy > y)
3491  {
3492  i = len_years[isleap(y)];
3493  ++y;
3494  }
3495  else
3496  {
3497  --y;
3498  i = -len_years[isleap(y)];
3499  }
3500  dayoff = oadd(dayoff, i);
3501  }
3502  while (m != rp->r_month)
3503  {
3504  i = len_months[isleap(y)][m];
3505  dayoff = oadd(dayoff, i);
3506  ++m;
3507  }
3508  i = rp->r_dayofmonth;
3509  if (m == TM_FEBRUARY && i == 29 && !isleap(y))
3510  {
3511  if (rp->r_dycode == DC_DOWLEQ)
3512  --i;
3513  else
3514  {
3515  error(_("use of 2/29 in non leap-year"));
3516  exit(EXIT_FAILURE);
3517  }
3518  }
3519  --i;
3520  dayoff = oadd(dayoff, i);
3521  if (rp->r_dycode == DC_DOWGEQ || rp->r_dycode == DC_DOWLEQ)
3522  {
3523  zic_t wday;
3524 
3525 #define LDAYSPERWEEK ((zic_t) DAYSPERWEEK)
3526  wday = EPOCH_WDAY;
3527 
3528  /*
3529  * Don't trust mod of negative numbers.
3530  */
3531  if (dayoff >= 0)
3532  wday = (wday + dayoff) % LDAYSPERWEEK;
3533  else
3534  {
3535  wday -= ((-dayoff) % LDAYSPERWEEK);
3536  if (wday < 0)
3537  wday += LDAYSPERWEEK;
3538  }
3539  while (wday != rp->r_wday)
3540  if (rp->r_dycode == DC_DOWGEQ)
3541  {
3542  dayoff = oadd(dayoff, 1);
3543  if (++wday >= LDAYSPERWEEK)
3544  wday = 0;
3545  ++i;
3546  }
3547  else
3548  {
3549  dayoff = oadd(dayoff, -1);
3550  if (--wday < 0)
3551  wday = LDAYSPERWEEK - 1;
3552  --i;
3553  }
3554  if (i < 0 || i >= len_months[isleap(y)][m])
3555  {
3556  if (noise)
3557  warning(_("rule goes past start/end of month; \
3558 will not work with pre-2004 versions of zic"));
3559  }
3560  }
3561  if (dayoff < min_time / SECSPERDAY)
3562  return min_time;
3563  if (dayoff > max_time / SECSPERDAY)
3564  return max_time;
3565  t = (zic_t) dayoff *SECSPERDAY;
3566 
3567  return tadd(t, rp->r_tod);
3568 }
zic_t r_tod
Definition: zic.c:72
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:495
#define EPOCH_WDAY
Definition: tzfile.h:137
int r_month
Definition: zic.c:66
#define DC_DOWGEQ
Definition: zic.c:88
#define isleap(y)
Definition: datetime.h:273
static const int len_months[2][MONSPERYEAR]
Definition: zic.c:362
#define ZIC_MAX
Definition: zic.c:27
#define LDAYSPERWEEK
static zic_t tadd(zic_t t1, zic_t t2)
Definition: zic.c:3444
#define SECSPERDAY
Definition: tzfile.h:110
#define TM_FEBRUARY
Definition: tzfile.h:122
int64 zic_t
Definition: zic.c:25
#define ZIC_MIN
Definition: zic.c:26
int r_dycode
Definition: zic.c:68
#define DC_DOWLEQ
Definition: zic.c:89
static zic_t const max_time
Definition: zic.c:967
static bool noise
Definition: zic.c:177
int r_dayofmonth
Definition: zic.c:69
int r_wday
Definition: zic.c:70
#define TM_JANUARY
Definition: tzfile.h:121
int i
#define EXIT_FAILURE
Definition: settings.h:150
#define EPOCH_YEAR
Definition: tzfile.h:136
static const int len_years[2]
Definition: zic.c:367
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
static zic_t const min_time
Definition: zic.c:966
#define _(x)
Definition: elog.c:84
static zic_t oadd(zic_t t1, zic_t t2)
Definition: zic.c:3436
static int rule_cmp ( struct rule const *  a,
struct rule const *  b 
)
static

Definition at line 2495 of file zic.c.

References rule::r_dayofmonth, rule::r_hiyear, and rule::r_month.

Referenced by stringzone().

2496 {
2497  if (!a)
2498  return -!!b;
2499  if (!b)
2500  return 1;
2501  if (a->r_hiyear != b->r_hiyear)
2502  return a->r_hiyear < b->r_hiyear ? -1 : 1;
2503  if (a->r_month - b->r_month != 0)
2504  return a->r_month - b->r_month;
2505  return a->r_dayofmonth - b->r_dayofmonth;
2506 }
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 1638 of file zic.c.

References _, byword(), DC_DOM, DC_DOWGEQ, DC_DOWLEQ, ecpyalloc(), error(), EXIT_FAILURE, free, gethms(), lookup::l_value, lowerit(), NULL, 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_todisgmt, rule::r_todisstd, rule::r_wday, rule::r_yrtype, YR_MAXIMUM, YR_MINIMUM, YR_ONLY, ZIC_MAX, and ZIC_MIN.

Referenced by inrule(), and inzsub().

1641 {
1642  const struct lookup *lp;
1643  const char *cp;
1644  char *dp;
1645  char *ep;
1646  char xs;
1647 
1648  /* PG: year_tmp is to avoid sscanf portability issues */
1649  int year_tmp;
1650 
1651  if ((lp = byword(monthp, mon_names)) == NULL)
1652  {
1653  error(_("invalid month name"));
1654  return;
1655  }
1656  rp->r_month = lp->l_value;
1657  rp->r_todisstd = false;
1658  rp->r_todisgmt = false;
1659  dp = ecpyalloc(timep);
1660  if (*dp != '\0')
1661  {
1662  ep = dp + strlen(dp) - 1;
1663  switch (lowerit(*ep))
1664  {
1665  case 's': /* Standard */
1666  rp->r_todisstd = true;
1667  rp->r_todisgmt = false;
1668  *ep = '\0';
1669  break;
1670  case 'w': /* Wall */
1671  rp->r_todisstd = false;
1672  rp->r_todisgmt = false;
1673  *ep = '\0';
1674  break;
1675  case 'g': /* Greenwich */
1676  case 'u': /* Universal */
1677  case 'z': /* Zulu */
1678  rp->r_todisstd = true;
1679  rp->r_todisgmt = true;
1680  *ep = '\0';
1681  break;
1682  }
1683  }
1684  rp->r_tod = gethms(dp, _("invalid time of day"), false);
1685  free(dp);
1686 
1687  /*
1688  * Year work.
1689  */
1690  cp = loyearp;
1691  lp = byword(cp, begin_years);
1692  rp->r_lowasnum = lp == NULL;
1693  if (!rp->r_lowasnum)
1694  switch (lp->l_value)
1695  {
1696  case YR_MINIMUM:
1697  rp->r_loyear = ZIC_MIN;
1698  break;
1699  case YR_MAXIMUM:
1700  rp->r_loyear = ZIC_MAX;
1701  break;
1702  default: /* "cannot happen" */
1703  fprintf(stderr,
1704  _("%s: panic: Invalid l_value %d\n"),
1705  progname, lp->l_value);
1706  exit(EXIT_FAILURE);
1707  }
1708  else if (sscanf(cp, "%d%c", &year_tmp, &xs) == 1)
1709  rp->r_loyear = year_tmp;
1710  else
1711  {
1712  error(_("invalid starting year"));
1713  return;
1714  }
1715  cp = hiyearp;
1716  lp = byword(cp, end_years);
1717  rp->r_hiwasnum = lp == NULL;
1718  if (!rp->r_hiwasnum)
1719  switch (lp->l_value)
1720  {
1721  case YR_MINIMUM:
1722  rp->r_hiyear = ZIC_MIN;
1723  break;
1724  case YR_MAXIMUM:
1725  rp->r_hiyear = ZIC_MAX;
1726  break;
1727  case YR_ONLY:
1728  rp->r_hiyear = rp->r_loyear;
1729  break;
1730  default: /* "cannot happen" */
1731  fprintf(stderr,
1732  _("%s: panic: Invalid l_value %d\n"),
1733  progname, lp->l_value);
1734  exit(EXIT_FAILURE);
1735  }
1736  else if (sscanf(cp, "%d%c", &year_tmp, &xs) == 1)
1737  rp->r_hiyear = year_tmp;
1738  else
1739  {
1740  error(_("invalid ending year"));
1741  return;
1742  }
1743  if (rp->r_loyear > rp->r_hiyear)
1744  {
1745  error(_("starting year greater than ending year"));
1746  return;
1747  }
1748  if (*typep == '\0')
1749  rp->r_yrtype = NULL;
1750  else
1751  {
1752  if (rp->r_loyear == rp->r_hiyear)
1753  {
1754  error(_("typed single year"));
1755  return;
1756  }
1757  rp->r_yrtype = ecpyalloc(typep);
1758  }
1759 
1760  /*
1761  * Day work. Accept things such as: 1 last-Sunday Sun<=20 Sun>=7
1762  */
1763  dp = ecpyalloc(dayp);
1764  if ((lp = byword(dp, lasts)) != NULL)
1765  {
1766  rp->r_dycode = DC_DOWLEQ;
1767  rp->r_wday = lp->l_value;
1768  rp->r_dayofmonth = len_months[1][rp->r_month];
1769  }
1770  else
1771  {
1772  if ((ep = strchr(dp, '<')) != NULL)
1773  rp->r_dycode = DC_DOWLEQ;
1774  else if ((ep = strchr(dp, '>')) != NULL)
1775  rp->r_dycode = DC_DOWGEQ;
1776  else
1777  {
1778  ep = dp;
1779  rp->r_dycode = DC_DOM;
1780  }
1781  if (rp->r_dycode != DC_DOM)
1782  {
1783  *ep++ = 0;
1784  if (*ep++ != '=')
1785  {
1786  error(_("invalid day of month"));
1787  free(dp);
1788  return;
1789  }
1790  if ((lp = byword(dp, wday_names)) == NULL)
1791  {
1792  error(_("invalid weekday name"));
1793  free(dp);
1794  return;
1795  }
1796  rp->r_wday = lp->l_value;
1797  }
1798  if (sscanf(ep, "%d%c", &rp->r_dayofmonth, &xs) != 1 ||
1799  rp->r_dayofmonth <= 0 ||
1800  (rp->r_dayofmonth > len_months[1][rp->r_month]))
1801  {
1802  error(_("invalid day of month"));
1803  free(dp);
1804  return;
1805  }
1806  }
1807  free(dp);
1808 }
#define YR_MINIMUM
Definition: zic.c:264
zic_t r_tod
Definition: zic.c:72
bool r_todisstd
Definition: zic.c:73
static char * ecpyalloc(char const *str)
Definition: zic.c:427
int r_month
Definition: zic.c:66
#define DC_DOWGEQ
Definition: zic.c:88
static struct lookup const begin_years[]
Definition: zic.c:343
#define DC_DOM
Definition: zic.c:87
static const int len_months[2][MONSPERYEAR]
Definition: zic.c:362
const int l_value
Definition: zic.c:291
bool r_lowasnum
Definition: zic.c:63
#define ZIC_MAX
Definition: zic.c:27
#define YR_ONLY
Definition: zic.c:266
static struct lookup const mon_names[]
Definition: zic.c:305
Definition: zic.c:288
zic_t r_hiyear
Definition: zic.c:61
const char * r_yrtype
Definition: zic.c:62
#define ZIC_MIN
Definition: zic.c:26
static struct lookup const end_years[]
Definition: zic.c:349
int r_dycode
Definition: zic.c:68
#define DC_DOWLEQ
Definition: zic.c:89
static zic_t gethms(const char *string, const char *errstring, bool)
Definition: zic.c:1254
static const char * progname
Definition: zic.c:182
#define free(a)
Definition: header.h:60
#define NULL
Definition: c.h:226
int r_dayofmonth
Definition: zic.c:69
int r_wday
Definition: zic.c:70
static struct lookup const * byword(const char *string, const struct lookup *lp)
Definition: zic.c:3358
static char lowerit(char)
Definition: zic.c:3271
#define YR_MAXIMUM
Definition: zic.c:265
static struct lookup const lasts[]
Definition: zic.c:332
bool r_hiwasnum
Definition: zic.c:64
static struct lookup const wday_names[]
Definition: zic.c:321
#define EXIT_FAILURE
Definition: settings.h:150
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
zic_t r_loyear
Definition: zic.c:60
bool r_todisgmt
Definition: zic.c:75
#define _(x)
Definition: elog.c:84
static char* shellquote ( char *  b,
char const *  s 
)
static

Definition at line 3139 of file zic.c.

Referenced by yearistype().

3140 {
3141  *b++ = '\'';
3142  while (*s)
3143  {
3144  if (*s == '\'')
3145  *b++ = '\'', *b++ = '\\', *b++ = '\'';
3146  *b++ = *s++;
3147  }
3148  *b++ = '\'';
3149  return b;
3150 }
static size_t size_product ( size_t  nitems,
size_t  itemsize 
)
static

Definition at line 399 of file zic.c.

References _, memory_exhausted(), and SIZE_MAX.

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

400 {
401  if (SIZE_MAX / itemsize < nitems)
402  memory_exhausted(_("size overflow"));
403  return nitems * itemsize;
404 }
#define SIZE_MAX
Definition: private.h:52
static void memory_exhausted(const char *msg) pg_attribute_noreturn()
Definition: zic.c:392
#define _(x)
Definition: elog.c:84
static int stringoffset ( char *  result,
zic_t  offset 
)
static

Definition at line 2379 of file zic.c.

References DAYSPERWEEK, HOURSPERDAY, MINSPERHOUR, and SECSPERMIN.

Referenced by stringrule(), and stringzone().

2380 {
2381  int hours;
2382  int minutes;
2383  int seconds;
2384  bool negative = offset < 0;
2385  int len = negative;
2386 
2387  if (negative)
2388  {
2389  offset = -offset;
2390  result[0] = '-';
2391  }
2392  seconds = offset % SECSPERMIN;
2393  offset /= SECSPERMIN;
2394  minutes = offset % MINSPERHOUR;
2395  offset /= MINSPERHOUR;
2396  hours = offset;
2397  if (hours >= HOURSPERDAY * DAYSPERWEEK)
2398  {
2399  result[0] = '\0';
2400  return 0;
2401  }
2402  len += sprintf(result + len, "%d", hours);
2403  if (minutes != 0 || seconds != 0)
2404  {
2405  len += sprintf(result + len, ":%02d", minutes);
2406  if (seconds != 0)
2407  len += sprintf(result + len, ":%02d", seconds);
2408  }
2409  return len;
2410 }
#define HOURSPERDAY
Definition: tzfile.h:105
#define MINSPERHOUR
Definition: tzfile.h:104
#define DAYSPERWEEK
Definition: tzfile.h:106
#define SECSPERMIN
Definition: tzfile.h:103
static int stringrule ( char *  result,
const struct rule *const  rp,
const zic_t  dstoff,
const zic_t  gmtoff 
)
static

Definition at line 2413 of file zic.c.

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

Referenced by stringzone().

2415 {
2416  zic_t tod = rp->r_tod;
2417  int compat = 0;
2418 
2419  if (rp->r_dycode == DC_DOM)
2420  {
2421  int month,
2422  total;
2423 
2424  if (rp->r_dayofmonth == 29 && rp->r_month == TM_FEBRUARY)
2425  return -1;
2426  total = 0;
2427  for (month = 0; month < rp->r_month; ++month)
2428  total += len_months[0][month];
2429  /* Omit the "J" in Jan and Feb, as that's shorter. */
2430  if (rp->r_month <= 1)
2431  result += sprintf(result, "%d", total + rp->r_dayofmonth - 1);
2432  else
2433  result += sprintf(result, "J%d", total + rp->r_dayofmonth);
2434  }
2435  else
2436  {
2437  int week;
2438  int wday = rp->r_wday;
2439  int wdayoff;
2440 
2441  if (rp->r_dycode == DC_DOWGEQ)
2442  {
2443  wdayoff = (rp->r_dayofmonth - 1) % DAYSPERWEEK;
2444  if (wdayoff)
2445  compat = 2013;
2446  wday -= wdayoff;
2447  tod += wdayoff * SECSPERDAY;
2448  week = 1 + (rp->r_dayofmonth - 1) / DAYSPERWEEK;
2449  }
2450  else if (rp->r_dycode == DC_DOWLEQ)
2451  {
2452  if (rp->r_dayofmonth == len_months[1][rp->r_month])
2453  week = 5;
2454  else
2455  {
2456  wdayoff = rp->r_dayofmonth % DAYSPERWEEK;
2457  if (wdayoff)
2458  compat = 2013;
2459  wday -= wdayoff;
2460  tod += wdayoff * SECSPERDAY;
2461  week = rp->r_dayofmonth / DAYSPERWEEK;
2462  }
2463  }
2464  else
2465  return -1; /* "cannot happen" */
2466  if (wday < 0)
2467  wday += DAYSPERWEEK;
2468  result += sprintf(result, "M%d.%d.%d",
2469  rp->r_month + 1, week, wday);
2470  }
2471  if (rp->r_todisgmt)
2472  tod += gmtoff;
2473  if (rp->r_todisstd && rp->r_stdoff == 0)
2474  tod += dstoff;
2475  if (tod != 2 * SECSPERMIN * MINSPERHOUR)
2476  {
2477  *result++ = '/';
2478  if (!stringoffset(result, tod))
2479  return -1;
2480  if (tod < 0)
2481  {
2482  if (compat < 2013)
2483  compat = 2013;
2484  }
2485  else if (SECSPERDAY <= tod)
2486  {
2487  if (compat < 1994)
2488  compat = 1994;
2489  }
2490  }
2491  return compat;
2492 }
zic_t r_tod
Definition: zic.c:72
bool r_todisstd
Definition: zic.c:73
int r_month
Definition: zic.c:66
#define DC_DOWGEQ
Definition: zic.c:88
#define DC_DOM
Definition: zic.c:87
static const int len_months[2][MONSPERYEAR]
Definition: zic.c:362
static int stringoffset(char *result, zic_t offset)
Definition: zic.c:2379
#define SECSPERDAY
Definition: tzfile.h:110
#define TM_FEBRUARY
Definition: tzfile.h:122
int64 zic_t
Definition: zic.c:25
enum COMPAT_MODE compat
Definition: ecpg.c:25
int r_dycode
Definition: zic.c:68
#define DC_DOWLEQ
Definition: zic.c:89
#define MINSPERHOUR
Definition: tzfile.h:104
zic_t r_stdoff
Definition: zic.c:76
#define DAYSPERWEEK
Definition: tzfile.h:106
int r_dayofmonth
Definition: zic.c:69
int r_wday
Definition: zic.c:70
#define SECSPERMIN
Definition: tzfile.h:103
bool r_todisgmt
Definition: zic.c:75
static int stringzone ( char *  result,
struct zone const *  zpfirst,
ptrdiff_t  zonecount 
)
static

Definition at line 2513 of file zic.c.

References compat, DC_DOM, doabbr(), i, MINSPERHOUR, NULL, rule::r_abbrvar, rule::r_dayofmonth, rule::r_dycode, rule::r_hiwasnum, rule::r_hiyear, rule::r_month, rule::r_stdoff, rule::r_tod, rule::r_todisgmt, rule::r_todisstd, rule::r_yrtype, rule_cmp(), SECSPERDAY, SECSPERMIN, stringoffset(), stringrule(), TM_DECEMBER, TM_JANUARY, YEAR_BY_YEAR_ZONE, zone::z_gmtoff, zone::z_nrules, zone::z_rules, zone::z_stdoff, and ZIC_MAX.

Referenced by outzone().

2514 {
2515  const struct zone *zp;
2516  struct rule *rp;
2517  struct rule *stdrp;
2518  struct rule *dstrp;
2519  ptrdiff_t i;
2520  const char *abbrvar;
2521  int compat = 0;
2522  int c;
2523  size_t len;
2524  int offsetlen;
2525  struct rule stdr,
2526  dstr;
2527 
2528  result[0] = '\0';
2529  zp = zpfirst + zonecount - 1;
2530  stdrp = dstrp = NULL;
2531  for (i = 0; i < zp->z_nrules; ++i)
2532  {
2533  rp = &zp->z_rules[i];
2534  if (rp->r_hiwasnum || rp->r_hiyear != ZIC_MAX)
2535  continue;
2536  if (rp->r_yrtype != NULL)
2537  continue;
2538  if (rp->r_stdoff == 0)
2539  {
2540  if (stdrp == NULL)
2541  stdrp = rp;
2542  else
2543  return -1;
2544  }
2545  else
2546  {
2547  if (dstrp == NULL)
2548  dstrp = rp;
2549  else
2550  return -1;
2551  }
2552  }
2553  if (stdrp == NULL && dstrp == NULL)
2554  {
2555  /*
2556  * There are no rules running through "max". Find the latest std rule
2557  * in stdabbrrp and latest rule of any type in stdrp.
2558  */
2559  struct rule *stdabbrrp = NULL;
2560 
2561  for (i = 0; i < zp->z_nrules; ++i)
2562  {
2563  rp = &zp->z_rules[i];
2564  if (rp->r_stdoff == 0 && rule_cmp(stdabbrrp, rp) < 0)
2565  stdabbrrp = rp;
2566  if (rule_cmp(stdrp, rp) < 0)
2567  stdrp = rp;
2568  }
2569 
2570  /*
2571  * Horrid special case: if year is 2037, presume this is a zone
2572  * handled on a year-by-year basis; do not try to apply a rule to the
2573  * zone.
2574  */
2575  if (stdrp != NULL && stdrp->r_hiyear == 2037)
2576  return YEAR_BY_YEAR_ZONE;
2577 
2578  if (stdrp != NULL && stdrp->r_stdoff != 0)
2579  {
2580  /* Perpetual DST. */
2581  dstr.r_month = TM_JANUARY;
2582  dstr.r_dycode = DC_DOM;
2583  dstr.r_dayofmonth = 1;
2584  dstr.r_tod = 0;
2585  dstr.r_todisstd = dstr.r_todisgmt = false;
2586  dstr.r_stdoff = stdrp->r_stdoff;
2587  dstr.r_abbrvar = stdrp->r_abbrvar;
2588  stdr.r_month = TM_DECEMBER;
2589  stdr.r_dycode = DC_DOM;
2590  stdr.r_dayofmonth = 31;
2591  stdr.r_tod = SECSPERDAY + stdrp->r_stdoff;
2592  stdr.r_todisstd = stdr.r_todisgmt = false;
2593  stdr.r_stdoff = 0;
2594  stdr.r_abbrvar
2595  = (stdabbrrp ? stdabbrrp->r_abbrvar : "");
2596  dstrp = &dstr;
2597  stdrp = &stdr;
2598  }
2599  }
2600  if (stdrp == NULL && (zp->z_nrules != 0 || zp->z_stdoff != 0))
2601  return -1;
2602  abbrvar = (stdrp == NULL) ? "" : stdrp->r_abbrvar;
2603  len = doabbr(result, zp, abbrvar, 0, true);
2604  offsetlen = stringoffset(result + len, -zp->z_gmtoff);
2605  if (!offsetlen)
2606  {
2607  result[0] = '\0';
2608  return -1;
2609  }
2610  len += offsetlen;
2611  if (dstrp == NULL)
2612  return compat;
2613  len += doabbr(result + len, zp, dstrp->r_abbrvar, dstrp->r_stdoff, true);
2614  if (dstrp->r_stdoff != SECSPERMIN * MINSPERHOUR)
2615  {
2616  offsetlen = stringoffset(result + len,
2617  -(zp->z_gmtoff + dstrp->r_stdoff));
2618  if (!offsetlen)
2619  {
2620  result[0] = '\0';
2621  return -1;
2622  }
2623  len += offsetlen;
2624  }
2625  result[len++] = ',';
2626  c = stringrule(result + len, dstrp, dstrp->r_stdoff, zp->z_gmtoff);
2627  if (c < 0)
2628  {
2629  result[0] = '\0';
2630  return -1;
2631  }
2632  if (compat < c)
2633  compat = c;
2634  len += strlen(result + len);
2635  result[len++] = ',';
2636  c = stringrule(result + len, stdrp, dstrp->r_stdoff, zp->z_gmtoff);
2637  if (c < 0)
2638  {
2639  result[0] = '\0';
2640  return -1;
2641  }
2642  if (compat < c)
2643  compat = c;
2644  return compat;
2645 }
static int stringrule(char *result, const struct rule *const rp, const zic_t dstoff, const zic_t gmtoff)
Definition: zic.c:2413
static int rule_cmp(struct rule const *a, struct rule const *b)
Definition: zic.c:2495
#define DC_DOM
Definition: zic.c:87
static int stringoffset(char *result, zic_t offset)
Definition: zic.c:2379
Definition: localtime.c:74
#define ZIC_MAX
Definition: zic.c:27
static size_t doabbr(char *abbr, struct zone const *zp, char const *letters, zic_t stdoff, bool doquotes)
Definition: zic.c:2327
#define SECSPERDAY
Definition: tzfile.h:110
char * c
zic_t r_hiyear
Definition: zic.c:61
const char * r_yrtype
Definition: zic.c:62
enum COMPAT_MODE compat
Definition: ecpg.c:25
#define TM_DECEMBER
Definition: tzfile.h:132
const char * r_abbrvar
Definition: zic.c:77
#define MINSPERHOUR
Definition: tzfile.h:104
ptrdiff_t z_nrules
Definition: zic.c:105
zic_t r_stdoff
Definition: zic.c:76
#define NULL
Definition: c.h:226
zic_t z_gmtoff
Definition: zic.c:97
#define TM_JANUARY
Definition: tzfile.h:121
#define SECSPERMIN
Definition: tzfile.h:103
struct rule * z_rules
Definition: zic.c:104
Definition: zic.c:91
bool r_hiwasnum
Definition: zic.c:64
int i
zic_t z_stdoff
Definition: zic.c:102
static zic_t tadd ( zic_t  t1,
zic_t  t2 
)
static

Definition at line 3444 of file zic.c.

References max_time, min_time, and time_overflow().

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

3445 {
3446  if (t1 < 0)
3447  {
3448  if (t2 < min_time - t1)
3449  {
3450  if (t1 != min_time)
3451  time_overflow();
3452  return min_time;
3453  }
3454  }
3455  else
3456  {
3457  if (max_time - t1 < t2)
3458  {
3459  if (t1 != max_time)
3460  time_overflow();
3461  return max_time;
3462  }
3463  }
3464  return t1 + t2;
3465 }
static void time_overflow(void)
Definition: zic.c:3429
static zic_t const max_time
Definition: zic.c:967
static zic_t const min_time
Definition: zic.c:966
static void time_overflow ( void  )
static

Definition at line 3429 of file zic.c.

References _, error(), and EXIT_FAILURE.

Referenced by oadd(), and tadd().

3430 {
3431  error(_("time overflow"));
3432  exit(EXIT_FAILURE);
3433 }
#define EXIT_FAILURE
Definition: settings.h:150
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
#define _(x)
Definition: elog.c:84
static void updateminmax ( const zic_t  x)
static

Definition at line 2370 of file zic.c.

Referenced by outzone().

2371 {
2372  if (min_year > x)
2373  min_year = x;
2374  if (max_year < x)
2375  max_year = x;
2376 }
static zic_t min_year
Definition: zic.c:176
static zic_t max_year
Definition: zic.c:175
static void usage ( FILE *  stream,
int  status 
)
static

Definition at line 523 of file zic.c.

References _, close_file(), EXIT_SUCCESS, and NULL.

Referenced by main().

524 {
525  fprintf(stream,
526  _("%s: usage is %s [ --version ] [ --help ] [ -v ] [ -P ] \\\n"
527  "\t[ -l localtime ] [ -p posixrules ] [ -d directory ] \\\n"
528  "\t[ -L leapseconds ] [ filename ... ]\n\n"
529  "Report bugs to %s.\n"),
530  progname, progname, PACKAGE_BUGREPORT);
531  if (status == EXIT_SUCCESS)
532  close_file(stream, NULL, NULL);
533  exit(status);
534 }
#define EXIT_SUCCESS
Definition: settings.h:146
static const char * progname
Definition: zic.c:182
#define NULL
Definition: c.h:226
static void close_file(FILE *stream, char const *dir, char const *name)
Definition: zic.c:507
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:222
#define _(x)
Definition: elog.c:84
static void verror ( const char *  string,
va_list  args 
)
static

Definition at line 468 of file zic.c.

References _, NULL, and PRIdLINENO.

Referenced by error(), and warning().

469 {
470  /*
471  * Match the format of "cc" to allow sh users to zic ... 2>&1 | error -t
472  * "*" -v on BSD systems.
473  */
474  if (filename)
475  fprintf(stderr, _("\"%s\", line %" PRIdLINENO ": "), filename, linenum);
476  vfprintf(stderr, string, args);
477  if (rfilename != NULL)
478  fprintf(stderr, _(" (rule from \"%s\", line %" PRIdLINENO ")"),
480  fprintf(stderr, "\n");
481 }
#define PRIdLINENO
Definition: zic.c:52
static lineno_t rlinenum
Definition: zic.c:181
static const char * filename
Definition: zic.c:167
static lineno_t linenum
Definition: zic.c:172
static const char * rfilename
Definition: zic.c:180
#define NULL
Definition: c.h:226
#define _(x)
Definition: elog.c:84
static void warning ( const char *  string,
  ... 
)
static

Definition at line 495 of file zic.c.

References _, generate_unaccent_rules::args, and verror().

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

496 {
497  va_list args;
498 
499  fprintf(stderr, _("warning: "));
500  va_start(args, string);
501  verror(string, args);
502  va_end(args);
503  warnings = true;
504 }
static bool warnings
Definition: zic.c:166
static void verror(const char *string, va_list args) pg_attribute_printf(1
Definition: zic.c:468
#define _(x)
Definition: elog.c:84
static void writezone ( const char *const  name,
const char *const  string,
char  version 
)
static

Definition at line 1866 of file zic.c.

References _, addtype(), attype::at, atcomp(), attypes, close_file(), convert(), DO, emalloc(), error(), EXIT_FAILURE, free, GRANDPARENTED, i, INT64_FORMAT, is32(), leapcnt, mkdirs(), PG_INT32_MIN, puttzcode(), puttzcode64(), qsort, size_product(), strerror(), tadd(), timecnt, tm, 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_reserved, tzhead::tzh_timecnt, tzhead::tzh_ttisgmtcnt, tzhead::tzh_ttisstdcnt, tzhead::tzh_typecnt, tzhead::tzh_version, warning(), and WORK_AROUND_QTBUG_53071.

Referenced by outzone().

1867 {
1868  FILE *fp;
1869  ptrdiff_t i,
1870  j;
1871  int leapcnt32,
1872  leapi32;
1873  ptrdiff_t timecnt32,
1874  timei32;
1875  int pass;
1876  static const struct tzhead tzh0;
1877  static struct tzhead tzh;
1878  bool dir_checked = false;
1879  zic_t one = 1;
1880  zic_t y2038_boundary = one << 31;
1881  ptrdiff_t nats = timecnt + WORK_AROUND_QTBUG_53071;
1882  zic_t *ats = emalloc(size_product(nats, sizeof *ats + 1));
1883  void *typesptr = ats + nats;
1884  unsigned char *types = typesptr;
1885 
1886  /*
1887  * Sort.
1888  */
1889  if (timecnt > 1)
1890  qsort(attypes, timecnt, sizeof *attypes, atcomp);
1891 
1892  /*
1893  * Optimize.
1894  */
1895  {
1896  ptrdiff_t fromi,
1897  toi;
1898 
1899  toi = 0;
1900  fromi = 0;
1901  while (fromi < timecnt && attypes[fromi].at < early_time)
1902  ++fromi;
1903  for (; fromi < timecnt; ++fromi)
1904  {
1905  if (toi > 1 && ((attypes[fromi].at +
1906  gmtoffs[attypes[toi - 1].type]) <=
1907  (attypes[toi - 1].at +
1908  gmtoffs[attypes[toi - 2].type])))
1909  {
1910  attypes[toi - 1].type =
1911  attypes[fromi].type;
1912  continue;
1913  }
1914  if (toi == 0
1915  || attypes[fromi].dontmerge
1916  || attypes[toi - 1].type != attypes[fromi].type)
1917  attypes[toi++] = attypes[fromi];
1918  }
1919  timecnt = toi;
1920  }
1921 
1922  if (noise && timecnt > 1200)
1923  {
1924  if (timecnt > TZ_MAX_TIMES)
1925  warning(_("reference clients mishandle"
1926  " more than %d transition times"),
1927  TZ_MAX_TIMES);
1928  else
1929  warning(_("pre-2014 clients may mishandle"
1930  " more than 1200 transition times"));
1931  }
1932 
1933  /*
1934  * Transfer.
1935  */
1936  for (i = 0; i < timecnt; ++i)
1937  {
1938  ats[i] = attypes[i].at;
1939  types[i] = attypes[i].type;
1940  }
1941 
1942  /*
1943  * Work around QTBUG-53071 for time stamps less than y2038_boundary - 1,
1944  * by inserting a no-op transition at time y2038_boundary - 1. This works
1945  * only for timestamps before the boundary, which should be good enough in
1946  * practice as QTBUG-53071 should be long-dead by 2038.
1947  */
1948  if (WORK_AROUND_QTBUG_53071 && timecnt != 0
1949  && ats[timecnt - 1] < y2038_boundary - 1 && strchr(string, '<'))
1950  {
1951  ats[timecnt] = y2038_boundary - 1;
1952  types[timecnt] = types[timecnt - 1];
1953  timecnt++;
1954  }
1955 
1956  /*
1957  * Correct for leap seconds.
1958  */
1959  for (i = 0; i < timecnt; ++i)
1960  {
1961  j = leapcnt;
1962  while (--j >= 0)
1963  if (ats[i] > trans[j] - corr[j])
1964  {
1965  ats[i] = tadd(ats[i], corr[j]);
1966  break;
1967  }
1968  }
1969 
1970  /*
1971  * Figure out 32-bit-limited starts and counts.
1972  */
1973  timecnt32 = timecnt;
1974  timei32 = 0;
1975  leapcnt32 = leapcnt;
1976  leapi32 = 0;
1977  while (timecnt32 > 0 && !is32(ats[timecnt32 - 1]))
1978  --timecnt32;
1979  while (timecnt32 > 0 && !is32(ats[timei32]))
1980  {
1981  --timecnt32;
1982  ++timei32;
1983  }
1984 
1985  /*
1986  * Output an INT32_MIN "transition" if appropriate; see below.
1987  */
1988  if (timei32 > 0 && ats[timei32] > PG_INT32_MIN)
1989  {
1990  --timei32;
1991  ++timecnt32;
1992  }
1993  while (leapcnt32 > 0 && !is32(trans[leapcnt32 - 1]))
1994  --leapcnt32;
1995  while (leapcnt32 > 0 && !is32(trans[leapi32]))
1996  {
1997  --leapcnt32;
1998  ++leapi32;
1999  }
2000 
2001  /*
2002  * Remove old file, if any, to snap links.
2003  */
2004  if (remove(name) == 0)
2005  dir_checked = true;
2006  else if (errno != ENOENT)
2007  {
2008  const char *e = strerror(errno);
2009 
2010  fprintf(stderr, _("%s: Cannot remove %s/%s: %s\n"),
2011  progname, directory, name, e);
2012  exit(EXIT_FAILURE);
2013  }
2014  fp = fopen(name, "wb");
2015  if (!fp)
2016  {
2017  int fopen_errno = errno;
2018 
2019  if (fopen_errno == ENOENT && !dir_checked)
2020  {
2021  mkdirs(name, true);
2022  fp = fopen(name, "wb");
2023  fopen_errno = errno;
2024  }
2025  if (!fp)
2026  {
2027  fprintf(stderr, _("%s: Cannot create %s/%s: %s\n"),
2028  progname, directory, name, strerror(fopen_errno));
2029  exit(EXIT_FAILURE);
2030  }
2031  }
2032  for (pass = 1; pass <= 2; ++pass)
2033  {
2034  ptrdiff_t thistimei,
2035  thistimecnt,
2036  thistimelim;
2037  int thisleapi,
2038  thisleapcnt,
2039  thisleaplim;
2040  int writetype[TZ_MAX_TYPES];
2041  int typemap[TZ_MAX_TYPES];
2042  int thistypecnt;
2043  char thischars[TZ_MAX_CHARS];
2044  int thischarcnt;
2045  bool toomanytimes;
2046  int indmap[TZ_MAX_CHARS];
2047 
2048  if (pass == 1)
2049  {
2050  thistimei = timei32;
2051  thistimecnt = timecnt32;
2052  toomanytimes = thistimecnt >> 31 >> 1 != 0;
2053  thisleapi = leapi32;
2054  thisleapcnt = leapcnt32;
2055  }
2056  else
2057  {
2058  thistimei = 0;
2059  thistimecnt = timecnt;
2060  toomanytimes = thistimecnt >> 31 >> 31 >> 2 != 0;
2061  thisleapi = 0;
2062  thisleapcnt = leapcnt;
2063  }
2064  if (toomanytimes)
2065  error(_("too many transition times"));
2066  thistimelim = thistimei + thistimecnt;
2067  thisleaplim = thisleapi + thisleapcnt;
2068  for (i = 0; i < typecnt; ++i)
2069  writetype[i] = thistimecnt == timecnt;
2070  if (thistimecnt == 0)
2071  {
2072  /*
2073  * No transition times fall in the current (32- or 64-bit) window.
2074  */
2075  if (typecnt != 0)
2076  writetype[typecnt - 1] = true;
2077  }
2078  else
2079  {
2080  for (i = thistimei - 1; i < thistimelim; ++i)
2081  if (i >= 0)
2082  writetype[types[i]] = true;
2083 
2084  /*
2085  * For America/Godthab and Antarctica/Palmer
2086  */
2087  if (thistimei == 0)
2088  writetype[0] = true;
2089  }
2090 #ifndef LEAVE_SOME_PRE_2011_SYSTEMS_IN_THE_LURCH
2091 
2092  /*
2093  * For some pre-2011 systems: if the last-to-be-written standard (or
2094  * daylight) type has an offset different from the most recently used
2095  * offset, append an (unused) copy of the most recently used type (to
2096  * help get global "altzone" and "timezone" variables set correctly).
2097  */
2098  {
2099  int mrudst,
2100  mrustd,
2101  hidst,
2102  histd,
2103  type;
2104 
2105  hidst = histd = mrudst = mrustd = -1;
2106  for (i = thistimei; i < thistimelim; ++i)
2107  if (isdsts[types[i]])
2108  mrudst = types[i];
2109  else
2110  mrustd = types[i];
2111  for (i = 0; i < typecnt; ++i)
2112  if (writetype[i])
2113  {
2114  if (isdsts[i])
2115  hidst = i;
2116  else
2117  histd = i;
2118  }
2119  if (hidst >= 0 && mrudst >= 0 && hidst != mrudst &&
2120  gmtoffs[hidst] != gmtoffs[mrudst])
2121  {
2122  isdsts[mrudst] = -1;
2123  type = addtype(gmtoffs[mrudst],
2124  &chars[abbrinds[mrudst]],
2125  true,
2126  ttisstds[mrudst],
2127  ttisgmts[mrudst]);
2128  isdsts[mrudst] = 1;
2129  writetype[type] = true;
2130  }
2131  if (histd >= 0 && mrustd >= 0 && histd != mrustd &&
2132  gmtoffs[histd] != gmtoffs[mrustd])
2133  {
2134  isdsts[mrustd] = -1;
2135  type = addtype(gmtoffs[mrustd],
2136  &chars[abbrinds[mrustd]],
2137  false,
2138  ttisstds[mrustd],
2139  ttisgmts[mrustd]);
2140  isdsts[mrustd] = 0;
2141  writetype[type] = true;
2142  }
2143  }
2144 #endif /* !defined
2145  * LEAVE_SOME_PRE_2011_SYSTEMS_IN_THE_LURCH */
2146  thistypecnt = 0;
2147  for (i = 0; i < typecnt; ++i)
2148  typemap[i] = writetype[i] ? thistypecnt++ : -1;
2149  for (i = 0; i < sizeof indmap / sizeof indmap[0]; ++i)
2150  indmap[i] = -1;
2151  thischarcnt = 0;
2152  for (i = 0; i < typecnt; ++i)
2153  {
2154  char *thisabbr;
2155 
2156  if (!writetype[i])
2157  continue;
2158  if (indmap[abbrinds[i]] >= 0)
2159  continue;
2160  thisabbr = &chars[abbrinds[i]];
2161  for (j = 0; j < thischarcnt; ++j)
2162  if (strcmp(&thischars[j], thisabbr) == 0)
2163  break;
2164  if (j == thischarcnt)
2165  {
2166  strcpy(&thischars[thischarcnt], thisabbr);
2167  thischarcnt += strlen(thisabbr) + 1;
2168  }
2169  indmap[abbrinds[i]] = j;
2170  }
2171 #define DO(field) fwrite(tzh.field, sizeof tzh.field, 1, fp)
2172  tzh = tzh0;
2173  strncpy(tzh.tzh_magic, TZ_MAGIC, sizeof tzh.tzh_magic);
2174  tzh.tzh_version[0] = version;
2175  convert(thistypecnt, tzh.tzh_ttisgmtcnt);
2176  convert(thistypecnt, tzh.tzh_ttisstdcnt);
2177  convert(thisleapcnt, tzh.tzh_leapcnt);
2178  convert(thistimecnt, tzh.tzh_timecnt);
2179  convert(thistypecnt, tzh.tzh_typecnt);
2180  convert(thischarcnt, tzh.tzh_charcnt);
2181  DO(tzh_magic);
2182  DO(tzh_version);
2183  DO(tzh_reserved);
2184  DO(tzh_ttisgmtcnt);
2185  DO(tzh_ttisstdcnt);
2186  DO(tzh_leapcnt);
2187  DO(tzh_timecnt);
2188  DO(tzh_typecnt);
2189  DO(tzh_charcnt);
2190 #undef DO
2191  for (i = thistimei; i < thistimelim; ++i)
2192  if (pass == 1)
2193 
2194  /*
2195  * Output an INT32_MIN "transition" if appropriate; see above.
2196  */
2197  puttzcode(((ats[i] < PG_INT32_MIN) ?
2198  PG_INT32_MIN : ats[i]), fp);
2199  else
2200  {
2201  puttzcode64(ats[i], fp);
2202 
2203  /* Print current timezone abbreviations if requested */
2204  if (print_abbrevs &&
2205  (i == thistimelim - 1 || ats[i + 1] > print_cutoff))
2206  {
2207  unsigned char tm = typemap[types[i]];
2208  char *thisabbrev = &thischars[indmap[abbrinds[tm]]];
2209 
2210  /* filter out assorted junk entries */
2211  if (strcmp(thisabbrev, GRANDPARENTED) != 0 &&
2212  strcmp(thisabbrev, "zzz") != 0)
2213  fprintf(stdout, "%s\t" INT64_FORMAT "%s\n",
2214  thisabbrev,
2215  gmtoffs[tm],
2216  isdsts[tm] ? "\tD" : "");
2217  }
2218  }
2219  for (i = thistimei; i < thistimelim; ++i)
2220  {
2221  unsigned char uc;
2222 
2223  uc = typemap[types[i]];
2224  fwrite(&uc, sizeof uc, 1, fp);
2225  }
2226  for (i = 0; i < typecnt; ++i)
2227  if (writetype[i])
2228  {
2229  puttzcode(gmtoffs[i], fp);
2230  putc(isdsts[i], fp);
2231  putc((unsigned char) indmap[abbrinds[i]], fp);
2232  }
2233  if (thischarcnt != 0)
2234  fwrite(thischars, sizeof thischars[0],
2235  thischarcnt, fp);
2236  for (i = thisleapi; i < thisleaplim; ++i)
2237  {
2238  zic_t todo;
2239 
2240  if (roll[i])
2241  {
2242  if (timecnt == 0 || trans[i] < ats[0])
2243  {
2244  j = 0;
2245  while (isdsts[j])
2246  if (++j >= typecnt)
2247  {
2248  j = 0;
2249  break;
2250  }
2251  }
2252  else
2253  {
2254  j = 1;
2255  while (j < timecnt &&
2256  trans[i] >= ats[j])
2257  ++j;
2258  j = types[j - 1];
2259  }
2260  todo = tadd(trans[i], -gmtoffs[j]);
2261  }
2262  else
2263  todo = trans[i];
2264  if (pass == 1)
2265  puttzcode(todo, fp);
2266  else
2267  puttzcode64(todo, fp);
2268  puttzcode(corr[i], fp);
2269  }
2270  for (i = 0; i < typecnt; ++i)
2271  if (writetype[i])
2272  putc(ttisstds[i], fp);
2273  for (i = 0; i < typecnt; ++i)
2274  if (writetype[i])
2275  putc(ttisgmts[i], fp);
2276  }
2277  fprintf(fp, "\n%s\n", string);
2278  close_file(fp, directory, name);
2279  free(ats);
2280 }
static bool ttisstds[TZ_MAX_TYPES]
Definition: zic.c:380
static bool print_abbrevs
Definition: zic.c:178
static zic_t print_cutoff
Definition: zic.c:179
static int typecnt
Definition: zic.c:185
static zic_t gmtoffs[TZ_MAX_TYPES]
Definition: zic.c:377
static unsigned char abbrinds[TZ_MAX_TYPES]
Definition: zic.c:379
struct typedefs * types
Definition: ecpg.c:29
unsigned char type
Definition: zic.c:375
static char isdsts[TZ_MAX_TYPES]
Definition: zic.c:378
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:495
static zic_t corr[TZ_MAX_LEAPS]
Definition: zic.c:384
static bool is32(const zic_t x)
Definition: zic.c:1860
#define TZ_MAX_TIMES
Definition: tzfile.h:93
char tzh_timecnt[4]
Definition: tzfile.h:41
static bool ttisgmts[TZ_MAX_TYPES]
Definition: zic.c:381
static void mkdirs(char const *, bool)
Definition: zic.c:3609
#define GRANDPARENTED
Definition: private.h:27
static const zic_t early_time
Definition: zic.c:1007
static struct pg_tm tm
Definition: localtime.c:103
static zic_t tadd(zic_t t1, zic_t t2)
Definition: zic.c:3444
static void convert(const int32 val, char *const buf)
Definition: zic.c:1811
static int addtype(zic_t, char const *, bool, bool, bool)
Definition: zic.c:3040
char tzh_magic[4]
Definition: tzfile.h:35
#define TZ_MAGIC
Definition: tzfile.h:31
static int leapcnt
Definition: zic.c:168
int64 zic_t
Definition: zic.c:25
char tzh_leapcnt[4]
Definition: tzfile.h:40
#define PG_INT32_MIN
Definition: c.h:336
#define TZ_MAX_CHARS
Definition: tzfile.h:98
static struct attype * attypes
zic_t at
Definition: zic.c:373
static void puttzcode64(const zic_t val, FILE *const fp)
Definition: zic.c:1842
static bool noise
Definition: zic.c:177
Definition: tzfile.h:33
char tzh_typecnt[4]
Definition: tzfile.h:42
static const char * progname
Definition: zic.c:182
#define free(a)
Definition: header.h:60
char tzh_version[1]
Definition: tzfile.h:36
char tzh_charcnt[4]
Definition: tzfile.h:43
static ptrdiff_t timecnt
Definition: zic.c:183
static const char * directory
Definition: zic.c:562
static void close_file(FILE *stream, char const *dir, char const *name)
Definition: zic.c:507
#define INT64_FORMAT
Definition: c.h:312
const char * name
Definition: encode.c:521
static int atcomp(const void *avp, const void *bvp)
Definition: zic.c:1851
e
Definition: preproc-init.c:82
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:383
#define TZ_MAX_TYPES
Definition: tzfile.h:96
char tzh_ttisstdcnt[4]
Definition: tzfile.h:39
int i
const char * strerror(int errnum)
Definition: strerror.c:19
#define EXIT_FAILURE
Definition: settings.h:150
char tzh_reserved[15]
Definition: tzfile.h:37
#define qsort(a, b, c, d)
Definition: port.h:440
#define DO(field)
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
static char chars[TZ_MAX_CHARS]
Definition: zic.c:382
#define _(x)
Definition: elog.c:84
static size_t size_product(size_t nitems, size_t itemsize)
Definition: zic.c:399
static void puttzcode(const int32 val, FILE *const fp)
Definition: zic.c:1833
static char roll[TZ_MAX_LEAPS]
Definition: zic.c:385
static void * emalloc(size_t size)
Definition: zic.c:415
char tzh_ttisgmtcnt[4]
Definition: tzfile.h:38
static bool yearistype ( zic_t  year,
const char *  type 
)
static

Definition at line 3153 of file zic.c.

References _, buf, emalloc(), error(), EXIT_FAILURE, free, INT64_FORMAT, INT_STRLEN_MAXIMUM, NULL, shellquote(), status(), WEXITSTATUS, and WIFEXITED.

Referenced by outzone().

3154 {
3155  char *buf;
3156  char *b;
3157  int result;
3158 
3159  if (type == NULL || *type == '\0')
3160  return true;
3161  buf = emalloc(1 + 4 * strlen(yitcommand) + 2
3162  + INT_STRLEN_MAXIMUM(zic_t) +2 + 4 * strlen(type) + 2);
3163  b = shellquote(buf, yitcommand);
3164  *b++ = ' ';
3165  b += sprintf(b, INT64_FORMAT, year);
3166  *b++ = ' ';
3167  b = shellquote(b, type);
3168  *b = '\0';
3169  result = system(buf);
3170  if (WIFEXITED(result))
3171  {
3172  int status = WEXITSTATUS(result);
3173 
3174  if (status <= 1)
3175  {
3176  free(buf);
3177  return status == 0;
3178  }
3179  }
3180  error(_("Wild result from command execution"));
3181  fprintf(stderr, _("%s: command was '%s', result was %d\n"),
3182  progname, buf, result);
3183  exit(EXIT_FAILURE);
3184 }
#define INT_STRLEN_MAXIMUM(type)
Definition: private.h:98
#define WIFEXITED(w)
Definition: win32.h:180
static const char * yitcommand
Definition: zic.c:564
static char * shellquote(char *b, char const *s)
Definition: zic.c:3139
static char * buf
Definition: pg_test_fsync.c:65
int64 zic_t
Definition: zic.c:25
static const char * progname
Definition: zic.c:182
#define free(a)
Definition: header.h:60
#define WEXITSTATUS(w)
Definition: win32.h:182
#define NULL
Definition: c.h:226
#define INT64_FORMAT
Definition: c.h:312
#define EXIT_FAILURE
Definition: settings.h:150
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:222
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:484
#define _(x)
Definition: elog.c:84
static void * emalloc(size_t size)
Definition: zic.c:415

Variable Documentation

unsigned char abbrinds[TZ_MAX_TYPES]
static

Definition at line 379 of file zic.c.

struct attype * attypes
static

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

struct lookup const begin_years[]
static
Initial value:
= {
{"minimum", YR_MINIMUM},
{"maximum", YR_MAXIMUM},
{NULL, 0}
}
#define YR_MINIMUM
Definition: zic.c:264
#define NULL
Definition: c.h:226
#define YR_MAXIMUM
Definition: zic.c:265

Definition at line 343 of file zic.c.

int charcnt
static

Definition at line 164 of file zic.c.

Referenced by addtype(), pg_interpret_timezone_abbrev(), tzloadbody(), and tzparse().

char chars[TZ_MAX_CHARS]
static

Definition at line 382 of file zic.c.

Referenced by getColorInfo().

zic_t corr[TZ_MAX_LEAPS]
static

Definition at line 384 of file zic.c.

Referenced by timesub(), and tzloadbody().

const char* directory
static

Definition at line 562 of file zic.c.

Referenced by main().

const zic_t early_time
static
Initial value:
#define TIME_T_BITS_IN_FILE
Definition: zic.c:964
#define MINVAL(t, b)
Definition: private.h:88
int64 zic_t
Definition: zic.c:25
#define BIG_BANG
Definition: zic.c:992

Definition at line 1007 of file zic.c.

struct lookup const end_years[]
static
Initial value:
= {
{"minimum", YR_MINIMUM},
{"maximum", YR_MAXIMUM},
{"only", YR_ONLY},
{NULL, 0}
}
#define YR_MINIMUM
Definition: zic.c:264
#define YR_ONLY
Definition: zic.c:266
#define NULL
Definition: c.h:226
#define YR_MAXIMUM
Definition: zic.c:265

Definition at line 349 of file zic.c.

bool errors
static

Definition at line 165 of file zic.c.

const char* filename
static

Definition at line 167 of file zic.c.

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

zic_t gmtoffs[TZ_MAX_TYPES]
static

Definition at line 377 of file zic.c.

char isdsts[TZ_MAX_TYPES]
static

Definition at line 378 of file zic.c.

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_SATURDAY
Definition: tzfile.h:119
#define TM_THURSDAY
Definition: tzfile.h:117
#define TM_FRIDAY
Definition: tzfile.h:118
#define TM_SUNDAY
Definition: tzfile.h:113
#define NULL
Definition: c.h:226
#define TM_WEDNESDAY
Definition: tzfile.h:116
#define TM_TUESDAY
Definition: tzfile.h:115
#define TM_MONDAY
Definition: tzfile.h:114

Definition at line 332 of file zic.c.

const char* lcltime
static

Definition at line 561 of file zic.c.

struct lookup const leap_types[]
static
Initial value:
= {
{"Rolling", true},
{"Stationary", false},
{NULL, 0}
}
#define NULL
Definition: c.h:226

Definition at line 356 of file zic.c.

int leapcnt
static

Definition at line 168 of file zic.c.

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

zic_t leapmaxyear
static

Definition at line 171 of file zic.c.

zic_t leapminyear
static

Definition at line 170 of file zic.c.

const char* leapsec
static

Definition at line 563 of file zic.c.

bool leapseen
static

Definition at line 169 of file zic.c.

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 362 of file zic.c.

const int len_years[2]
static
Initial value:
= {
}
#define DAYSPERLYEAR
Definition: tzfile.h:108
#define DAYSPERNYEAR
Definition: tzfile.h:107

Definition at line 367 of file zic.c.

struct lookup const line_codes[]
static
Initial value:
= {
{"Rule", LC_RULE},
{"Zone", LC_ZONE},
{"Link", LC_LINK},
{"Leap", LC_LEAP},
{NULL, 0}
}
#define LC_LEAP
Definition: zic.c:194
#define LC_LINK
Definition: zic.c:193
#define LC_ZONE
Definition: zic.c:192
#define NULL
Definition: c.h:226
#define LC_RULE
Definition: zic.c:191

Definition at line 297 of file zic.c.

lineno_t linenum
static

Definition at line 172 of file zic.c.

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

struct link* links
static

Definition at line 284 of file zic.c.

int max_abbrvar_len = PERCENT_Z_LEN_BOUND
static

Definition at line 173 of file zic.c.

Referenced by outzone().

int max_format_len
static

Definition at line 174 of file zic.c.

zic_t const max_time = MAXVAL(zic_t, TIME_T_BITS_IN_FILE)
static

Definition at line 967 of file zic.c.

Referenced by rpytime(), and tadd().

zic_t max_year
static

Definition at line 175 of file zic.c.

Referenced by outzone().

zic_t const min_time = MINVAL(zic_t, TIME_T_BITS_IN_FILE)
static

Definition at line 966 of file zic.c.

Referenced by rpytime(), and tadd().

zic_t min_year
static

Definition at line 176 of file zic.c.

struct lookup const mon_names[]
static
Initial value:
= {
{"January",