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

Go to the source code of this file.

Data Structures

struct  rule
 
struct  zone
 
struct  link
 
struct  lookup
 
struct  attype
 

Macros

#define ZIC_VERSION_PRE_2013   '2'
 
#define ZIC_VERSION   '3'
 
#define ZIC_MIN   PG_INT64_MIN
 
#define ZIC_MAX   PG_INT64_MAX
 
#define ZIC_MAX_ABBR_LEN_WO_WARN   6
 
#define MKDIR_UMASK   0755
 
#define linkat(fromdir, from, todir, to, flag)   (itssymlink(from) ? (errno = ENOTSUP, -1) : link(from, to))
 
#define PRIdLINENO   "d"
 
#define DC_DOM   0 /* 1..31 */ /* unused */
 
#define DC_DOWGEQ   1 /* 1..31 */ /* 0..6 (Sun..Sat) */
 
#define DC_DOWLEQ   2 /* 1..31 */ /* 0..6 (Sun..Sat) */
 
#define LC_RULE   0
 
#define LC_ZONE   1
 
#define LC_LINK   2
 
#define LC_LEAP   3
 
#define ZF_NAME   1
 
#define ZF_GMTOFF   2
 
#define ZF_RULE   3
 
#define ZF_FORMAT   4
 
#define ZF_TILYEAR   5
 
#define ZF_TILMONTH   6
 
#define ZF_TILDAY   7
 
#define ZF_TILTIME   8
 
#define ZONE_MINFIELDS   5
 
#define ZONE_MAXFIELDS   9
 
#define ZFC_GMTOFF   0
 
#define ZFC_RULE   1
 
#define ZFC_FORMAT   2
 
#define ZFC_TILYEAR   3
 
#define ZFC_TILMONTH   4
 
#define ZFC_TILDAY   5
 
#define ZFC_TILTIME   6
 
#define ZONEC_MINFIELDS   3
 
#define ZONEC_MAXFIELDS   7
 
#define RF_NAME   1
 
#define RF_LOYEAR   2
 
#define RF_HIYEAR   3
 
#define RF_COMMAND   4
 
#define RF_MONTH   5
 
#define RF_DAY   6
 
#define RF_TOD   7
 
#define RF_STDOFF   8
 
#define RF_ABBRVAR   9
 
#define RULE_FIELDS   10
 
#define LF_FROM   1
 
#define LF_TO   2
 
#define LINK_FIELDS   3
 
#define LP_YEAR   1
 
#define LP_MONTH   2
 
#define LP_DAY   3
 
#define LP_TIME   4
 
#define LP_CORR   5
 
#define LP_ROLL   6
 
#define LEAP_FIELDS   7
 
#define YR_MINIMUM   0
 
#define YR_MAXIMUM   1
 
#define YR_ONLY   2
 
#define TIME_T_BITS_IN_FILE   64
 
#define BIG_BANG   (- (((zic_t) 1) << 59))
 
#define DO(field)   fwrite(tzh.field, sizeof tzh.field, 1, fp)
 
#define LDAYSPERWEEK   ((zic_t) DAYSPERWEEK)
 

Typedefs

typedef int64 zic_t
 
typedef int lineno_t
 

Enumerations

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

Functions

int link (const char *fromname, const char *toname)
 
static void memory_exhausted (const char *msg) pg_attribute_noreturn()
 
