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 <sys/stat.h>
#include <time.h>
#include "pg_getopt.h"
#include "private.h"
#include "tzfile.h"
Include dependency graph for zic.c:

Go to the source code of this file.

Data Structures

struct  rule
 
struct  zone
 
struct  link
 
struct  lookup
 
struct  attype
 

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 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 bool ciprefix (char const *abbr, char const *word)
 
static void time_overflow (void)
 

Variables

static ptrdiff_t const PTRDIFF_MAX = MAXVAL(ptrdiff_t, TYPE_BIT(ptrdiff_t))
 
static int charcnt
 
static bool errors
 
static bool warnings
 
static const char * filename
 
static int leapcnt
 
static bool leapseen
 
static zic_t leapminyear
 
static zic_t leapmaxyear
 
static lineno_t linenum
 
static int max_abbrvar_len = PERCENT_Z_LEN_BOUND
 
static int max_format_len
 
static zic_t max_year
 
static zic_t min_year
 
static bool noise
 
static bool print_abbrevs
 
static zic_t print_cutoff
 
static const char * rfilename
 
static lineno_t rlinenum
 
static const char * progname
 
static ptrdiff_t timecnt
 
static ptrdiff_t timecnt_alloc
 
static int typecnt
 
static struct rulerules
 
static ptrdiff_t nrules
 
static ptrdiff_t nrules_alloc
 
static struct zonezones
 
static ptrdiff_t nzones
 
static ptrdiff_t nzones_alloc
 
static struct linklinks
 
static ptrdiff_t nlinks
 
static ptrdiff_t nlinks_alloc
 
static struct lookup const zi_line_codes []
 
static struct lookup const leap_line_codes []
 
static struct lookup const mon_names []
 
static struct lookup const wday_names []
 
static struct lookup const lasts []
 
static struct lookup const begin_years []
 
static struct lookup const end_years []
 
static struct lookup const leap_types []
 
static const int len_months [2][MONSPERYEAR]
 
static const int len_years [2]
 
static struct attypeattypes
 
static zic_t 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 1000 of file zic.c.

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

Definition at line 88 of file zic.c.

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

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

Definition at line 89 of file zic.c.

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

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

Definition at line 90 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 195 of file zic.c.

Referenced by infile().

#define LC_LINK   2

Definition at line 194 of file zic.c.

Referenced by infile().

#define LC_RULE   0

Definition at line 192 of file zic.c.

Referenced by infile().

#define LC_ZONE   1

Definition at line 193 of file zic.c.

Referenced by infile().

#define LDAYSPERWEEK   ((zic_t) DAYSPERWEEK)

Referenced by rpytime().

#define LEAP_FIELDS   7

Definition at line 259 of file zic.c.

Referenced by inleap().

#define LF_FROM   1

Definition at line 245 of file zic.c.

Referenced by inlink().

#define LF_TO   2

Definition at line 246 of file zic.c.

Referenced by inlink().

#define LINK_FIELDS   3

Definition at line 247 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 39 of file zic.c.

Referenced by hardlinkerr().

#define LP_CORR   5

Definition at line 257 of file zic.c.

Referenced by inleap().

#define LP_DAY   3

Definition at line 255 of file zic.c.

Referenced by inleap().

#define LP_MONTH   2

Definition at line 254 of file zic.c.

Referenced by inleap().

#define LP_ROLL   6

Definition at line 258 of file zic.c.

Referenced by inleap().

#define LP_TIME   4

Definition at line 256 of file zic.c.

Referenced by inleap().

#define LP_YEAR   1

Definition at line 253 of file zic.c.

Referenced by inleap().

#define MKDIR_UMASK   0755

Definition at line 35 of file zic.c.

Referenced by mkdirs().

#define RF_ABBRVAR   9

Definition at line 238 of file zic.c.

Referenced by inrule().

#define RF_COMMAND   4

Definition at line 233 of file zic.c.

Referenced by inrule().

#define RF_DAY   6

Definition at line 235 of file zic.c.

Referenced by inrule().

#define RF_HIYEAR   3

Definition at line 232 of file zic.c.

Referenced by inrule().

#define RF_LOYEAR   2

Definition at line 231 of file zic.c.

Referenced by inrule().

#define RF_MONTH   5

Definition at line 234 of file zic.c.

Referenced by inrule().

#define RF_NAME   1

Definition at line 230 of file zic.c.

Referenced by inrule().

#define RF_STDOFF   8

Definition at line 237 of file zic.c.

Referenced by inrule().

#define RF_TOD   7

Definition at line 236 of file zic.c.

Referenced by inrule().

#define RULE_FIELDS   10

Definition at line 239 of file zic.c.

Referenced by inrule().

#define TIME_T_BITS_IN_FILE   64

Definition at line 972 of file zic.c.

#define YR_MAXIMUM   1

Definition at line 266 of file zic.c.

Referenced by rulesub().

#define YR_MINIMUM   0

Definition at line 265 of file zic.c.

Referenced by rulesub().

#define YR_ONLY   2

Definition at line 267 of file zic.c.

Referenced by rulesub().

#define ZF_FORMAT   4

Definition at line 204 of file zic.c.

Referenced by inzsub().

#define ZF_GMTOFF   2

Definition at line 202 of file zic.c.

Referenced by inzsub().

#define ZF_NAME   1

Definition at line 201 of file zic.c.

Referenced by inzone(), and inzsub().

#define ZF_RULE   3

Definition at line 203 of file zic.c.

Referenced by inzsub().

#define ZF_TILDAY   7

Definition at line 207 of file zic.c.

Referenced by inzsub().

#define ZF_TILMONTH   6

Definition at line 206 of file zic.c.

Referenced by inzsub().

#define ZF_TILTIME   8

Definition at line 208 of file zic.c.

Referenced by inzsub().

#define ZF_TILYEAR   5

Definition at line 205 of file zic.c.

Referenced by inzsub().

#define ZFC_FORMAT   2

Definition at line 218 of file zic.c.

Referenced by inzsub().

#define ZFC_GMTOFF   0

Definition at line 216 of file zic.c.

Referenced by inzsub().

#define ZFC_RULE   1

Definition at line 217 of file zic.c.

Referenced by inzsub().

#define ZFC_TILDAY   5

Definition at line 221 of file zic.c.

Referenced by inzsub().

#define ZFC_TILMONTH   4

Definition at line 220 of file zic.c.

Referenced by inzsub().

#define ZFC_TILTIME   6

Definition at line 222 of file zic.c.

Referenced by inzsub().

#define ZFC_TILYEAR   3

Definition at line 219 of file zic.c.

Referenced by inzsub().

#define ZIC_MAX   PG_INT64_MAX

Definition at line 25 of file zic.c.

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

#define ZIC_MAX_ABBR_LEN_WO_WARN   6

Definition at line 28 of file zic.c.

Referenced by newabbr().

#define ZIC_MIN   PG_INT64_MIN

Definition at line 24 of file zic.c.

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

#define ZIC_VERSION   '3'

Definition at line 21 of file zic.c.

Referenced by outzone().

#define ZIC_VERSION_PRE_2013   '2'