static void verror (const char *string, va_list args) pg_attribute_printf(1
 
static void static void error (const char *string,...) pg_attribute_printf(1
 
static void static void static void warning (const char *string,...) pg_attribute_printf(1
 
static void static void static
void static void 
usage (FILE *stream, int status) pg_attribute_noreturn()
 
static void addtt (zic_t starttime, int type)
 
static int addtype (zic_t, char const *, bool, bool, bool)
 
static void leapadd (zic_t, bool, int, int)
 
static void adjleap (void)
 
static void associate (void)
 
static void dolink (const char *, const char *, bool)
 
static char ** getfields (char *buf)
 
static zic_t gethms (const char *string, const char *errstring, bool)
 
static void infile (const char *filename)
 
static void inleap (char **fields, int nfields)
 
static void inlink (char **fields, int nfields)
 
static void inrule (char **fields, int nfields)
 
static bool inzcont (char **fields, int nfields)
 
static bool inzone (char **fields, int nfields)
 
static bool inzsub (char **, int, bool)
 
static bool itsdir (char const *)
 
static bool itssymlink (char const *)
 
static bool is_alpha (char a)
 
static char lowerit (char)
 
static void mkdirs (char const *, bool)
 
static void newabbr (const char *abbr)
 
static zic_t oadd (zic_t t1, zic_t t2)
 
static void outzone (const struct zone *zp, ptrdiff_t ntzones)
 
static zic_t rpytime (const struct rule *rp, zic_t wantedy)
 
static void rulesub (struct rule *rp, const char *loyearp, const char *hiyearp, const char *typep, const char *monthp, const char *dayp, const char *timep)
 
static zic_t tadd (zic_t t1, zic_t t2)
 
static bool yearistype (zic_t year, const char *type)
 
static struct lookup const * byword (const char *string, const struct lookup *lp)
 
static size_t size_product (size_t nitems, size_t itemsize)
 
static void * memcheck (void *ptr)
 
static void * emalloc (size_t size)
 
static void * erealloc (void *ptr, size_t size)
 
static char * ecpyalloc (char const *str)
 
static void * growalloc (void *ptr, size_t itemsize, ptrdiff_t nitems, ptrdiff_t *nitems_alloc)
 
static void eats (char const *name, lineno_t num, char const *rname, lineno_t rnum)
 
static void eat (char const *name, lineno_t num)
 
static void close_file (FILE *stream, char const *dir, char const *name)
 
static void change_directory (char const *dir)
 
int main (int argc, char *argv[])
 
static bool componentcheck (char const *name, char const *component, char const *component_end)
 
static bool namecheck (const char *name)
 
static int hardlinkerr (char const *from, char const *to)
 
static int rcomp (const void *cp1, const void *cp2)
 
static void convert (const int32 val, char *const buf)
 
static void convert64 (const zic_t val, char *const buf)
 
static void puttzcode (const int32 val, FILE *const fp)
 
static void puttzcode64 (const zic_t val, FILE *const fp)
 
static int atcomp (const void *avp, const void *bvp)
 
static bool is32 (const zic_t x)
 
static void writezone (const char *const name, const char *const string, char version)
 
static char const * abbroffset (char *buf, zic_t offset)
 
static size_t doabbr (char *abbr, struct zone const *zp, char const *letters, zic_t stdoff, bool doquotes)
 
static void updateminmax (const zic_t x)
 
static int stringoffset (char *result, zic_t offset)
 
static int stringrule (char *result, const struct rule *const rp, const zic_t dstoff, const zic_t gmtoff)
 
static int rule_cmp (struct rule const *a, struct rule const *b)
 
static int stringzone (char *result, struct zone const *zpfirst, ptrdiff_t zonecount)
 
static char * shellquote (char *b, char const *s)
 
static bool is_space (char a)
 
static bool ciequal (const char *ap, const char *bp)
 
static bool itsabbr (const char *abbr, const char *word)
 
static void time_overflow (void)
 

Variables

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

Macro Definition Documentation

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

Definition at line 991 of file zic.c.

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

Definition at line 86 of file zic.c.

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

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

Definition at line 87 of file zic.c.

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

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

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

Referenced by infile().

#define LC_LINK   2

Definition at line 192 of file zic.c.

Referenced by infile().

#define LC_RULE   0

Definition at line 190 of file zic.c.

Referenced by infile().

#define LC_ZONE   1

Definition at line 191 of file zic.c.

Referenced by infile().

#define LDAYSPERWEEK   ((zic_t) DAYSPERWEEK)

Referenced by rpytime().

#define LEAP_FIELDS   7

Definition at line 257 of file zic.c.

Referenced by inleap().

#define LF_FROM   1

Definition at line 243 of file zic.c.

Referenced by inlink().

#define LF_TO   2

Definition at line 244 of file zic.c.

Referenced by inlink().

#define LINK_FIELDS   3

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

Referenced by hardlinkerr().

#define LP_CORR   5

Definition at line 255 of file zic.c.

Referenced by inleap().

#define LP_DAY   3

Definition at line 253 of file zic.c.

Referenced by inleap().

#define LP_MONTH   2

Definition at line 252 of file zic.c.

Referenced by inleap().

#define LP_ROLL   6

Definition at line 256 of file zic.c.

Referenced by inleap().

#define LP_TIME   4

Definition at line 254 of file zic.c.

Referenced by inleap().

#define LP_YEAR   1

Definition at line 251 of file zic.c.

Referenced by inleap().

#define MKDIR_UMASK   0755

Definition at line 36 of file zic.c.

Referenced by mkdirs().

#define PRIdLINENO   "d"

Definition at line 51 of file zic.c.

Referenced by inzone(), and verror().

#define RF_ABBRVAR   9

Definition at line 236 of file zic.c.

Referenced by inrule().

#define RF_COMMAND   4

Definition at line 231 of file zic.c.

Referenced by inrule().

#define RF_DAY   6

Definition at line 233 of file zic.c.

Referenced by inrule().

#define RF_HIYEAR   3

Definition at line 230 of file zic.c.

Referenced by inrule().

#define RF_LOYEAR   2

Definition at line 229 of file zic.c.

Referenced by inrule().

#define RF_MONTH   5

Definition at line 232 of file zic.c.

Referenced by inrule().

#define RF_NAME   1

Definition at line 228 of file zic.c.

Referenced by inrule().

#define RF_STDOFF   8

Definition at line 235 of file zic.c.

Referenced by inrule().

#define RF_TOD   7

Definition at line 234 of file zic.c.

Referenced by inrule().

#define RULE_FIELDS   10

Definition at line 237 of file zic.c.

Referenced by inrule().

#define TIME_T_BITS_IN_FILE   64

Definition at line 963 of file zic.c.

#define YR_MAXIMUM   1

Definition at line 264 of file zic.c.

Referenced by rulesub().

#define YR_MINIMUM   0

Definition at line 263 of file zic.c.

Referenced by rulesub().

#define YR_ONLY   2

Definition at line 265 of file zic.c.

Referenced by rulesub().

#define ZF_FORMAT   4

Definition at line 202 of file zic.c.

Referenced by inzsub().

#define ZF_GMTOFF   2

Definition at line 200 of file zic.c.

Referenced by inzsub().

#define ZF_NAME   1

Definition at line 199 of file zic.c.

Referenced by inzone(), and inzsub().

#define ZF_RULE   3

Definition at line 201 of file zic.c.

Referenced by inzsub().

#define ZF_TILDAY   7

Definition at line 205 of file zic.c.

Referenced by inzsub().

#define ZF_TILMONTH   6

Definition at line 204 of file zic.c.

Referenced by inzsub().

#define ZF_TILTIME   8

Definition at line 206 of file zic.c.

Referenced by inzsub().

#define ZF_TILYEAR   5

Definition at line 203 of file zic.c.

Referenced by inzsub().

#define ZFC_FORMAT   2

Definition at line 216 of file zic.c.

Referenced by inzsub().

#define ZFC_GMTOFF   0

Definition at line 214 of file zic.c.

Referenced by inzsub().

#define ZFC_RULE   1

Definition at line 215 of file zic.c.

Referenced by inzsub().

#define ZFC_TILDAY   5

Definition at line 219 of file zic.c.

Referenced by inzsub().

#define ZFC_TILMONTH   4

Definition at line 218 of file zic.c.

Referenced by inzsub().

#define ZFC_TILTIME   6

Definition at line 220 of file zic.c.

Referenced by inzsub().

#define ZFC_TILYEAR   3

Definition at line 217 of file zic.c.

Referenced by inzsub().

#define ZIC_MAX   PG_INT64_MAX

Definition at line 26 of file zic.c.

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

#define ZIC_MAX_ABBR_LEN_WO_WARN   6

Definition at line 29 of file zic.c.

Referenced by newabbr().

#define ZIC_MIN   PG_INT64_MIN

Definition at line 25 of file zic.c.

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

#define ZIC_VERSION   '3'

Definition at line 22 of file zic.c.

Referenced by outzone().

#define ZIC_VERSION_PRE_2013   '2'

Definition at line 21 of file zic.c.

Referenced by outzone().

#define ZONE_MAXFIELDS   9

Definition at line 208 of file zic.c.

Referenced by inzone().

#define ZONE_MINFIELDS   5

Definition at line 207 of file zic.c.

#define ZONEC_MAXFIELDS   7

Definition at line 222 of file zic.c.

Referenced by inzcont().

#define ZONEC_MINFIELDS   3

Definition at line 221 of file zic.c.

Typedef Documentation

Definition at line 50 of file zic.c.

typedef int64 zic_t

Definition at line 24 of file zic.c.

Enumeration Type Documentation

anonymous enum
Enumerator
PERCENT_Z_LEN_BOUND 

Definition at line 150 of file zic.c.

151 {
152 PERCENT_Z_LEN_BOUND = sizeof "+995959" - 1};
anonymous enum
Enumerator
WORK_AROUND_QTBUG_53071 

Definition at line 159 of file zic.c.

anonymous enum
Enumerator
WORK_AROUND_GNOME_BUG_730332 

Definition at line 1002 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:107
char sign
Definition: informix.c:693
static char * buf
Definition: pg_test_fsync.c:66
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:483
#define _(x)
Definition: elog.c:84
#define MINSPERHOUR
Definition: private.h:108
static void addtt ( zic_t  starttime,
int  type 
)
static

Definition at line 3023 of file zic.c.

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

Referenced by outzone().

3024 {
3025  if (starttime <= early_time
3026  || (timecnt == 1 && attypes[0].at < early_time))
3027  {
3028  gmtoffs[0] = gmtoffs[type];
3029  isdsts[0] = isdsts[type];
3030  ttisstds[0] = ttisstds[type];
3031  ttisgmts[0] = ttisgmts[type];
3032  if (abbrinds[type] != 0)
3033  strcpy(chars, &chars[abbrinds[type]]);
3034  abbrinds[0] = 0;
3035  charcnt = strlen(chars) + 1;
3036  typecnt = 1;
3037  timecnt = 0;
3038  type = 0;
3039  }
3041  attypes[timecnt].at = starttime;
3042  attypes[timecnt].dontmerge = false;
3043  attypes[timecnt].type = type;
3044  ++timecnt;
3045 }
static bool ttisstds[TZ_MAX_TYPES]
Definition: zic.c:379
static int typecnt
Definition: zic.c:184
static zic_t gmtoffs[TZ_MAX_TYPES]
Definition: zic.c:376
static unsigned char abbrinds[TZ_MAX_TYPES]
Definition: zic.c:378
unsigned char type
Definition: zic.c:374
static char isdsts[TZ_MAX_TYPES]
Definition: zic.c:377
static bool ttisgmts[TZ_MAX_TYPES]
Definition: zic.c:380
static const zic_t early_time
Definition: zic.c:1006
static void * growalloc(void *ptr, size_t itemsize, ptrdiff_t nitems, ptrdiff_t *nitems_alloc)
Definition: zic.c:432
zic_t at
Definition: zic.c:372
static ptrdiff_t timecnt_alloc
Definition: zic.c:183
static struct attype * attypes
static ptrdiff_t timecnt
Definition: zic.c:182
static int charcnt
Definition: zic.c:163
bool dontmerge
Definition: zic.c:373
static char chars[TZ_MAX_CHARS]
Definition: zic.c:381
static int addtype ( zic_t  gmtoff,
char const *  abbr,
bool  isdst,
bool  ttisstd,
bool  ttisgmt 
)
static

Definition at line 3048 of file zic.c.

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

Referenced by outzone(), and writezone().

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

Definition at line 3131 of file zic.c.

References i, leapcnt, and tadd().

Referenced by main().

3132 {
3133  int i;
3134  zic_t last = 0;
3135 
3136  /*
3137  * propagate leap seconds forward
3138  */
3139  for (i = 0; i < leapcnt; ++i)
3140  {
3141  trans[i] = tadd(trans[i], last);
3142  last = corr[i] += last;
3143  }
3144 }
static zic_t corr[TZ_MAX_LEAPS]
Definition: zic.c:383
static zic_t tadd(zic_t t1, zic_t t2)
Definition: zic.c:3452
static int leapcnt
Definition: zic.c:167
int64 zic_t
Definition: zic.c:24
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:382
int i
static void associate ( void  )
static

Definition at line 1064 of file zic.c.

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

Referenced by main().

1065 {
1066  struct zone *zp;
1067  struct rule *rp;
1068  ptrdiff_t i,
1069  j,
1070  base,
1071  out;
1072 
1073  if (nrules != 0)
1074  {
1075  qsort(rules, nrules, sizeof *rules, rcomp);
1076  for (i = 0; i < nrules - 1; ++i)
1077  {
1078  if (strcmp(rules[i].r_name,
1079  rules[i + 1].r_name) != 0)
1080  continue;
1081  if (strcmp(rules[i].r_filename,
1082  rules[i + 1].r_filename) == 0)
1083  continue;
1084  eat(rules[i].r_filename, rules[i].r_linenum);
1085  warning(_("same rule name in multiple files"));
1086  eat(rules[i + 1].r_filename, rules[i + 1].r_linenum);
1087  warning(_("same rule name in multiple files"));
1088  for (j = i + 2; j < nrules; ++j)
1089  {
1090  if (strcmp(rules[i].r_name,
1091  rules[j].r_name) != 0)
1092  break;
1093  if (strcmp(rules[i].r_filename,
1094  rules[j].r_filename) == 0)
1095  continue;
1096  if (strcmp(rules[i + 1].r_filename,
1097  rules[j].r_filename) == 0)
1098  continue;
1099  break;
1100  }
1101  i = j - 1;
1102  }
1103  }
1104  for (i = 0; i < nzones; ++i)
1105  {
1106  zp = &zones[i];
1107  zp->z_rules = NULL;
1108  zp->z_nrules = 0;
1109  }
1110  for (base = 0; base < nrules; base = out)
1111  {
1112  rp = &rules[base];
1113  for (out = base + 1; out < nrules; ++out)
1114  if (strcmp(rp->r_name, rules[out].r_name) != 0)
1115  break;
1116  for (i = 0; i < nzones; ++i)
1117  {
1118  zp = &zones[i];
1119  if (strcmp(zp->z_rule, rp->r_name) != 0)
1120  continue;
1121  zp->z_rules = rp;
1122  zp->z_nrules = out - base;
1123  }
1124  }
1125  for (i = 0; i < nzones; ++i)
1126  {
1127  zp = &zones[i];
1128  if (zp->z_nrules == 0)
1129  {
1130  /*
1131  * Maybe we have a local standard time offset.
1132  */
1133  eat(zp->z_filename, zp->z_linenum);
1134  zp->z_stdoff = gethms(zp->z_rule, _("unruly zone"),
1135  true);
1136 
1137  /*
1138  * Note, though, that if there's no rule, a '%s' in the format is
1139  * a bad thing.
1140  */
1141  if (zp->z_format_specifier == 's')
1142  error("%s", _("%s in ruleless zone"));
1143  }
1144  }
1145  if (errors)
1146  exit(EXIT_FAILURE);
1147 }
lineno_t r_linenum
Definition: zic.c:56
static int rcomp(const void *cp1, const void *cp2)
Definition: zic.c:1057
const char * z_rule
Definition: zic.c:97
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:494
static bool errors
Definition: zic.c:164
static ptrdiff_t nzones
Definition: zic.c:272
Definition: localtime.c:82
char z_format_specifier
Definition: zic.c:99
const char * r_name
Definition: zic.c:57
const char * z_filename
Definition: zic.c:92
static struct rule * rules
Definition: zic.c:267
const char * r_filename
Definition: zic.c:55
static zic_t gethms(const char *string, const char *errstring, bool)
Definition: zic.c:1253
static void eat(char const *name, lineno_t num)
Definition: zic.c:461
ptrdiff_t z_nrules
Definition: zic.c:104
lineno_t z_linenum
Definition: zic.c:93
#define NULL
Definition: c.h:229
static ptrdiff_t nrules
Definition: zic.c:268
static struct zone * zones
Definition: zic.c:271
struct rule * z_rules
Definition: zic.c:103
Definition: zic.c:90
int i
#define EXIT_FAILURE
Definition: settings.h:151
#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:483
#define _(x)
Definition: elog.c:84
zic_t z_stdoff
Definition: zic.c:101
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:370
int64 zic_t
Definition: zic.c:24
static const struct lookup * byword ( const char *  string,
const struct lookup lp 
)
static

Definition at line 3366 of file zic.c.

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

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

3367 {
3368  const struct lookup *foundlp;
3369  const struct lookup *lp;
3370 
3371  if (word == NULL || table == NULL)
3372  return NULL;
3373 
3374  /*
3375  * Look for exact match.
3376  */
3377  for (lp = table; lp->l_word != NULL; ++lp)
3378  if (ciequal(word, lp->l_word))
3379  return lp;
3380 
3381  /*
3382  * Look for inexact match.
3383  */
3384  foundlp = NULL;
3385  for (lp = table; lp->l_word != NULL; ++lp)
3386  if (itsabbr(word, lp->l_word))
3387  {
3388  if (foundlp == NULL)
3389  foundlp = lp;
3390  else
3391  return NULL; /* multiple inexact matches */
3392  }
3393  return foundlp;
3394 }
Definition: zic.c:287
static bool ciequal(const char *ap, const char *bp)
Definition: zic.c:3342
const char * l_word
Definition: zic.c:289
#define NULL
Definition: c.h:229
static void word(struct vars *, int, struct state *, struct state *)
Definition: regcomp.c:1243
static bool itsabbr(const char *abbr, const char *word)
Definition: zic.c:3351
static void change_directory ( char const *  dir)
static

Definition at line 539 of file zic.c.

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

Referenced by main().

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

Definition at line 3342 of file zic.c.

References lowerit().

Referenced by byword().

3343 {
3344  while (lowerit(*ap) == lowerit(*bp++))
3345  if (*ap++ == '\0')
3346  return true;
3347  return false;
3348 }
static char lowerit(char)
Definition: zic.c:3279
static void close_file ( FILE *  stream,
char const *  dir,
char const *  name 
)
static

Definition at line 506 of file zic.c.

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

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

507 {
508  char const *e = (ferror(stream) ? _("I/O error")
509  : fclose(stream) != 0 ? strerror(errno) : NULL);
510 
511  if (e)
512  {
513  fprintf(stderr, "%s: %s%s%s%s%s\n", progname,
514  dir ? dir : "", dir ? "/" : "",
515  name ? name : "", name ? ": " : "",
516  e);
517  exit(EXIT_FAILURE);
518  }
519 }
static const char * progname
Definition: zic.c:181
#define NULL
Definition: c.h:229
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:151
#define _(x)
Definition: elog.c:84
static bool componentcheck ( char const *  name,
char const *  component,
char const *  component_end 
)
static

Definition at line 723 of file zic.c.

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

Referenced by namecheck().

725 {
726  enum
727  {
728  component_len_max = 14};
729  ptrdiff_t component_len = component_end - component;
730 
731  if (component_len == 0)
732  {
733  if (!*name)
734  error(_("empty file name"));
735  else
736  error(_(component == name
737  ? "file name '%s' begins with '/'"
738  : *component_end
739  ? "file name '%s' contains '//'"
740  : "file name '%s' ends with '/'"),
741  name);
742  return false;
743  }
744  if (0 < component_len && component_len <= 2
745  && component[0] == '.' && component_end[-1] == '.')
746  {
747  int len = component_len;
748 
749  error(_("file name '%s' contains '%.*s' component"),
750  name, len, component);
751  return false;
752  }
753  if (noise)
754  {
755  if (0 < component_len && component[0] == '-')
756  warning(_("file name '%s' component contains leading '-'"),
757  name);
758  if (component_len_max < component_len)
759  warning(_("file name '%s' contains overlength component"
760  " '%.*s...'"),
761  name, component_len_max, component);
762  }
763  return true;
764 }
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:494
static bool noise
Definition: zic.c:176
const char * name
Definition: encode.c:521
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:483
#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:66
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:66
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, NULL, 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:3214
#define memmove(d, s, c)
Definition: c.h:1058
#define NULL
Definition: c.h:229
static char format
Definition: pg_basebackup.c:80
static void dolink ( const char *  fromfield,
const char *  tofield,
bool  staysymlink 
)
static

Definition at line 868 of file zic.c.

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

Referenced by main().

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

Definition at line 461 of file zic.c.

References eats(), and NULL.

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

462 {
463  eats(name, num, NULL, -1);
464 }
#define NULL
Definition: c.h:229
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:452
static void eats ( char const *  name,
lineno_t  num,
char const *  rname,
lineno_t  rnum 
)
static

Definition at line 452 of file zic.c.

References name.

Referenced by eat(), and outzone().

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

Definition at line 426 of file zic.c.

References memcheck().

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

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

Definition at line 414 of file zic.c.

References malloc, and memcheck().

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

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

Definition at line 420 of file zic.c.

References memcheck(), and realloc.

Referenced by growalloc().

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

Definition at line 483 of file zic.c.

References generate_unaccent_rules::args, and verror().

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

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

Definition at line 3397 of file zic.c.

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

Referenced by infile().

3398 {
3399  char *dp;
3400  char **array;
3401  int nsubs;
3402 
3403  if (cp == NULL)
3404  return NULL;
3405  array = emalloc(size_product(strlen(cp) + 1, sizeof *array));
3406  nsubs = 0;
3407  for (;;)
3408  {
3409  while (is_space(*cp))
3410  ++cp;
3411  if (*cp == '\0' || *cp == '#')
3412  break;
3413  array[nsubs++] = dp = cp;
3414  do
3415  {
3416  if ((*dp = *cp++) != '"')
3417  ++dp;
3418  else
3419  while ((*dp = *cp++) != '"')
3420  if (*dp != '\0')
3421  ++dp;
3422  else
3423  {
3424  error(_("Odd number of quotation marks"));
3425  exit(EXIT_FAILURE);
3426  }
3427  } while (*cp && *cp != '#' && !is_space(*cp));
3428  if (is_space(*cp))
3429  ++cp;
3430  *dp = '\0';
3431  }
3432  array[nsubs] = NULL;
3433  return array;
3434 }
static bool is_space(char a)
Definition: zic.c:3196
#define NULL
Definition: c.h:229
#define EXIT_FAILURE
Definition: settings.h:151
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:483
#define _(x)
Definition: elog.c:84
static size_t size_product(size_t nitems, size_t itemsize)
Definition: zic.c:398
static void * emalloc(size_t size)
Definition: zic.c:414
static zic_t gethms ( const char *  string,
const char *  errstring,
bool  signable 
)
static

Definition at line 1253 of file zic.c.

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

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

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

Definition at line 432 of file zic.c.

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

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

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

Definition at line 860 of file zic.c.

References linkat.

Referenced by dolink().

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

Definition at line 1150 of file zic.c.

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

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

1151 {
1152  FILE *fp;
1153  char **fields;
1154  char *cp;
1155  const struct lookup *lp;
1156  int nfields;
1157  bool wantcont;
1158  lineno_t num;
1159  char buf[BUFSIZ];
1160 
1161  if (strcmp(name, "-") == 0)
1162  {
1163  name = _("standard input");
1164  fp = stdin;
1165  }
1166  else if ((fp = fopen(name, "r")) == NULL)
1167  {
1168  const char *e = strerror(errno);
1169 
1170  fprintf(stderr, _("%s: Cannot open %s: %s\n"),
1171  progname, name, e);
1172  exit(EXIT_FAILURE);
1173  }
1174  wantcont = false;
1175  for (num = 1;; ++num)
1176  {
1177  eat(name, num);
1178  if (fgets(buf, sizeof buf, fp) != buf)
1179  break;
1180  cp = strchr(buf, '\n');
1181  if (cp == NULL)
1182  {
1183  error(_("line too long"));
1184  exit(EXIT_FAILURE);
1185  }
1186  *cp = '\0';
1187  fields = getfields(buf);
1188  nfields = 0;
1189  while (fields[nfields] != NULL)
1190  {
1191  static char nada;
1192 
1193  if (strcmp(fields[nfields], "-") == 0)
1194  fields[nfields] = &nada;
1195  ++nfields;
1196  }
1197  if (nfields == 0)
1198  {
1199  /* nothing to do */
1200  }
1201  else if (wantcont)
1202  wantcont = inzcont(fields, nfields);
1203  else
1204  {
1205  lp = byword(fields[0], line_codes);
1206  if (lp == NULL)
1207  error(_("input line of unknown type"));
1208  else
1209  switch (lp->l_value)
1210  {
1211  case LC_RULE:
1212  inrule(fields, nfields);
1213  wantcont = false;
1214  break;
1215  case LC_ZONE:
1216  wantcont = inzone(fields, nfields);
1217  break;
1218  case LC_LINK:
1219  inlink(fields, nfields);
1220  wantcont = false;
1221  break;
1222  case LC_LEAP:
1223  if (name != leapsec)
1224  warning(_("%s: Leap line in non leap"
1225  " seconds file %s"),
1226  progname, name);
1227  else
1228  inleap(fields, nfields);
1229  wantcont = false;
1230  break;
1231  default: /* "cannot happen" */
1232  fprintf(stderr,
1233  _("%s: panic: Invalid l_value %d\n"),
1234  progname, lp->l_value);
1235  exit(EXIT_FAILURE);
1236  }
1237  }
1238  free(fields);
1239  }
1240  close_file(fp, NULL, filename);
1241  if (wantcont)
1242  error(_("expected continuation line not found"));
1243 }
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:494
static void inrule(char **fields, int nfields)
Definition: zic.c:1306
#define LC_LEAP
Definition: zic.c:193
static const char * leapsec
Definition: zic.c:562
const int l_value
Definition: zic.c:290
static const char * filename
Definition: zic.c:166
static void inleap(char **fields, int nfields)
Definition: zic.c:1482
static char ** getfields(char *buf)
Definition: zic.c:3397
static bool inzcont(char **fields, int nfields)
Definition: zic.c:1372
static char * buf
Definition: pg_test_fsync.c:66
Definition: zic.c:287
#define LC_LINK
Definition: zic.c:192
static void eat(char const *name, lineno_t num)
Definition: zic.c:461
#define LC_ZONE
Definition: zic.c:191
static const char * progname
Definition: zic.c:181
#define free(a)
Definition: header.h:65
static bool inzone(char **fields, int nfields)
Definition: zic.c:1334
#define NULL
Definition: c.h:229
static void inlink(char **fields, int nfields)
Definition: zic.c:1612
static void close_file(FILE *stream, char const *dir, char const *name)
Definition: zic.c:506
static struct lookup const * byword(const char *string, const struct lookup *lp)
Definition: zic.c:3366
static struct lookup const line_codes[]
Definition: zic.c:296
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:151
int lineno_t
Definition: zic.c:50
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:483
#define LC_RULE
Definition: zic.c:190
#define _(x)
Definition: elog.c:84
static void inleap ( char **  fields,
int  nfields 
)
static

Definition at line 1482 of file zic.c.

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

Referenced by infile().

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

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

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

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

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

Definition at line 1372 of file zic.c.

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

Referenced by infile().

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

Definition at line 1334 of file zic.c.

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

Referenced by infile().

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

Definition at line 1383 of file zic.c.

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

Referenced by inzcont(), and inzone().

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

Definition at line 3214 of file zic.c.

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

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

Definition at line 3196 of file zic.c.

Referenced by getfields().

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

Definition at line 3351 of file zic.c.

References lowerit(), and word().

Referenced by byword().

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

Definition at line 1012 of file zic.c.

References emalloc(), EOVERFLOW, and free.

Referenced by dolink(), and mkdirs().

1013 {
1014  struct stat st;
1015  int res = stat(name, &st);
1016 #ifdef S_ISDIR
1017  if (res == 0)
1018  return S_ISDIR(st.st_mode) != 0;
1019 #endif
1020  if (res == 0 || errno == EOVERFLOW)
1021  {
1022  size_t n = strlen(name);
1023  char *nameslashdot = emalloc(n + 3);
1024  bool dir;
1025 
1026  memcpy(nameslashdot, name, n);
1027  strcpy(&nameslashdot[n], &"/."[!(n && name[n - 1] != '/')]);
1028  dir = stat(nameslashdot, &st) == 0 || errno == EOVERFLOW;
1029  free(nameslashdot);
1030  return dir;
1031  }
1032  return false;
1033 }
#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:414
static bool itssymlink ( char const *  name)
static

Definition at line 1037 of file zic.c.

Referenced by dolink().

1038 {
1039 #ifdef HAVE_SYMLINK
1040  char c;
1041 
1042  return 0 <= readlink(name, &c, 1);
1043 #else
1044  return false;
1045 #endif
1046 }
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 3095 of file zic.c.

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

Referenced by inleap().

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

Definition at line 3279 of file zic.c.

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

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

Definition at line 566 of file zic.c.

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

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

Definition at line 406 of file zic.c.

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

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

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

Definition at line 391 of file zic.c.

References _, and EXIT_FAILURE.

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

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

Definition at line 3617 of file zic.c.

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

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

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

Definition at line 767 of file zic.c.

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

Referenced by inlink(), and inzsub().

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

Definition at line 3579 of file zic.c.

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

Referenced by addtype().

3580 {
3581  int i;
3582 
3583  if (strcmp(string, GRANDPARENTED) != 0)
3584  {
3585  const char *cp;
3586  const char *mp;
3587 
3588  cp = string;
3589  mp = NULL;
3590  while (is_alpha(*cp) || ('0' <= *cp && *cp <= '9')
3591  || *cp == '-' || *cp == '+')
3592  ++cp;
3593  if (noise && cp - string < 3)
3594  mp = _("time zone abbreviation has fewer than 3 characters");
3595  if (cp - string > ZIC_MAX_ABBR_LEN_WO_WARN)
3596  mp = _("time zone abbreviation has too many characters");
3597  if (*cp != '\0')
3598  mp = _("time zone abbreviation differs from POSIX standard");
3599  if (mp != NULL)
3600  warning("%s (%s)", mp, string);
3601  }
3602  i = strlen(string) + 1;
3603  if (charcnt + i > TZ_MAX_CHARS)
3604  {
3605  error(_("too many, or too long, time zone abbreviations"));
3606  exit(EXIT_FAILURE);
3607  }
3608  strcpy(&chars[charcnt], string);
3609  charcnt += i;
3610 }
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:494
#define GRANDPARENTED
Definition: private.h:27
static bool is_alpha(char a)
Definition: zic.c:3214
char string[11]
Definition: preproc-type.c:46
#define ZIC_MAX_ABBR_LEN_WO_WARN
Definition: zic.c:29
#define TZ_MAX_CHARS
Definition: tzfile.h:98
static bool noise
Definition: zic.c:176
#define NULL
Definition: c.h:229
static int charcnt
Definition: zic.c:163
int i
#define EXIT_FAILURE
Definition: settings.h:151
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:483
static char chars[TZ_MAX_CHARS]
Definition: zic.c:381
#define _(x)
Definition: elog.c:84
static zic_t oadd ( zic_t  t1,
zic_t  t2 
)
static

Definition at line 3444 of file zic.c.

References time_overflow(), ZIC_MAX, and ZIC_MIN.

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

3445 {
3446  if (t1 < 0 ? t2 < ZIC_MIN - t1 : ZIC_MAX - t1 < t2)
3447  time_overflow();
3448  return t1 + t2;
3449 }
#define ZIC_MAX
Definition: zic.c:26
#define ZIC_MIN
Definition: zic.c:25
static void time_overflow(void)
Definition: zic.c:3437
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, NULL, oadd(), rule::r_abbrvar, rule::r_dayofmonth, rule::r_dycode, rule::r_filename, rule::r_hiwasnum, rule::r_hiyear, rule::r_linenum, rule::r_lowasnum, rule::r_loyear, rule::r_month, rule::r_stdoff, rule::r_temp, rule::r_tod, rule::r_todisgmt, rule::r_todisstd, rule::r_todo, rule::r_yrtype, rpytime(), stringzone(), tadd(), timecnt, TM_JANUARY, updateminmax(), warning(), writezone(), YEAR_BY_YEAR_ZONE, yearistype(), YEARSPERREPEAT, zone::z_filename, zone::z_format, zone::z_gmtoff, zone::z_linenum, zone::z_name, zone::z_nrules, zone::z_rules, zone::z_stdoff, zone::z_untilrule, zone::z_untiltime, ZIC_MAX, ZIC_MIN, ZIC_VERSION, and ZIC_VERSION_PRE_2013.

Referenced by main().

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 = 0;
2854  zic_t offset;
2855 
2856  if (useuntil)
2857  {
2858  /*
2859  * Turn untiltime into UT assuming the current gmtoff
2860  * and stdoff values.
2861  */
2862  untiltime = zp->z_untiltime;
2863  if (!zp->z_untilrule.r_todisgmt)
2864  untiltime = tadd(untiltime,
2865  -gmtoff);
2866  if (!zp->z_untilrule.r_todisstd)
2867  untiltime = tadd(untiltime,
2868  -stdoff);
2869  }
2870 
2871  /*
2872  * Find the rule (of those to do, if any) that takes
2873  * effect earliest in the year.
2874  */
2875  k = -1;
2876  for (j = 0; j < zp->z_nrules; ++j)
2877  {
2878  rp = &zp->z_rules[j];
2879  if (!rp->r_todo)
2880  continue;
2881  eats(zp->z_filename, zp->z_linenum,
2882  rp->r_filename, rp->r_linenum);
2883  offset = rp->r_todisgmt ? 0 : gmtoff;
2884  if (!rp->r_todisstd)
2885  offset = oadd(offset, stdoff);
2886  jtime = rp->r_temp;
2887  if (jtime == min_time ||
2888  jtime == max_time)
2889  continue;
2890  jtime = tadd(jtime, -offset);
2891  if (k < 0 || jtime < ktime)
2892  {
2893  k = j;
2894  ktime = jtime;
2895  }
2896  else if (jtime == ktime)
2897  {
2898  char const *dup_rules_msg =
2899  _("two rules for same instant");
2900 
2901  eats(zp->z_filename, zp->z_linenum,
2902  rp->r_filename, rp->r_linenum);
2903  warning("%s", dup_rules_msg);
2904  rp = &zp->z_rules[k];
2905  eats(zp->z_filename, zp->z_linenum,
2906  rp->r_filename, rp->r_linenum);
2907  error("%s", dup_rules_msg);
2908  }
2909  }
2910  if (k < 0)
2911  break; /* go on to next year */
2912  rp = &zp->z_rules[k];
2913  rp->r_todo = false;
2914  if (useuntil && ktime >= untiltime)
2915  break;
2916  stdoff = rp->r_stdoff;
2917  if (usestart && ktime == starttime)
2918  usestart = false;
2919  if (usestart)
2920  {
2921  if (ktime < starttime)
2922  {
2923  startoff = oadd(zp->z_gmtoff,
2924  stdoff);
2925  doabbr(startbuf, zp,
2926  rp->r_abbrvar,
2927  rp->r_stdoff,
2928  false);
2929  continue;
2930  }
2931  if (*startbuf == '\0' &&
2932  startoff == oadd(zp->z_gmtoff, stdoff))
2933  {
2934  doabbr(startbuf,
2935  zp,
2936  rp->r_abbrvar,
2937  rp->r_stdoff,
2938  false);
2939  }
2940  }
2941  eats(zp->z_filename, zp->z_linenum,
2942  rp->r_filename, rp->r_linenum);
2943  doabbr(ab, zp, rp->r_abbrvar,
2944  rp->r_stdoff, false);
2945  offset = oadd(zp->z_gmtoff, rp->r_stdoff);
2946  type = addtype(offset, ab, rp->r_stdoff != 0,
2947  rp->r_todisstd, rp->r_todisgmt);
2948  if (rp->r_hiyear == ZIC_MAX
2949  && !(0 <= lastatmax
2950  && ktime < attypes[lastatmax].at))
2951  lastatmax = timecnt;
2952  addtt(ktime, type);
2953  }
2954  }
2955  if (usestart)
2956  {
2957  if (*startbuf == '\0' &&
2958  zp->z_format != NULL &&
2959  strchr(zp->z_format, '%') == NULL &&
2960  strchr(zp->z_format, '/') == NULL)
2961  strcpy(startbuf, zp->z_format);
2962  eat(zp->z_filename, zp->z_linenum);
2963  if (*startbuf == '\0')
2964  error(_("cannot determine time zone abbreviation to use just after until time"));
2965  else
2966  addtt(starttime,
2967  addtype(startoff, startbuf,
2968  startoff != zp->z_gmtoff,
2969  startttisstd,
2970  startttisgmt));
2971  }
2972 
2973  /*
2974  * Now we may get to set starttime for the next zone line.
2975  */
2976  if (useuntil)
2977  {
2978  startttisstd = zp->z_untilrule.r_todisstd;
2979  startttisgmt = zp->z_untilrule.r_todisgmt;
2980  starttime = zp->z_untiltime;
2981  if (!startttisstd)
2982  starttime = tadd(starttime, -stdoff);
2983  if (!startttisgmt)
2984  starttime = tadd(starttime, -gmtoff);
2985  }
2986  }
2987  if (0 <= lastatmax)
2988  attypes[lastatmax].dontmerge = true;
2989  if (do_extend)
2990  {
2991  /*
2992  * If we're extending the explicitly listed observations for 400 years
2993  * because we can't fill the POSIX-TZ field, check whether we actually
2994  * ended up explicitly listing observations through that period. If
2995  * there aren't any near the end of the 400-year period, add a
2996  * redundant one at the end of the final year, to make it clear that
2997  * we are claiming to have definite knowledge of the lack of
2998  * transitions up to that point.
2999  */
3000  struct rule xr;
3001  struct attype *lastat;
3002 
3003  xr.r_month = TM_JANUARY;
3004  xr.r_dycode = DC_DOM;
3005  xr.r_dayofmonth = 1;
3006  xr.r_tod = 0;
3007  for (lastat = &attypes[0], i = 1; i < timecnt; i++)
3008  if (attypes[i].at > lastat->at)
3009  lastat = &attypes[i];
3010  if (lastat->at < rpytime(&xr, max_year - 1))
3011  {
3012  addtt(rpytime(&xr, max_year + 1), typecnt - 1);
3013  attypes[timecnt - 1].dontmerge = true;
3014  }
3015  }
3016  writezone(zpfirst->z_name, envvar, version);
3017  free(startbuf);
3018  free(ab);
3019  free(envvar);
3020 }
static bool yearistype(zic_t year, const char *type)
Definition: zic.c:3161
static void writezone(const char *const name, const char *const string, char version)
Definition: zic.c:1865
static zic_t leapmaxyear
Definition: zic.c:170
lineno_t r_linenum
Definition: zic.c:56
static int typecnt
Definition: zic.c:184
static int stringzone(char *result, struct zone const *zpfirst, ptrdiff_t zonecount)
Definition: zic.c:2512
Definition: zic.c:370
bool r_todisstd
Definition: zic.c:72
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:494
static void addtt(zic_t starttime, int type)
Definition: zic.c:3023
#define INITIALIZE(x)
Definition: private.h:98
const char * z_format
Definition: zic.c:98
#define DC_DOM
Definition: zic.c:86
zic_t z_untiltime
Definition: zic.c:107
struct rule z_untilrule
Definition: zic.c:106
static zic_t min_year
Definition: zic.c:175
static void updateminmax(const zic_t x)
Definition: zic.c:2369
static int max_format_len
Definition: zic.c:173
Definition: localtime.c:82
static const zic_t early_time
Definition: zic.c:1006
bool r_lowasnum
Definition: zic.c:62
#define ZIC_MAX
Definition: zic.c:26
const char * z_filename
Definition: zic.c:92
static zic_t tadd(zic_t t1, zic_t t2)
Definition: zic.c:3452
static int addtype(zic_t, char const *, bool, bool, bool)
Definition: zic.c:3048
bool r_todo
Definition: zic.c:78
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:21
static bool leapseen
Definition: zic.c:168
#define ZIC_VERSION
Definition: zic.c:22
static int max_abbrvar_len
Definition: zic.c:172
int64 zic_t
Definition: zic.c:24
zic_t r_hiyear
Definition: zic.c:60
const char * r_yrtype
Definition: zic.c:61
zic_t r_temp
Definition: zic.c:79
#define ZIC_MIN
Definition: zic.c:25
const char * r_filename
Definition: zic.c:55
enum COMPAT_MODE compat
Definition: ecpg.c:25
zic_t at
Definition: zic.c:372
#define EPOCH_YEAR
Definition: private.h:140
static zic_t rpytime(const struct rule *rp, zic_t wantedy)
Definition: zic.c:3481
static void eat(char const *name, lineno_t num)
Definition: zic.c:461
const char * r_abbrvar
Definition: zic.c:76
static struct attype * attypes
static zic_t const max_time
Definition: zic.c:966
static bool noise
Definition: zic.c:176
ptrdiff_t z_nrules
Definition: zic.c:104
#define TM_JANUARY
Definition: private.h:125
lineno_t z_linenum
Definition: zic.c:93
static zic_t max_year
Definition: zic.c:174
#define free(a)
Definition: header.h:65
zic_t r_stdoff
Definition: zic.c:75
#define NULL
Definition: c.h:229
zic_t z_gmtoff
Definition: zic.c:96
static ptrdiff_t timecnt
Definition: zic.c:182
static int charcnt
Definition: zic.c:163
static zic_t leapminyear
Definition: zic.c:169
#define YEARSPERREPEAT
Definition: private.h:105
struct rule * z_rules
Definition: zic.c:103
Definition: zic.c:90
bool r_hiwasnum
Definition: zic.c:63
int i
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:483
zic_t r_loyear
Definition: zic.c:59
bool r_todisgmt
Definition: zic.c:74
static zic_t const min_time
Definition: zic.c:965
bool dontmerge
Definition: zic.c:373
static void eats(char const *name, lineno_t num, char const *rname, lineno_t rnum)
Definition: zic.c:452
#define _(x)
Definition: elog.c:84
static zic_t oadd(zic_t t1, zic_t t2)
Definition: zic.c:3444
zic_t z_stdoff
Definition: zic.c:101
static void * emalloc(size_t size)
Definition: zic.c:414
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:66
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:66
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 1057 of file zic.c.

Referenced by associate().

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

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

3482 {
3483  int m,
3484  i;
3485  zic_t dayoff; /* with a nod to Margaret O. */
3486  zic_t t,
3487  y;
3488 
3489  if (wantedy == ZIC_MIN)
3490  return min_time;
3491  if (wantedy == ZIC_MAX)
3492  return max_time;
3493  dayoff = 0;
3494  m = TM_JANUARY;
3495  y = EPOCH_YEAR;
3496  while (wantedy != y)
3497  {
3498  if (wantedy > y)
3499  {
3500  i = len_years[isleap(y)];
3501  ++y;
3502  }
3503  else
3504  {
3505  --y;
3506  i = -len_years[isleap(y)];
3507  }
3508  dayoff = oadd(dayoff, i);
3509  }
3510  while (m != rp->r_month)
3511  {
3512  i = len_months[isleap(y)][m];
3513  dayoff = oadd(dayoff, i);
3514  ++m;
3515  }
3516  i = rp->r_dayofmonth;
3517  if (m == TM_FEBRUARY && i == 29 && !isleap(y))
3518  {
3519  if (rp->r_dycode == DC_DOWLEQ)
3520  --i;
3521  else
3522  {
3523  error(_("use of 2/29 in non leap-year"));
3524  exit(EXIT_FAILURE);
3525  }
3526  }
3527  --i;
3528  dayoff = oadd(dayoff, i);
3529  if (rp->r_dycode == DC_DOWGEQ || rp->r_dycode == DC_DOWLEQ)
3530  {
3531  zic_t wday;
3532 
3533 #define LDAYSPERWEEK ((zic_t) DAYSPERWEEK)
3534  wday = EPOCH_WDAY;
3535 
3536  /*
3537  * Don't trust mod of negative numbers.
3538  */
3539  if (dayoff >= 0)
3540  wday = (wday + dayoff) % LDAYSPERWEEK;
3541  else
3542  {
3543  wday -= ((-dayoff) % LDAYSPERWEEK);
3544  if (wday < 0)
3545  wday += LDAYSPERWEEK;
3546  }
3547  while (wday != rp->r_wday)
3548  if (rp->r_dycode == DC_DOWGEQ)
3549  {
3550  dayoff = oadd(dayoff, 1);
3551  if (++wday >= LDAYSPERWEEK)
3552  wday = 0;
3553  ++i;
3554  }
3555  else
3556  {
3557  dayoff = oadd(dayoff, -1);
3558  if (--wday < 0)
3559  wday = LDAYSPERWEEK - 1;
3560  --i;
3561  }
3562  if (i < 0 || i >= len_months[isleap(y)][m])
3563  {
3564  if (noise)
3565  warning(_("rule goes past start/end of month; \
3566 will not work with pre-2004 versions of zic"));
3567  }
3568  }
3569  if (dayoff < min_time / SECSPERDAY)
3570  return min_time;
3571  if (dayoff > max_time / SECSPERDAY)
3572  return max_time;
3573  t = (zic_t) dayoff * SECSPERDAY;
3574 
3575  return tadd(t, rp->r_tod);
3576 }
zic_t r_tod
Definition: zic.c:71
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:494
int r_month
Definition: zic.c:65
#define DC_DOWGEQ
Definition: zic.c:87
#define SECSPERDAY
Definition: private.h:114
#define isleap(y)
Definition: datetime.h:273
static const int len_months[2][MONSPERYEAR]
Definition: zic.c:361
#define ZIC_MAX
Definition: zic.c:26
#define LDAYSPERWEEK
static zic_t tadd(zic_t t1, zic_t t2)
Definition: zic.c:3452
int64 zic_t
Definition: zic.c:24
#define ZIC_MIN
Definition: zic.c:25
int r_dycode
Definition: zic.c:67
#define EPOCH_YEAR
Definition: private.h:140
#define DC_DOWLEQ
Definition: zic.c:88
static zic_t const max_time
Definition: zic.c:966
static bool noise
Definition: zic.c:176
#define TM_JANUARY
Definition: private.h:125
#define TM_FEBRUARY
Definition: private.h:126
int r_dayofmonth
Definition: zic.c:68
int r_wday
Definition: zic.c:69
#define EPOCH_WDAY
Definition: private.h:141
int i
#define EXIT_FAILURE
Definition: settings.h:151
static const int len_years[2]
Definition: zic.c:366
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:483
static zic_t const min_time
Definition: zic.c:965
#define _(x)
Definition: elog.c:84
static zic_t oadd(zic_t t1, zic_t t2)
Definition: zic.c:3444
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 1637 of file zic.c.