Definition at line 20 of file zic.c.

Referenced by outzone().

#define ZONE_MAXFIELDS   9

Definition at line 210 of file zic.c.

Referenced by inzone().

#define ZONE_MINFIELDS   5

Definition at line 209 of file zic.c.

#define ZONEC_MAXFIELDS   7

Definition at line 224 of file zic.c.

Referenced by inzcont().

#define ZONEC_MINFIELDS   3

Definition at line 223 of file zic.c.

Typedef Documentation

Definition at line 53 of file zic.c.

typedef int64 zic_t

Definition at line 23 of file zic.c.

Enumeration Type Documentation

anonymous enum
Enumerator
PERCENT_Z_LEN_BOUND 

Definition at line 152 of file zic.c.

153 {
154 PERCENT_Z_LEN_BOUND = sizeof "+995959" - 1};
anonymous enum
Enumerator
WORK_AROUND_QTBUG_53071 

Definition at line 161 of file zic.c.

anonymous enum
Enumerator
WORK_AROUND_GNOME_BUG_730332 

Definition at line 1011 of file zic.c.

anonymous enum
Enumerator
YEAR_BY_YEAR_ZONE 

Definition at line 2507 of file zic.c.

2508 {
2509 YEAR_BY_YEAR_ZONE = 1};

Function Documentation

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

Definition at line 2282 of file zic.c.

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

Referenced by doabbr().

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

Definition at line 3025 of file zic.c.

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

Referenced by outzone().

3026 {
3027  if (starttime <= early_time
3028  || (timecnt == 1 && attypes[0].at < early_time))
3029  {
3030  gmtoffs[0] = gmtoffs[type];
3031  isdsts[0] = isdsts[type];
3032  ttisstds[0] = ttisstds[type];
3033  ttisgmts[0] = ttisgmts[type];
3034  if (abbrinds[type] != 0)
3035  strcpy(chars, &chars[abbrinds[type]]);
3036  abbrinds[0] = 0;
3037  charcnt = strlen(chars) + 1;
3038  typecnt = 1;
3039  timecnt = 0;
3040  type = 0;
3041  }
3043  attypes[timecnt].at = starttime;
3044  attypes[timecnt].dontmerge = false;
3045  attypes[timecnt].type = type;
3046  ++timecnt;
3047 }
static bool ttisstds[TZ_MAX_TYPES]
Definition: zic.c:384
static int typecnt
Definition: zic.c:186
static zic_t gmtoffs[TZ_MAX_TYPES]
Definition: zic.c:381
static unsigned char abbrinds[TZ_MAX_TYPES]
Definition: zic.c:383
unsigned char type
Definition: zic.c:379
static char isdsts[TZ_MAX_TYPES]
Definition: zic.c:382
static bool ttisgmts[TZ_MAX_TYPES]
Definition: zic.c:385
static const zic_t early_time
Definition: zic.c:1015
static void * growalloc(void *ptr, size_t itemsize, ptrdiff_t nitems, ptrdiff_t *nitems_alloc)
Definition: zic.c:437
zic_t at
Definition: zic.c:377
static ptrdiff_t timecnt_alloc
Definition: zic.c:185
static struct attype * attypes
static ptrdiff_t timecnt
Definition: zic.c:184
static int charcnt
Definition: zic.c:165
bool dontmerge
Definition: zic.c:378
static char chars[TZ_MAX_CHARS]
Definition: zic.c:386
static int addtype ( zic_t  gmtoff,
char const *  abbr,
bool  isdst,
bool  ttisstd,
bool  ttisgmt 
)
static

Definition at line 3050 of file zic.c.

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

Referenced by outzone(), and writezone().

3051 {
3052  int i,
3053  j;
3054 
3055  /*
3056  * See if there's already an entry for this zone type. If so, just return
3057  * its index.
3058  */
3059  for (i = 0; i < typecnt; ++i)
3060  {
3061  if (gmtoff == gmtoffs[i] && isdst == isdsts[i] &&
3062  strcmp(abbr, &chars[abbrinds[i]]) == 0 &&
3063  ttisstd == ttisstds[i] &&
3064  ttisgmt == ttisgmts[i])
3065  return i;
3066  }
3067 
3068  /*
3069  * There isn't one; add a new one, unless there are already too many.
3070  */
3071  if (typecnt >= TZ_MAX_TYPES)
3072  {
3073  error(_("too many local time types"));
3074  exit(EXIT_FAILURE);
3075  }
3076  if (!(-1L - 2147483647L <= gmtoff && gmtoff <= 2147483647L))
3077  {
3078  error(_("UT offset out of range"));
3079  exit(EXIT_FAILURE);
3080  }
3081  gmtoffs[i] = gmtoff;
3082  isdsts[i] = isdst;
3083  ttisstds[i] = ttisstd;
3084  ttisgmts[i] = ttisgmt;
3085 
3086  for (j = 0; j < charcnt; ++j)
3087  if (strcmp(&chars[j], abbr) == 0)
3088  break;
3089  if (j == charcnt)
3090  newabbr(abbr);
3091  abbrinds[i] = j;
3092  ++typecnt;
3093  return i;
3094 }
static bool ttisstds[TZ_MAX_TYPES]
Definition: zic.c:384
static int typecnt
Definition: zic.c:186
static zic_t gmtoffs[TZ_MAX_TYPES]
Definition: zic.c:381
static unsigned char abbrinds[TZ_MAX_TYPES]
Definition: zic.c:383
static char isdsts[TZ_MAX_TYPES]
Definition: zic.c:382
static bool ttisgmts[TZ_MAX_TYPES]
Definition: zic.c:385
static int charcnt
Definition: zic.c:165
#define TZ_MAX_TYPES
Definition: tzfile.h:96
static void newabbr(const char *abbr)
Definition: zic.c:3629
int i
#define EXIT_FAILURE
Definition: settings.h:152
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:489
static char chars[TZ_MAX_CHARS]
Definition: zic.c:386
#define _(x)
Definition: elog.c:84
static void adjleap ( void  )
static

Definition at line 3126 of file zic.c.

References _, error(), EXIT_FAILURE, i, leapcnt, SECSPERDAY, and tadd().

Referenced by main().

3127 {
3128  int i;
3129  zic_t last = 0;
3130  zic_t prevtrans = 0;
3131 
3132  /*
3133  * propagate leap seconds forward
3134  */
3135  for (i = 0; i < leapcnt; ++i)
3136  {
3137  if (trans[i] - prevtrans < 28 * SECSPERDAY)
3138  {
3139  error(_("Leap seconds too close together"));
3140  exit(EXIT_FAILURE);
3141  }
3142  prevtrans = trans[i];
3143  trans[i] = tadd(trans[i], last);
3144  last = corr[i] += last;
3145  }
3146 }
static zic_t corr[TZ_MAX_LEAPS]
Definition: zic.c:388
#define SECSPERDAY
Definition: private.h:97
static zic_t tadd(zic_t t1, zic_t t2)
Definition: zic.c:3502
static int leapcnt
Definition: zic.c:169
int64 zic_t
Definition: zic.c:23
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:387
int i
#define EXIT_FAILURE
Definition: settings.h:152
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:489
#define _(x)
Definition: elog.c:84
static void associate ( void  )
static