References _, byword(), DC_DOM, DC_DOWGEQ, DC_DOWLEQ, ecpyalloc(), error(), EXIT_FAILURE, free, gethms(), lookup::l_value, lowerit(), NULL, rule::r_dayofmonth, rule::r_dycode, rule::r_hiwasnum, rule::r_hiyear, rule::r_lowasnum, rule::r_loyear, rule::r_month, rule::r_tod, rule::r_todisgmt, rule::r_todisstd, rule::r_wday, rule::r_yrtype, YR_MAXIMUM, YR_MINIMUM, YR_ONLY, ZIC_MAX, and ZIC_MIN.

Referenced by inrule(), and inzsub().

1640 {
1641  const struct lookup *lp;
1642  const char *cp;
1643  char *dp;
1644  char *ep;
1645  char xs;
1646 
1647  /* PG: year_tmp is to avoid sscanf portability issues */
1648  int year_tmp;
1649 
1650  if ((lp = byword(monthp, mon_names)) == NULL)
1651  {
1652  error(_("invalid month name"));
1653  return;
1654  }
1655  rp->r_month = lp->l_value;
1656  rp->r_todisstd = false;
1657  rp->r_todisgmt = false;
1658  dp = ecpyalloc(timep);
1659  if (*dp != '\0')
1660  {
1661  ep = dp + strlen(dp) - 1;
1662  switch (lowerit(*ep))
1663  {
1664  case 's': /* Standard */
1665  rp->r_todisstd = true;
1666  rp->r_todisgmt = false;
1667  *ep = '\0';
1668  break;
1669  case 'w': /* Wall */
1670  rp->r_todisstd = false;
1671  rp->r_todisgmt = false;
1672  *ep = '\0';
1673  break;
1674  case 'g': /* Greenwich */
1675  case 'u': /* Universal */
1676  case 'z': /* Zulu */
1677  rp->r_todisstd = true;
1678  rp->r_todisgmt = true;
1679  *ep = '\0';
1680  break;
1681  }
1682  }
1683  rp->r_tod = gethms(dp, _("invalid time of day"), false);
1684  free(dp);
1685 
1686  /*
1687  * Year work.
1688  */
1689  cp = loyearp;
1690  lp = byword(cp, begin_years);
1691  rp->r_lowasnum = lp == NULL;
1692  if (!rp->r_lowasnum)
1693  switch (lp->l_value)
1694  {
1695  case YR_MINIMUM:
1696  rp->r_loyear = ZIC_MIN;
1697  break;
1698  case YR_MAXIMUM:
1699  rp->r_loyear = ZIC_MAX;
1700  break;
1701  default: /* "cannot happen" */
1702  fprintf(stderr,
1703  _("%s: panic: Invalid l_value %d\n"),
1704  progname, lp->l_value);
1705  exit(EXIT_FAILURE);
1706  }
1707  else if (sscanf(cp, "%d%c", &year_tmp, &xs) == 1)
1708  rp->r_loyear = year_tmp;
1709  else
1710  {
1711  error(_("invalid starting year"));
1712  return;
1713  }
1714  cp = hiyearp;
1715  lp = byword(cp, end_years);
1716  rp->r_hiwasnum = lp == NULL;
1717  if (!rp->r_hiwasnum)
1718  switch (lp->l_value)
1719  {
1720  case YR_MINIMUM:
1721  rp->r_hiyear = ZIC_MIN;
1722  break;
1723  case YR_MAXIMUM:
1724  rp->r_hiyear = ZIC_MAX;
1725  break;
1726  case YR_ONLY:
1727  rp->r_hiyear = rp->r_loyear;
1728  break;
1729  default: /* "cannot happen" */
1730  fprintf(stderr,
1731  _("%s: panic: Invalid l_value %d\n"),
1732  progname, lp->l_value);
1733  exit(EXIT_FAILURE);
1734  }
1735  else if (sscanf(cp, "%d%c", &year_tmp, &xs) == 1)
1736  rp->r_hiyear = year_tmp;
1737  else
1738  {
1739  error(_("invalid ending year"));
1740  return;
1741  }
1742  if (rp->r_loyear > rp->r_hiyear)
1743  {
1744  error(_("starting year greater than ending year"));
1745  return;
1746  }
1747  if (*typep == '\0')
1748  rp->r_yrtype = NULL;
1749  else
1750  {
1751  if (rp->r_loyear == rp->r_hiyear)
1752  {
1753  error(_("typed single year"));
1754  return;
1755  }
1756  rp->r_yrtype = ecpyalloc(typep);
1757  }
1758 
1759  /*
1760  * Day work. Accept things such as: 1 last-Sunday 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:263
zic_t r_tod
Definition: zic.c:71
bool r_todisstd
Definition: zic.c:72
static char * ecpyalloc(char const *str)
Definition: zic.c:426
int r_month
Definition: zic.c:65
#define DC_DOWGEQ
Definition: zic.c:87
static struct lookup const begin_years[]
Definition: zic.c:342
#define DC_DOM
Definition: zic.c:86
static const int len_months[2][MONSPERYEAR]
Definition: zic.c:361
const int l_value
Definition: zic.c:290
bool r_lowasnum
Definition: zic.c:62
#define ZIC_MAX
Definition: zic.c:26
#define YR_ONLY
Definition: zic.c:265
static struct lookup const mon_names[]
Definition: zic.c:304
Definition: zic.c:287
zic_t r_hiyear
Definition: zic.c:60
const char * r_yrtype
Definition: zic.c:61
#define ZIC_MIN
Definition: zic.c:25
static struct lookup const end_years[]
Definition: zic.c:348
int r_dycode
Definition: zic.c:67
#define DC_DOWLEQ
Definition: zic.c:88
static zic_t gethms(const char *string, const char *errstring, bool)
Definition: zic.c:1253
static const char * progname
Definition: zic.c:181
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
int r_dayofmonth
Definition: zic.c:68
int r_wday
Definition: zic.c:69
static struct lookup const * byword(const char *string, const struct lookup *lp)
Definition: zic.c:3366
static char lowerit(char)
Definition: zic.c:3279
#define YR_MAXIMUM
Definition: zic.c:264
static struct lookup const lasts[]
Definition: zic.c:331
bool r_hiwasnum
Definition: zic.c:63
static struct lookup const wday_names[]
Definition: zic.c:320
#define EXIT_FAILURE
Definition: settings.h:151
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:483
zic_t r_loyear
Definition: zic.c:59
bool r_todisgmt
Definition: zic.c:74
#define _(x)
Definition: elog.c:84
static char* shellquote ( char *  b,
char const *  s 
)
static

Definition at line 3147 of file zic.c.

Referenced by yearistype().

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

Definition at line 398 of file zic.c.

References _, memory_exhausted(), and SIZE_MAX.

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

399 {
400  if (SIZE_MAX / itemsize < nitems)
401  memory_exhausted(_("size overflow"));
402  return nitems * itemsize;
403 }
#define SIZE_MAX
Definition: private.h:52
static void memory_exhausted(const char *msg) pg_attribute_noreturn()
Definition: zic.c:391
#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:107
#define HOURSPERDAY
Definition: private.h:109
return result
Definition: formatting.c:1633
#define DAYSPERWEEK
Definition: private.h:110
#define MINSPERHOUR
Definition: private.h:108
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:107
zic_t r_tod
Definition: zic.c:71
bool r_todisstd
Definition: zic.c:72
int r_month
Definition: zic.c:65
#define DC_DOWGEQ
Definition: zic.c:87
#define SECSPERDAY
Definition: private.h:114
#define DC_DOM
Definition: zic.c:86
return result
Definition: formatting.c:1633
static const int len_months[2][MONSPERYEAR]
Definition: zic.c:361
static int stringoffset(char *result, zic_t offset)
Definition: zic.c:2378
#define DAYSPERWEEK
Definition: private.h:110
int64 zic_t
Definition: zic.c:24
enum COMPAT_MODE compat
Definition: ecpg.c:25
int r_dycode
Definition: zic.c:67
#define DC_DOWLEQ
Definition: zic.c:88
#define TM_FEBRUARY
Definition: private.h:126
zic_t r_stdoff
Definition: zic.c:75
int r_dayofmonth
Definition: zic.c:68
int r_wday
Definition: zic.c:69
bool r_todisgmt
Definition: zic.c:74
#define MINSPERHOUR
Definition: private.h:108
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, NULL, rule::r_abbrvar, rule::r_dayofmonth, rule::r_dycode, rule::r_hiwasnum, rule::r_hiyear, rule::r_month, rule::r_stdoff, rule::r_tod, rule::r_todisgmt, rule::r_todisstd, rule::r_yrtype, rule_cmp(), SECSPERDAY, SECSPERMIN, stringoffset(), stringrule(), TM_DECEMBER, TM_JANUARY, YEAR_BY_YEAR_ZONE, zone::z_gmtoff, zone::z_nrules, zone::z_rules, zone::z_stdoff, and ZIC_MAX.

Referenced by outzone().

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:107
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:114
#define TM_DECEMBER
Definition: private.h:136
static int rule_cmp(struct rule const *a, struct rule const *b)
Definition: zic.c:2494
#define DC_DOM
Definition: zic.c:86
return result
Definition: formatting.c:1633
static int stringoffset(char *result, zic_t offset)
Definition: zic.c:2378
Definition: localtime.c:82
#define ZIC_MAX
Definition: zic.c:26
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:60
const char * r_yrtype
Definition: zic.c:61
enum COMPAT_MODE compat
Definition: ecpg.c:25
const char * r_abbrvar
Definition: zic.c:76
ptrdiff_t z_nrules
Definition: zic.c:104
#define TM_JANUARY
Definition: private.h:125
zic_t r_stdoff
Definition: zic.c:75
#define NULL
Definition: c.h:229
zic_t z_gmtoff
Definition: zic.c:96
struct rule * z_rules
Definition: zic.c:103
Definition: zic.c:90
bool r_hiwasnum
Definition: zic.c:63
int i
#define MINSPERHOUR
Definition: private.h:108
zic_t z_stdoff
Definition: zic.c:101
static zic_t tadd ( zic_t  t1,
zic_t  t2 
)
static

Definition at line 3452 of file zic.c.

References max_time, min_time, and time_overflow().

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

3453 {
3454  if (t1 < 0)
3455  {
3456  if (t2 < min_time - t1)
3457  {
3458  if (t1 != min_time)
3459  time_overflow();
3460  return min_time;
3461  }
3462  }
3463  else
3464  {
3465  if (max_time - t1 < t2)
3466  {
3467  if (t1 != max_time)
3468  time_overflow();
3469  return max_time;
3470  }
3471  }
3472  return t1 + t2;
3473 }
static void time_overflow(void)
Definition: zic.c:3437
static zic_t const max_time
Definition: zic.c:966
static zic_t const min_time
Definition: zic.c:965
static void time_overflow ( void  )
static

Definition at line 3437 of file zic.c.

References _, error(), and EXIT_FAILURE.

Referenced by oadd(), and tadd().

3438 {
3439  error(_("time overflow"));
3440  exit(EXIT_FAILURE);
3441 }
#define EXIT_FAILURE
Definition: settings.h:151
static void static void error(const char *string,...) pg_attribute_printf(1
Definition: zic.c:483
#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:175
static zic_t max_year
Definition: zic.c:174
static void usage ( FILE *  stream,
int  status 
)
static

Definition at line 522 of file zic.c.

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

Referenced by main().

523 {
524  fprintf(stream,
525  _("%s: usage is %s [ --version ] [ --help ] [ -v ] [ -P ] \\\n"
526  "\t[ -l localtime ] [ -p posixrules ] [ -d directory ] \\\n"
527  "\t[ -L leapseconds ] [ filename ... ]\n\n"
528  "Report bugs to %s.\n"),
529  progname, progname, PACKAGE_BUGREPORT);
530  if (status == EXIT_SUCCESS)
531  close_file(stream, NULL, NULL);
532  exit(status);
533 }
#define EXIT_SUCCESS
Definition: settings.h:147
static const char * progname
Definition: zic.c:181
#define NULL
Definition: c.h:229
static void close_file(FILE *stream, char const *dir, char const *name)
Definition: zic.c:506
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 467 of file zic.c.

References _, NULL, and PRIdLINENO.

Referenced by error(), and warning().

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

Definition at line 494 of file zic.c.

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

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

495 {
496  va_list args;
497 
498  fprintf(stderr, _("warning: "));
499  va_start(args, string);
500  verror(string, args);
501  va_end(args);
502  warnings = true;
503 }
static bool warnings
Definition: zic.c:165
static void verror(const char *string, va_list args) pg_attribute_printf(1
Definition: zic.c:467
#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:379
static bool print_abbrevs
Definition: zic.c:177
static zic_t print_cutoff
Definition: zic.c:178
static int typecnt
Definition: zic.c:184
static zic_t gmtoffs[TZ_MAX_TYPES]
Definition: zic.c:376
static unsigned char abbrinds[TZ_MAX_TYPES]
Definition: zic.c:378
struct typedefs * types
Definition: ecpg.c:29
unsigned char type
Definition: zic.c:374
static char isdsts[TZ_MAX_TYPES]
Definition: zic.c:377
static void static void static void warning(const char *string,...) pg_attribute_printf(1
Definition: zic.c:494
static zic_t corr[TZ_MAX_LEAPS]
Definition: zic.c:383
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:380
static void mkdirs(char const *, bool)
Definition: zic.c:3617
#define GRANDPARENTED
Definition: private.h:27
static const zic_t early_time
Definition: zic.c:1006
static struct pg_tm tm
Definition: localtime.c:111
static zic_t tadd(zic_t t1, zic_t t2)
Definition: zic.c:3452
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:3048
char tzh_magic[4]
Definition: tzfile.h:35
#define TZ_MAGIC
Definition: tzfile.h:31
static int leapcnt
Definition: zic.c:167
int64 zic_t
Definition: zic.c:24
char tzh_leapcnt[4]
Definition: tzfile.h:40
#define PG_INT32_MIN
Definition: c.h:339
#define TZ_MAX_CHARS
Definition: tzfile.h:98
zic_t at
Definition: zic.c:372
static void puttzcode64(const zic_t val, FILE *const fp)
Definition: zic.c:1841
static struct attype * attypes
static bool noise
Definition: zic.c:176
Definition: tzfile.h:33
char tzh_typecnt[4]
Definition: tzfile.h:42
static const char * progname
Definition: zic.c:181
#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:182
static const char * directory
Definition: zic.c:561
static void close_file(FILE *stream, char const *dir, char const *name)
Definition: zic.c:506
#define INT64_FORMAT
Definition: c.h:315
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:382
#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:151
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:483
static char chars[TZ_MAX_CHARS]
Definition: zic.c:381
#define _(x)
Definition: elog.c:84
static size_t size_product(size_t nitems, size_t itemsize)
Definition: zic.c:398
static void puttzcode(const int32 val, FILE *const fp)
Definition: zic.c:1832
static char roll[TZ_MAX_LEAPS]
Definition: zic.c:384
static void * emalloc(size_t size)
Definition: zic.c:414
char tzh_ttisgmtcnt[4]
Definition: tzfile.h:38
static bool yearistype ( zic_t  year,
const char *  type 
)
static

Definition at line 3161 of file zic.c.

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

Referenced by outzone().

3162 {
3163  char *buf;
3164  char *b;
3165  int result;
3166 
3167  if (type == NULL || *type == '\0')
3168  return true;
3169  buf = emalloc(1 + 4 * strlen(yitcommand) + 2
3170  + INT_STRLEN_MAXIMUM(zic_t) +2 + 4 * strlen(type) + 2);
3171  b = shellquote(buf, yitcommand);
3172  *b++ = ' ';
3173  b += sprintf(b, INT64_FORMAT, year);
3174  *b++ = ' ';
3175  b = shellquote(b, type);
3176  *b = '\0';
3177  result = system(buf);
3178  if (WIFEXITED(result))
3179  {
3180  int status = WEXITSTATUS(result);
3181 
3182  if (status <= 1)
3183  {
3184  free(buf);
3185  return status == 0;
3186  }
3187  }
3188  error(_("Wild result from command execution"));
3189  fprintf(stderr, _("%s: command was '%s', result was %d\n"),
3190  progname, buf, result);
3191  exit(EXIT_FAILURE);
3192 }
#define INT_STRLEN_MAXIMUM(type)
Definition: private.h:91
#define WIFEXITED(w)
Definition: win32.h:172
return result
Definition: formatting.c:1633
static const char * yitcommand
Definition: zic.c:563
static char * shellquote(char *b, char const *s)
Definition: zic.c:3147
static char * buf
Definition: pg_test_fsync.c:66
int64 zic_t
Definition: zic.c:24
static const char * progname
Definition: zic.c:181
#define free(a)
Definition: header.h:65
#define WEXITSTATUS(w)
Definition: win32.h:174
#define NULL
Definition: c.h:229
#define INT64_FORMAT
Definition: c.h:315
#define EXIT_FAILURE
Definition: settings.h:151
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:483
#define _(x)
Definition: elog.c:84
static void * emalloc(size_t size)
Definition: zic.c:414

Variable Documentation

unsigned char abbrinds[TZ_MAX_TYPES]
static

Definition at line 378 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:263
#define NULL
Definition: c.h:229
#define YR_MAXIMUM
Definition: zic.c:264

Definition at line 342 of file zic.c.

int charcnt
static

Definition at line 163 of file zic.c.

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

char chars[TZ_MAX_CHARS]
static

Definition at line 381 of file zic.c.

Referenced by getColorInfo().

zic_t corr[TZ_MAX_LEAPS]
static

Definition at line 383 of file zic.c.

Referenced by timesub(), and tzloadbody().

const char* directory
static

Definition at line 561 of file zic.c.

Referenced by main().

const zic_t early_time
static
Initial value:
#define TIME_T_BITS_IN_FILE
Definition: zic.c:963
#define MINVAL(t, b)
Definition: private.h:82
int64 zic_t
Definition: zic.c:24
#define BIG_BANG
Definition: zic.c:991

Definition at line 1006 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:263
#define YR_ONLY
Definition: zic.c:265
#define NULL
Definition: c.h:229
#define YR_MAXIMUM
Definition: zic.c:264

Definition at line 348 of file zic.c.

bool errors
static

Definition at line 164 of file zic.c.

const char* filename
static

Definition at line 166 of file zic.c.

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

zic_t gmtoffs[TZ_MAX_TYPES]
static

Definition at line 376 of file zic.c.

char isdsts[TZ_MAX_TYPES]
static

Definition at line 377 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:121
#define TM_FRIDAY
Definition: private.h:122
#define TM_SATURDAY
Definition: private.h:123
#define TM_SUNDAY
Definition: private.h:117
#define NULL
Definition: c.h:229
#define TM_TUESDAY
Definition: private.h:119
#define TM_MONDAY
Definition: private.h:118
#define TM_WEDNESDAY
Definition: private.h:120

Definition at line 331 of file zic.c.

const char* lcltime
static

Definition at line 560 of file zic.c.

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

Definition at line 355 of file zic.c.

int leapcnt
static

Definition at line 167 of file zic.c.

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

zic_t leapmaxyear
static

Definition at line 170 of file zic.c.

zic_t leapminyear
static

Definition at line 169 of file zic.c.

const char* leapsec
static

Definition at line 562 of file zic.c.

bool leapseen
static

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

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

Definition at line 366 of file zic.c.

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

Definition at line 296 of file zic.c.

lineno_t linenum
static

Definition at line 171 of file zic.c.

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

struct link* links
static

Definition at line 283 of file zic.c.

int max_abbrvar_len = PERCENT_Z_LEN_BOUND
static

Definition at line 172 of file zic.c.

Referenced by outzone().