Definition at line 1073 of file zic.c.

References _, eat(), error(), EXIT_FAILURE, gethms(), i, nrules, 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().

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

Definition at line 1850 of file zic.c.

Referenced by writezone().

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

Definition at line 3381 of file zic.c.

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

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

3382 {
3383  const struct lookup *foundlp;
3384  const struct lookup *lp;
3385 
3386  if (word == NULL || table == NULL)
3387  return NULL;
3388 
3389  /*
3390  * If TABLE is LASTS and the word starts with "last" followed by a
3391  * non-'-', skip the "last" and look in WDAY_NAMES instead. Warn about any
3392  * usage of the undocumented prefix "last-".
3393  */
3394  if (table == lasts && ciprefix("last", word) && word[4])
3395  {
3396  if (word[4] == '-')
3397  warning(_("\"%s\" is undocumented; use \"last%s\" instead"),
3398  word, word + 5);
3399  else
3400  {
3401  word += 4;
3402  table = wday_names;
3403  }
3404  }
3405 
3406  /*
3407  * Look for exact match.
3408  */
3409  for (lp = table; lp->l_word != NULL; ++lp)
3410  if (ciequal(word, lp->l_word))
3411  return lp;
3412 
3413  /*
3414  * Look for inexact match.
3415  */
3416  foundlp = NULL;
3417  for (lp = table; lp->l_word != NULL; ++lp)
3418  if (ciprefix(word, lp->l_word))
3419  {
3420  if (foundlp == NULL)
3421  foundlp = lp;
3422  else
3423  return NULL; /* multiple inexact matches */
3424  }
3425 
3426  /* Warn about any backward-compatibility issue with pre-2017c zic. */
3427  if (foundlp)
3428  {
3429  bool pre_2017c_match = false;
3430 
3431  for (lp = table; lp->l_word; lp++)
3432  if (itsabbr(word, lp->l_word))
3433  {
3434  if (pre_2017c_match)
3435  {
3436  warning(_("\"%s\" is ambiguous in pre-2017c zic"), word);
3437  break;
3438  }
3439  pre_2017c_match = true;
3440  }
3441  }
3442 
3443  return foundlp;
3444 }
static bool ciprefix(char const *abbr, char const *word)
Definition: zic.c:3370
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:500
Definition: zic.c:289
static bool ciequal(const char *ap, const char *bp)
Definition: zic.c:3344
const char * l_word
Definition: zic.c:291
static void word(struct vars *, int, struct state *, struct state *)
Definition: regcomp.c:1243
static struct lookup const lasts[]
Definition: zic.c:336
static struct lookup const wday_names[]
Definition: zic.c:325
#define _(x)
Definition: elog.c:84
static bool itsabbr(const char *abbr, const char *word)
Definition: zic.c:3353
static void change_directory ( char const *  dir)
static

Definition at line 545 of file zic.c.

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

Referenced by main().

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

Definition at line 3344 of file zic.c.

References lowerit().

Referenced by byword().

3345 {
3346  while (lowerit(*ap) == lowerit(*bp++))
3347  if (*ap++ == '\0')
3348  return true;
3349  return false;
3350 }
static char lowerit(char)
Definition: zic.c:3281
static bool ciprefix ( char const *  abbr,
char const *  word 
)
static

Definition at line 3370 of file zic.c.

References lowerit().

Referenced by byword().

3371 {
3372  do
3373  if (!*abbr)
3374  return true;
3375  while (lowerit(*abbr++) == lowerit(*word++));
3376 
3377  return false;
3378 }
static char lowerit(char)
Definition: zic.c:3281
static void word(struct vars *, int, struct state *, struct state *)
Definition: regcomp.c:1243
static void close_file ( FILE *  stream,
char const *  dir,
char const *  name 
)
static

Definition at line 512 of file zic.c.

References _, EXIT_FAILURE, and strerror().

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

513 {
514  char const *e = (ferror(stream) ? _("I/O error")
515  : fclose(stream) != 0 ? strerror(errno) : NULL);
516 
517  if (e)
518  {
519  fprintf(stderr, "%s: %s%s%s%s%s\n", progname,
520  dir ? dir : "", dir ? "/" : "",
521  name ? name : "", name ? ": " : "",
522  e);
523  exit(EXIT_FAILURE);
524  }
525 }
static const char * progname
Definition: zic.c:183
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:152
#define _(x)
Definition: elog.c:84
static bool componentcheck ( char const *  name,
char const *  component,
char const *  component_end 
)
static

Definition at line 732 of file zic.c.

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

Referenced by namecheck().

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

Definition at line 1810 of file zic.c.

References i.

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

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

Definition at line 1821 of file zic.c.

References i.

Referenced by puttzcode64().

1822 {
1823  int i;
1824  int shift;
1825  unsigned char *const b = (unsigned char *) buf;
1826 
1827  for (i = 0, shift = 56; i < 8; ++i, shift -= 8)
1828  b[i] = val >> shift;
1829 }
static char * buf
Definition: pg_test_fsync.c:67
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 2326 of file zic.c.

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

Referenced by outzone(), and stringzone().

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

Definition at line 877 of file zic.c.

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

Referenced by main().

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

Definition at line 467 of file zic.c.

References eats().

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

468 {
469  eats(name, num, NULL, -1);
470 }
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:458
static void eats ( char const *  name,
lineno_t  num,
char const *  rname,
lineno_t  rnum 
)
static

Definition at line 458 of file zic.c.

References name.

Referenced by eat(), and outzone().

459 {
460  filename = name;
461  linenum = num;
462  rfilename = rname;
463  rlinenum = rnum;
464 }
static lineno_t rlinenum
Definition: zic.c:182
static const char * filename
Definition: zic.c:168
static lineno_t linenum
Definition: zic.c:173
static const char * rfilename
Definition: zic.c:181
const char * name
Definition: encode.c:521
static char* ecpyalloc ( char const *  str)
static

Definition at line 431 of file zic.c.

References memcheck().

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

432 {
433  return memcheck(strdup(str));
434 }
static void * memcheck(void *ptr)
Definition: zic.c:411
static void* emalloc ( size_t  size)
static

Definition at line 419 of file zic.c.

References malloc, and memcheck().

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

420 {
421  return memcheck(malloc(size));
422 }
#define malloc(a)
Definition: header.h:50
static void * memcheck(void *ptr)
Definition: zic.c:411
static void* erealloc ( void *  ptr,
size_t  size 
)
static

Definition at line 425 of file zic.c.

References memcheck(), and realloc.

Referenced by growalloc().

426 {
427  return memcheck(realloc(ptr, size));
428 }
#define realloc(a, b)
Definition: header.h:60
static void * memcheck(void *ptr)
Definition: zic.c:411
static void error ( const char *  string,
  ... 
)
static

Definition at line 489 of file zic.c.

References generate_unaccent_rules::args, and verror().

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

490 {
491  va_list args;
492 
493  va_start(args, string);
494  verror(string, args);
495  va_end(args);
496  errors = true;
497 }
static bool errors
Definition: zic.c:166
static void verror(const char *string, va_list args) pg_attribute_printf(1
Definition: zic.c:473
static char ** getfields ( char *  buf)
static

Definition at line 3447 of file zic.c.

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

Referenced by infile().

3448 {
3449  char *dp;
3450  char **array;
3451  int nsubs;
3452 
3453  if (cp == NULL)
3454  return NULL;
3455  array = emalloc(size_product(strlen(cp) + 1, sizeof *array));
3456  nsubs = 0;
3457  for (;;)
3458  {
3459  while (is_space(*cp))
3460  ++cp;
3461  if (*cp == '\0' || *cp == '#')
3462  break;
3463  array[nsubs++] = dp = cp;
3464  do
3465  {
3466  if ((*dp = *cp++) != '"')
3467  ++dp;
3468  else
3469  while ((*dp = *cp++) != '"')
3470  if (*dp != '\0')
3471  ++dp;
3472  else
3473  {
3474  error(_("Odd number of quotation marks"));
3475  exit(EXIT_FAILURE);
3476  }
3477  } while (*cp && *cp != '#' && !is_space(*cp));
3478  if (is_space(*cp))
3479  ++cp;
3480  *dp = '\0';
3481  }
3482  array[nsubs] = NULL;
3483  return array;
3484 }
static bool is_space(char a)
Definition: zic.c:3198
#define EXIT_FAILURE
Definition: settings.h:152
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:489
#define _(x)
Definition: elog.c:84
static size_t size_product(size_t nitems, size_t itemsize)
Definition: zic.c:403
static void * emalloc(size_t size)
Definition: zic.c:419
static zic_t gethms ( const char *  string,
const char *  errstring,
bool  signable 
)
static

Definition at line 1260 of file zic.c.

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

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

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

Definition at line 437 of file zic.c.

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

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

438 {
439  if (nitems < *nitems_alloc)
440  return ptr;
441  else
442  {
443  ptrdiff_t nitems_max = PTRDIFF_MAX - WORK_AROUND_QTBUG_53071;
444  ptrdiff_t amax = nitems_max < SIZE_MAX ? nitems_max : SIZE_MAX;
445 
446  if ((amax - 1) / 3 * 2 < *nitems_alloc)
447  memory_exhausted(_("integer overflow"));
448  *nitems_alloc += (*nitems_alloc >> 1) + 1;
449  return erealloc(ptr, size_product(*nitems_alloc, itemsize));
450  }
451 }
#define SIZE_MAX
Definition: c.h:336
static ptrdiff_t const PTRDIFF_MAX
Definition: zic.c:45
static void memory_exhausted(const char *msg) pg_attribute_noreturn()
Definition: zic.c:396
#define _(x)
Definition: elog.c:84
static size_t size_product(size_t nitems, size_t itemsize)
Definition: zic.c:403
static void * erealloc(void *ptr, size_t size)
Definition: zic.c:425
static int hardlinkerr ( char const *  from,
char const *  to 
)
static

Definition at line 869 of file zic.c.

References linkat.

Referenced by dolink().

870 {
871  int r = linkat(AT_FDCWD, from, AT_FDCWD, to, AT_SYMLINK_FOLLOW);
872 
873  return r == 0 ? 0 : errno;
874 }
#define linkat(fromdir, from, todir, to, flag)
Definition: zic.c:39
static void infile ( const char *  filename)
static

Definition at line 1159 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, strerror(), and zi_line_codes.

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

1160 {
1161  FILE *fp;
1162  char **fields;
1163  char *cp;
1164  const struct lookup *lp;
1165  int nfields;
1166  bool wantcont;
1167  lineno_t num;
1168  char buf[BUFSIZ];
1169 
1170  if (strcmp(name, "-") == 0)
1171  {
1172  name = _("standard input");
1173  fp = stdin;
1174  }
1175  else if ((fp = fopen(name, "r")) == NULL)
1176  {
1177  const char *e = strerror(errno);
1178 
1179  fprintf(stderr, _("%s: Cannot open %s: %s\n"),
1180  progname, name, e);
1181  exit(EXIT_FAILURE);
1182  }
1183  wantcont = false;
1184  for (num = 1;; ++num)
1185  {
1186  eat(name, num);
1187  if (fgets(buf, sizeof buf, fp) != buf)
1188  break;
1189  cp = strchr(buf, '\n');
1190  if (cp == NULL)
1191  {
1192  error(_("line too long"));
1193  exit(EXIT_FAILURE);
1194  }
1195  *cp = '\0';
1196  fields = getfields(buf);
1197  nfields = 0;
1198  while (fields[nfields] != NULL)
1199  {
1200  static char nada;
1201 
1202  if (strcmp(fields[nfields], "-") == 0)
1203  fields[nfields] = &nada;
1204  ++nfields;
1205  }
1206  if (nfields == 0)
1207  {
1208  /* nothing to do */
1209  }
1210  else if (wantcont)
1211  wantcont = inzcont(fields, nfields);
1212  else
1213  {
1214  struct lookup const *line_codes
1216 
1217  lp = byword(fields[0], line_codes);
1218  if (lp == NULL)
1219  error(_("input line of unknown type"));
1220  else
1221  switch (lp->l_value)
1222  {
1223  case LC_RULE:
1224  inrule(fields, nfields);
1225  wantcont = false;
1226  break;
1227  case LC_ZONE:
1228  wantcont = inzone(fields, nfields);
1229  break;
1230  case LC_LINK:
1231  inlink(fields, nfields);
1232  wantcont = false;
1233  break;
1234  case LC_LEAP:
1235  inleap(fields, nfields);
1236  wantcont = false;
1237  break;
1238  default: /* "cannot happen" */
1239  fprintf(stderr,
1240  _("%s: panic: Invalid l_value %d\n"),
1241  progname, lp->l_value);
1242  exit(EXIT_FAILURE);
1243  }
1244  }
1245  free(fields);
1246  }
1247  close_file(fp, NULL, filename);
1248  if (wantcont)
1249  error(_("expected continuation line not found"));
1250 }
static struct lookup const zi_line_codes[]
Definition: zic.c:298
static struct lookup const leap_line_codes[]
Definition: zic.c:304
static void inrule(char **fields, int nfields)
Definition: zic.c:1313
#define LC_LEAP
Definition: zic.c:195
static const char * leapsec
Definition: zic.c:568
const int l_value
Definition: zic.c:292
static const char * filename
Definition: zic.c:168
static void inleap(char **fields, int nfields)
Definition: zic.c:1489
static char ** getfields(char *buf)
Definition: zic.c:3447
static bool inzcont(char **fields, int nfields)
Definition: zic.c:1379
static char * buf
Definition: pg_test_fsync.c:67
Definition: zic.c:289
#define LC_LINK
Definition: zic.c:194
static void eat(char const *name, lineno_t num)
Definition: zic.c:467
#define LC_ZONE
Definition: zic.c:193
static const char * progname
Definition: zic.c:183
#define free(a)
Definition: header.h:65
static bool inzone(char **fields, int nfields)
Definition: zic.c:1341
static void inlink(char **fields, int nfields)
Definition: zic.c:1609
static void close_file(FILE *stream, char const *dir, char const *name)
Definition: zic.c:512
static struct lookup const * byword(const char *string, const struct lookup *lp)
Definition: zic.c:3381
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:152
int lineno_t
Definition: zic.c:53
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:489
#define LC_RULE
Definition: zic.c:192
#define _(x)
Definition: elog.c:84
static void inleap ( char **  fields,
int  nfields 
)
static

Definition at line 1489 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, oadd(), SECSPERDAY, tadd(), and TM_JANUARY.

Referenced by infile().

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

Definition at line 1609 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().

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

Definition at line 1313 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().

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

Definition at line 1379 of file zic.c.

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

Referenced by infile().

1380 {
1381  if (nfields < ZONEC_MINFIELDS || nfields > ZONEC_MAXFIELDS)
1382  {
1383  error(_("wrong number of fields on Zone continuation line"));
1384  return false;
1385  }
1386  return inzsub(fields, nfields, true);
1387 }
#define ZONEC_MAXFIELDS
Definition: zic.c:224
static bool inzsub(char **, int, bool)
Definition: zic.c:1390
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:489
#define _(x)
Definition: elog.c:84
static bool inzone ( char **  fields,
int  nfields 
)
static

Definition at line 1341 of file zic.c.

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

Referenced by infile().

1342 {
1343  ptrdiff_t i;
1344 
1345  if (nfields < ZONE_MINFIELDS || nfields > ZONE_MAXFIELDS)
1346  {
1347  error(_("wrong number of fields on Zone line"));
1348  return false;
1349  }
1350  if (strcmp(fields[ZF_NAME], TZDEFAULT) == 0 && lcltime != NULL)
1351  {
1352  error(
1353  _("\"Zone %s\" line and -l option are mutually exclusive"),
1354  TZDEFAULT);
1355  return false;
1356  }
1357  if (strcmp(fields[ZF_NAME], TZDEFRULES) == 0 && psxrules != NULL)
1358  {
1359  error(
1360  _("\"Zone %s\" line and -p option are mutually exclusive"),
1361  TZDEFRULES);
1362  return false;
1363  }
1364  for (i = 0; i < nzones; ++i)
1365  if (zones[i].z_name != NULL &&
1366  strcmp(zones[i].z_name, fields[ZF_NAME]) == 0)
1367  {
1368  error(_("duplicate zone name %s"
1369  " (file \"%s\", line %d)"),
1370  fields[ZF_NAME],
1371  zones[i].z_filename,
1372  zones[i].z_linenum);
1373  return false;
1374  }
1375  return inzsub(fields, nfields, false);
1376 }
#define TZDEFAULT
Definition: tzfile.h:24
#define ZF_NAME
Definition: zic.c:201
static ptrdiff_t nzones
Definition: zic.c:274
static const char * psxrules
Definition: zic.c:565
static bool inzsub(char **, int, bool)
Definition: zic.c:1390
#define ZONE_MAXFIELDS
Definition: zic.c:210
static const char * lcltime
Definition: zic.c:566
#define TZDEFRULES
Definition: tzfile.h:25
static struct zone * zones
Definition: zic.c:273
int i
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:489
#define _(x)
Definition: elog.c:84
static bool inzsub ( char **  fields,
int  nfields,
bool  iscont 
)
static

Definition at line 1390 of file zic.c.

References _, ecpyalloc(), error(), filename, gethms(), growalloc(), linenum, namecheck(), 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().

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

Definition at line 1859 of file zic.c.

Referenced by writezone().

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

Definition at line 3216 of file zic.c.

Referenced by doabbr(), and newabbr().

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

Definition at line 3198 of file zic.c.

Referenced by getfields().

3199 {
3200  switch (a)
3201  {
3202  default:
3203  return false;
3204  case ' ':
3205  case '\f':
3206  case '\n':
3207  case '\r':
3208  case '\t':
3209  case '\v':
3210  return true;
3211  }
3212 }
static bool itsabbr ( const char *  abbr,
const char *  word 
)
static

Definition at line 3353 of file zic.c.

References lowerit(), and word().

Referenced by byword().

3354 {
3355  if (lowerit(*abbr) != lowerit(*word))
3356  return false;
3357  ++word;
3358  while (*++abbr != '\0')
3359  do
3360  {
3361  if (*word == '\0')
3362  return false;
3363  } while (lowerit(*word++) != lowerit(*abbr));
3364  return true;
3365 }
static char lowerit(char)
Definition: zic.c:3281
static void word(struct vars *, int, struct state *, struct state *)
Definition: regcomp.c:1243
static bool itsdir ( char const *  name)
static

Definition at line 1021 of file zic.c.

References emalloc(), EOVERFLOW, and free.

Referenced by dolink(), and mkdirs().

1022 {
1023  struct stat st;
1024  int res = stat(name, &st);
1025 #ifdef S_ISDIR
1026  if (res == 0)
1027  return S_ISDIR(st.st_mode) != 0;
1028 #endif
1029  if (res == 0 || errno == EOVERFLOW)
1030  {
1031  size_t n = strlen(name);
1032  char *nameslashdot = emalloc(n + 3);
1033  bool dir;
1034 
1035  memcpy(nameslashdot, name, n);
1036  strcpy(&nameslashdot[n], &"/."[!(n && name[n - 1] != '/')]);
1037  dir = stat(nameslashdot, &st) == 0 || errno == EOVERFLOW;
1038  free(nameslashdot);
1039  return dir;
1040  }
1041  return false;
1042 }
#define free(a)
Definition: header.h:65
const char * name
Definition: encode.c:521
#define EOVERFLOW
Definition: private.h:38
static void * emalloc(size_t size)
Definition: zic.c:419
static bool itssymlink ( char const *  name)
static

Definition at line 1046 of file zic.c.

Referenced by dolink().

1047 {
1048 #ifdef HAVE_SYMLINK
1049  char c;
1050 
1051  return 0 <= readlink(name, &c, 1);
1052 #else
1053  return false;
1054 #endif
1055 }
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 3097 of file zic.c.

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

Referenced by inleap().

3098 {
3099  int i,
3100  j;
3101 
3102  if (leapcnt + (positive ? count : 1) > TZ_MAX_LEAPS)
3103  {
3104  error(_("too many leap seconds"));
3105  exit(EXIT_FAILURE);
3106  }
3107  for (i = 0; i < leapcnt; ++i)
3108  if (t <= trans[i])
3109  break;
3110  do
3111  {
3112  for (j = leapcnt; j > i; --j)
3113  {
3114  trans[j] = trans[j - 1];
3115  corr[j] = corr[j - 1];
3116  roll[j] = roll[j - 1];
3117  }
3118  trans[i] = t;
3119  corr[i] = positive ? 1 : -count;
3120  roll[i] = rolling;
3121  ++leapcnt;
3122  } while (positive && --count != 0);
3123 }
static zic_t corr[TZ_MAX_LEAPS]
Definition: zic.c:388
#define TZ_MAX_LEAPS
Definition: tzfile.h:101
static int leapcnt
Definition: zic.c:169
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:387
int i
#define EXIT_FAILURE
Definition: settings.h:152
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:489
#define _(x)
Definition: elog.c:84
static char roll[TZ_MAX_LEAPS]
Definition: zic.c:389
int link ( const char *  fromname,
const char *  toname 
)
static char lowerit ( char  a)
static

Definition at line 3281 of file zic.c.

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

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

Definition at line 572 of file zic.c.

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

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

Definition at line 411 of file zic.c.

References memory_exhausted(), and strerror().

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

412 {
413  if (ptr == NULL)
414  memory_exhausted(strerror(errno));
415  return ptr;
416 }
const char * strerror(int errnum)
Definition: strerror.c:19
static void memory_exhausted(const char *msg) pg_attribute_noreturn()
Definition: zic.c:396
static void memory_exhausted ( const char *  msg)
static

Definition at line 396 of file zic.c.

References _, and EXIT_FAILURE.

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

397 {
398  fprintf(stderr, _("%s: Memory exhausted: %s\n"), progname, msg);
399  exit(EXIT_FAILURE);
400 }
static const char * progname
Definition: zic.c:183
#define EXIT_FAILURE
Definition: settings.h:152
#define _(x)
Definition: elog.c:84
static void mkdirs ( char const *  argname,
bool  ancestors 
)
static

Definition at line 3667 of file zic.c.

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

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

3668 {
3669  char *name;
3670  char *cp;
3671 
3672  cp = name = ecpyalloc(argname);
3673 
3674  /*
3675  * On MS-Windows systems, do not worry about drive letters or backslashes,
3676  * as this should suffice in practice. Time zone names do not use drive
3677  * letters and backslashes. If the -d option of zic does not name an
3678  * already-existing directory, it can use slashes to separate the
3679  * already-existing ancestor prefix from the to-be-created subdirectories.
3680  */
3681 
3682  /* Do not mkdir a root directory, as it must exist. */
3683  while (*cp == '/')
3684  cp++;
3685 
3686  while (cp && ((cp = strchr(cp, '/')) || !ancestors))
3687  {
3688  if (cp)
3689  *cp = '\0';
3690 
3691  /*
3692  * Try to create it. It's OK if creation fails because the directory
3693  * already exists, perhaps because some other process just created it.
3694  * For simplicity do not check first whether it already exists, as
3695  * that is checked anyway if the mkdir fails.
3696  */
3697  if (mkdir(name, MKDIR_UMASK) != 0)
3698  {
3699  /*
3700  * For speed, skip itsdir if errno == EEXIST. Since mkdirs is
3701  * called only after open fails with ENOENT on a subfile, EEXIST
3702  * implies itsdir here.
3703  */
3704  int err = errno;
3705 
3706  if (err != EEXIST && !itsdir(name))
3707  {
3708  error(_("%s: Cannot create directory %s: %s"),
3709  progname, name, strerror(err));
3710  exit(EXIT_FAILURE);
3711  }
3712  }
3713  if (cp)
3714  *cp++ = '/';
3715  }
3716  free(name);
3717 }
static char * ecpyalloc(char const *str)
Definition: zic.c:431
#define mkdir(a, b)
Definition: win32.h:57
static bool itsdir(char const *)
Definition: zic.c:1021
static const char * progname
Definition: zic.c:183
#define free(a)
Definition: header.h:65
#define MKDIR_UMASK
Definition: zic.c:35
const char * name
Definition: encode.c:521
const char * strerror(int errnum)
Definition: strerror.c:19
#define EXIT_FAILURE
Definition: settings.h:152
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:489
#define _(x)
Definition: elog.c:84
static bool namecheck ( const char *  name)
static

Definition at line 776 of file zic.c.

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

Referenced by inlink(), and inzsub().

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

Definition at line 3629 of file zic.c.

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

Referenced by addtype().

3630 {
3631  int i;
3632 
3633  if (strcmp(string, GRANDPARENTED) != 0)
3634  {
3635  const char *cp;
3636  const char *mp;
3637 
3638  cp = string;
3639  mp = NULL;
3640  while (is_alpha(*cp) || ('0' <= *cp && *cp <= '9')
3641  || *cp == '-' || *cp == '+')
3642  ++cp;
3643  if (noise && cp - string < 3)
3644  mp = _("time zone abbreviation has fewer than 3 characters");
3645  if (cp - string > ZIC_MAX_ABBR_LEN_WO_WARN)
3646  mp = _("time zone abbreviation has too many characters");
3647  if (*cp != '\0')
3648  mp = _("time zone abbreviation differs from POSIX standard");
3649  if (mp != NULL)
3650  warning("%s (%s)", mp, string);
3651  }
3652  i = strlen(string) + 1;
3653  if (charcnt + i > TZ_MAX_CHARS)
3654  {
3655  error(_("too many, or too long, time zone abbreviations"));
3656  exit(EXIT_FAILURE);
3657  }
3658  strcpy(&chars[charcnt], string);
3659  charcnt += i;
3660 }
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:500
#define GRANDPARENTED
Definition: private.h:27
static bool is_alpha(char a)
Definition: zic.c:3216
char string[11]
Definition: preproc-type.c:46
#define ZIC_MAX_ABBR_LEN_WO_WARN
Definition: zic.c:28
#define TZ_MAX_CHARS
Definition: tzfile.h:98
static bool noise
Definition: zic.c:178
static int charcnt
Definition: zic.c:165
int i
#define EXIT_FAILURE
Definition: settings.h:152
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:489
static char chars[TZ_MAX_CHARS]
Definition: zic.c:386
#define _(x)
Definition: elog.c:84
static zic_t oadd ( zic_t  t1,
zic_t  t2 
)
static

Definition at line 3494 of file zic.c.

References time_overflow(), ZIC_MAX, and ZIC_MIN.

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

3495 {
3496  if (t1 < 0 ? t2 < ZIC_MIN - t1 : ZIC_MAX - t1 < t2)
3497  time_overflow();
3498  return t1 + t2;
3499 }
#define ZIC_MAX
Definition: zic.c:25
#define ZIC_MIN
Definition: zic.c:24
static void time_overflow(void)
Definition: zic.c:3487
static void outzone ( const struct zone zp,
ptrdiff_t  ntzones 
)
static

Definition at line 2647 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, 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().

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

Definition at line 1832 of file zic.c.

References buf, and convert().

Referenced by writezone().

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

Definition at line 1841 of file zic.c.

References buf, and convert64().

Referenced by writezone().

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

Definition at line 1066 of file zic.c.

Referenced by associate().

1067 {
1068  return strcmp(((const struct rule *) cp1)->r_name,
1069  ((const struct rule *) cp2)->r_name);
1070 }
Definition: localtime.c:78
static zic_t rpytime ( const struct rule rp,
zic_t  wantedy 
)
static

Definition at line 3531 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().

3532 {
3533  int m,
3534  i;
3535  zic_t dayoff; /* with a nod to Margaret O. */
3536  zic_t t,
3537  y;
3538 
3539  if (wantedy == ZIC_MIN)
3540  return min_time;
3541  if (wantedy == ZIC_MAX)
3542  return max_time;
3543  dayoff = 0;
3544  m = TM_JANUARY;
3545  y = EPOCH_YEAR;
3546  while (wantedy != y)
3547  {
3548  if (wantedy > y)
3549  {
3550  i = len_years[isleap(y)];
3551  ++y;
3552  }
3553  else
3554  {
3555  --y;
3556  i = -len_years[isleap(y)];
3557  }
3558  dayoff = oadd(dayoff, i);
3559  }
3560  while (m != rp->r_month)
3561  {
3562  i = len_months[isleap(y)][m];
3563  dayoff = oadd(dayoff, i);
3564  ++m;
3565  }
3566  i = rp->r_dayofmonth;
3567  if (m == TM_FEBRUARY && i == 29 && !isleap(y))
3568  {
3569  if (rp->r_dycode == DC_DOWLEQ)
3570  --i;
3571  else
3572  {
3573  error(_("use of 2/29 in non leap-year"));
3574  exit(EXIT_FAILURE);
3575  }
3576  }
3577  --i;
3578  dayoff = oadd(dayoff, i);
3579  if (rp->r_dycode == DC_DOWGEQ || rp->r_dycode == DC_DOWLEQ)
3580  {
3581  zic_t wday;
3582 
3583 #define LDAYSPERWEEK ((zic_t) DAYSPERWEEK)
3584  wday = EPOCH_WDAY;
3585 
3586  /*
3587  * Don't trust mod of negative numbers.
3588  */
3589  if (dayoff >= 0)
3590  wday = (wday + dayoff) % LDAYSPERWEEK;
3591  else
3592  {
3593  wday -= ((-dayoff) % LDAYSPERWEEK);
3594  if (wday < 0)
3595  wday += LDAYSPERWEEK;
3596  }
3597  while (wday != rp->r_wday)
3598  if (rp->r_dycode == DC_DOWGEQ)
3599  {
3600  dayoff = oadd(dayoff, 1);
3601  if (++wday >= LDAYSPERWEEK)
3602  wday = 0;
3603  ++i;
3604  }
3605  else
3606  {
3607  dayoff = oadd(dayoff, -1);
3608  if (--wday < 0)
3609  wday = LDAYSPERWEEK - 1;
3610  --i;
3611  }
3612  if (i < 0 || i >= len_months[isleap(y)][m])
3613  {
3614  if (noise)
3615  warning(_("rule goes past start/end of month; \
3616 will not work with pre-2004 versions of zic"));
3617  }
3618  }
3619  if (dayoff < min_time / SECSPERDAY)
3620  return min_time;
3621  if (dayoff > max_time / SECSPERDAY)
3622  return max_time;
3623  t = (zic_t) dayoff * SECSPERDAY;
3624 
3625  return tadd(t, rp->r_tod);
3626 }
zic_t r_tod
Definition: zic.c:73
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:500
int r_month
Definition: zic.c:67
#define DC_DOWGEQ
Definition: zic.c:89
#define SECSPERDAY
Definition: private.h:97
#define isleap(y)
Definition: datetime.h:273
static const int len_months[2][MONSPERYEAR]
Definition: zic.c:366
#define ZIC_MAX
Definition: zic.c:25
#define LDAYSPERWEEK
static zic_t tadd(zic_t t1, zic_t t2)
Definition: zic.c:3502
int64 zic_t
Definition: zic.c:23
#define ZIC_MIN
Definition: zic.c:24
int r_dycode
Definition: zic.c:69
#define EPOCH_YEAR
Definition: private.h:123
#define DC_DOWLEQ
Definition: zic.c:90
static zic_t const max_time
Definition: zic.c:975
static bool noise
Definition: zic.c:178
#define TM_JANUARY
Definition: private.h:108
#define TM_FEBRUARY
Definition: private.h:109
int r_dayofmonth
Definition: zic.c:70
int r_wday
Definition: zic.c:71
#define EPOCH_WDAY
Definition: private.h:124
int i
#define EXIT_FAILURE
Definition: settings.h:152
static const int len_years[2]
Definition: zic.c:371
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:489
static zic_t const min_time
Definition: zic.c:974
#define _(x)
Definition: elog.c:84
static zic_t oadd(zic_t t1, zic_t t2)
Definition: zic.c:3494
static int rule_cmp ( struct rule const *  a,
struct rule const *  b 
)
static

Definition at line 2494 of file zic.c.

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

Referenced by stringzone().

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

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

Referenced by inrule(), and inzsub().

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

Definition at line 3149 of file zic.c.

Referenced by yearistype().

3150 {
3151  *b++ = '\'';
3152  while (*s)
3153  {
3154  if (*s == '\'')
3155  *b++ = '\'', *b++ = '\\', *b++ = '\'';
3156  *b++ = *s++;
3157  }
3158  *b++ = '\'';
3159  return b;
3160 }
static size_t size_product ( size_t  nitems,
size_t  itemsize 
)
static

Definition at line 403 of file zic.c.

References _, memory_exhausted(), and SIZE_MAX.

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

404 {
405  if (SIZE_MAX / itemsize < nitems)
406  memory_exhausted(_("size overflow"));
407  return nitems * itemsize;
408 }
#define SIZE_MAX
Definition: c.h:336
static void memory_exhausted(const char *msg) pg_attribute_noreturn()
Definition: zic.c:396
#define _(x)
Definition: elog.c:84
static int stringoffset ( char *  result,
zic_t  offset 
)
static

Definition at line 2378 of file zic.c.

References DAYSPERWEEK, HOURSPERDAY, MINSPERHOUR, and SECSPERMIN.

Referenced by stringrule(), and stringzone().

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

Definition at line 2412 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().

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

Definition at line 2512 of file zic.c.

References compat, DC_DOM, doabbr(), i, MINSPERHOUR, 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().

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

Definition at line 3502 of file zic.c.

References max_time, min_time, and time_overflow().

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

3503 {
3504  if (t1 < 0)
3505  {
3506  if (t2 < min_time - t1)
3507  {
3508  if (t1 != min_time)
3509  time_overflow();
3510  return min_time;
3511  }
3512  }
3513  else
3514  {
3515  if (max_time - t1 < t2)
3516  {
3517  if (t1 != max_time)
3518  time_overflow();
3519  return max_time;
3520  }
3521  }
3522  return t1 + t2;
3523 }
static void time_overflow(void)
Definition: zic.c:3487
static zic_t const max_time
Definition: zic.c:975
static zic_t const min_time
Definition: zic.c:974
static void time_overflow ( void  )
static

Definition at line 3487 of file zic.c.

References _, error(), and EXIT_FAILURE.

Referenced by oadd(), and tadd().

3488 {
3489  error(_("time overflow"));
3490  exit(EXIT_FAILURE);
3491 }
#define EXIT_FAILURE
Definition: settings.h:152
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:489
#define _(x)
Definition: elog.c:84
static void updateminmax ( const zic_t  x)
static

Definition at line 2369 of file zic.c.

Referenced by outzone().

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

Definition at line 528 of file zic.c.

References _, close_file(), and EXIT_SUCCESS.

Referenced by main().

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

Definition at line 473 of file zic.c.

References _.

Referenced by error(), and warning().

474 {
475  /*
476  * Match the format of "cc" to allow sh users to zic ... 2>&1 | error -t
477  * "*" -v on BSD systems.
478  */
479  if (filename)
480  fprintf(stderr, _("\"%s\", line %d: "), filename, linenum);
481  vfprintf(stderr, string, args);
482  if (rfilename != NULL)
483  fprintf(stderr, _(" (rule from \"%s\", line %d)"),
485  fprintf(stderr, "\n");
486 }
static lineno_t rlinenum
Definition: zic.c:182
static const char * filename
Definition: zic.c:168
static lineno_t linenum
Definition: zic.c:173
static const char * rfilename
Definition: zic.c:181
#define _(x)
Definition: elog.c:84
static void warning ( const char *  string,
  ... 
)
static

Definition at line 500 of file zic.c.

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

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

501 {
502  va_list args;
503 
504  fprintf(stderr, _("warning: "));
505  va_start(args, string);
506  verror(string, args);
507  va_end(args);
508  warnings = true;
509 }
static bool warnings
Definition: zic.c:167
static void verror(const char *string, va_list args) pg_attribute_printf(1
Definition: zic.c:473
#define _(x)
Definition: elog.c:84
static void writezone ( const char *const  name,
const char *const  string,
char  version 
)
static

Definition at line 1865 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().

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

Definition at line 3163 of file zic.c.

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

Referenced by outzone().

3164 {
3165  char *buf;
3166  char *b;
3167  int result;
3168 
3169  if (type == NULL || *type == '\0')
3170  return true;
3171  buf = emalloc(1 + 4 * strlen(yitcommand) + 2
3172  + INT_STRLEN_MAXIMUM(zic_t) +2 + 4 * strlen(type) + 2);
3173  b = shellquote(buf, yitcommand);
3174  *b++ = ' ';
3175  b += sprintf(b, INT64_FORMAT, year);
3176  *b++ = ' ';
3177  b = shellquote(b, type);
3178  *b = '\0';
3179  result = system(buf);
3180  if (WIFEXITED(result))
3181  {
3182  int status = WEXITSTATUS(result);
3183 
3184  if (status <= 1)
3185  {
3186  free(buf);
3187  return status == 0;
3188  }
3189  }
3190  error(_("Wild result from command execution"));
3191  fprintf(stderr, _("%s: command was '%s', result was %d\n"),
3192  progname, buf, result);
3193  exit(EXIT_FAILURE);
3194 }
#define INT_STRLEN_MAXIMUM(type)
Definition: private.h:74
#define WIFEXITED(w)
Definition: win32.h:172
static const char * yitcommand
Definition: zic.c:569
static char * shellquote(char *b, char const *s)
Definition: zic.c:3149
static char * buf
Definition: pg_test_fsync.c:67
int64 zic_t
Definition: zic.c:23
static const char * progname
Definition: zic.c:183
#define free(a)
Definition: header.h:65
#define WEXITSTATUS(w)
Definition: win32.h:174
#define INT64_FORMAT
Definition: c.h:300
#define EXIT_FAILURE
Definition: settings.h:152
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:224
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:489
#define _(x)
Definition: elog.c:84
static void * emalloc(size_t size)
Definition: zic.c:419

Variable Documentation

unsigned char abbrinds[TZ_MAX_TYPES]
static

Definition at line 383 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:265
#define YR_MAXIMUM
Definition: zic.c:266

Definition at line 347 of file zic.c.

int charcnt
static

Definition at line 165 of file zic.c.

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

char chars[TZ_MAX_CHARS]
static

Definition at line 386 of file zic.c.

Referenced by getColorInfo().

zic_t corr[TZ_MAX_LEAPS]
static

Definition at line 388 of file zic.c.

Referenced by timesub(), and tzloadbody().

const char* directory
static

Definition at line 567 of file zic.c.

Referenced by main().

const zic_t early_time
static
Initial value:
#define TIME_T_BITS_IN_FILE
Definition: zic.c:972
#define MINVAL(t, b)
Definition: private.h:61
int64 zic_t
Definition: zic.c:23
#define BIG_BANG
Definition: zic.c:1000

Definition at line 1015 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:265
#define YR_ONLY
Definition: zic.c:267
#define YR_MAXIMUM
Definition: zic.c:266

Definition at line 353 of file zic.c.

bool errors
static

Definition at line 166 of file zic.c.

const char* filename
static

Definition at line 168 of file zic.c.

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

zic_t gmtoffs[TZ_MAX_TYPES]
static

Definition at line 381 of file zic.c.

char isdsts[TZ_MAX_TYPES]
static

Definition at line 382 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_THURSDAY
Definition: private.h:104
#define TM_FRIDAY
Definition: private.h:105
#define TM_SATURDAY
Definition: private.h:106
#define TM_SUNDAY
Definition: private.h:100
#define TM_TUESDAY
Definition: private.h:102
#define TM_MONDAY
Definition: private.h:101
#define TM_WEDNESDAY
Definition: private.h:103

Definition at line 336 of file zic.c.

const char* lcltime
static

Definition at line 566 of file zic.c.

struct lookup const leap_line_codes[]
static
Initial value:
= {
{"Leap", LC_LEAP},
{NULL, 0}
}
#define LC_LEAP
Definition: zic.c:195

Definition at line 304 of file zic.c.

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

Definition at line 360 of file zic.c.

int leapcnt
static

Definition at line 169 of file zic.c.

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

zic_t leapmaxyear
static

Definition at line 172 of file zic.c.

zic_t leapminyear
static

Definition at line 171 of file zic.c.

const char* leapsec
static

Definition at line 568 of file zic.c.

bool leapseen
static

Definition at line 170 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 366 of file zic.c.

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

Definition at line 371 of file zic.c.

lineno_t linenum
static

Definition at line 173 of file zic.c.

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

struct link* links
static

Definition at line 285 of file zic.c.

int max_abbrvar_len = PERCENT_Z_LEN_BOUND
static

Definition at line 174 of file zic.c.

Referenced by outzone().

int max_format_len
static

Definition at line 175 of file zic.c.

zic_t const max_time = MAXVAL(zic_t, TIME_T_BITS_IN_FILE)
static

Definition at line 975 of file zic.c.

Referenced by rpytime(), and tadd().

zic_t max_year
static

Definition at line 176 of file zic.c.

Referenced by outzone().

zic_t const min_time = MINVAL(zic_t, TIME_T_BITS_IN_FILE)
static

Definition at line 974 of file zic.c.

Referenced by rpytime(), and tadd().

zic_t min_year
static

Definition at line 177 of file zic.c.

struct lookup const mon_names[]
static
Initial value:
= {
{"January", TM_JANUARY},
{"February", TM_FEBRUARY},
{"March", TM_MARCH},
{"April", TM_APRIL},
{"May", TM_MAY},
{"June", TM_JUNE},
{"July", TM_JULY},
{"August", TM_AUGUST},
{"September", TM_SEPTEMBER},
{