PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pgtime.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  pg_tm
 

Macros

#define TZ_STRLEN_MAX   255
 

Typedefs

typedef int64 pg_time_t
 
typedef struct pg_tz pg_tz
 
typedef struct pg_tzenum pg_tzenum
 

Functions

struct pg_tmpg_localtime (const pg_time_t *timep, const pg_tz *tz)
 
struct pg_tmpg_gmtime (const pg_time_t *timep)
 
int pg_next_dst_boundary (const pg_time_t *timep, long int *before_gmtoff, int *before_isdst, pg_time_t *boundary, long int *after_gmtoff, int *after_isdst, const pg_tz *tz)
 
bool pg_interpret_timezone_abbrev (const char *abbrev, const pg_time_t *timep, long int *gmtoff, int *isdst, const pg_tz *tz)
 
bool pg_timezone_abbrev_is_known (const char *abbrev, bool *isfixed, long int *gmtoff, int *isdst, const pg_tz *tz)
 
const charpg_get_next_timezone_abbrev (int *indx, const pg_tz *tz)
 
bool pg_get_timezone_offset (const pg_tz *tz, long int *gmtoff)
 
const charpg_get_timezone_name (pg_tz *tz)
 
bool pg_tz_acceptable (pg_tz *tz)
 
size_t pg_strftime (char *s, size_t maxsize, const char *format, const struct pg_tm *t)
 
void pg_timezone_initialize (void)
 
pg_tzpg_tzset (const char *tzname)
 
pg_tzpg_tzset_offset (long gmtoffset)
 
pg_tzenumpg_tzenumerate_start (void)
 
pg_tzpg_tzenumerate_next (pg_tzenum *dir)
 
void pg_tzenumerate_end (pg_tzenum *dir)
 

Variables

PGDLLIMPORT pg_tzsession_timezone
 
PGDLLIMPORT pg_tzlog_timezone
 

Macro Definition Documentation

◆ TZ_STRLEN_MAX

#define TZ_STRLEN_MAX   255

Definition at line 54 of file pgtime.h.

Typedef Documentation

◆ pg_time_t

Definition at line 23 of file pgtime.h.

◆ pg_tz

Definition at line 50 of file pgtime.h.

◆ pg_tzenum

Definition at line 51 of file pgtime.h.

Function Documentation

◆ pg_get_next_timezone_abbrev()

const char * pg_get_next_timezone_abbrev ( int indx,
const pg_tz tz 
)
extern

Definition at line 1939 of file localtime.c.

1941{
1942 const char *result;
1943 const struct state *sp = &tz->state;
1944 const char *abbrs;
1945 int abbrind;
1946
1947 /* If we're still in range, the result is the current abbrev. */
1948 abbrs = sp->chars;
1949 abbrind = *indx;
1950 if (abbrind < 0 || abbrind >= sp->charcnt)
1951 return NULL;
1952 result = abbrs + abbrind;
1953
1954 /* Advance *indx past this abbrev and its trailing null. */
1955 while (abbrs[abbrind] != '\0')
1956 abbrind++;
1957 abbrind++;
1958 *indx = abbrind;
1959
1960 return result;
1961}
uint32 result
static int fb(int x)
struct state state
Definition pgtz.h:69
char chars[BIGGEST(BIGGEST(TZ_MAX_CHARS+1, 4),(2 *(TZ_STRLEN_MAX+1)))]
Definition pgtz.h:53

References state::chars, fb(), result, and pg_tz::state.

Referenced by pg_timezone_abbrevs_zone().

◆ pg_get_timezone_name()

const char * pg_get_timezone_name ( pg_tz tz)
extern

Definition at line 1992 of file localtime.c.

1993{
1994 if (tz)
1995 return tz->TZname;
1996 return NULL;
1997}
char TZname[TZ_STRLEN_MAX+1]
Definition pgtz.h:68

References fb(), and pg_tz::TZname.

Referenced by pg_timezone_names(), show_log_timezone(), show_timezone(), and timetz_at_local().

◆ pg_get_timezone_offset()

bool pg_get_timezone_offset ( const pg_tz tz,
long int gmtoff 
)
extern

Definition at line 1968 of file localtime.c.

1969{
1970 /*
1971 * The zone could have more than one ttinfo, if it's historically used
1972 * more than one abbreviation. We return true as long as they all have
1973 * the same gmtoff.
1974 */
1975 const struct state *sp;
1976 int i;
1977
1978 sp = &tz->state;
1979 for (i = 1; i < sp->typecnt; i++)
1980 {
1981 if (sp->ttis[i].tt_utoff != sp->ttis[0].tt_utoff)
1982 return false;
1983 }
1984 *gmtoff = sp->ttis[0].tt_utoff;
1985 return true;
1986}
int i
Definition isn.c:77
struct ttinfo ttis[TZ_MAX_TYPES]
Definition pgtz.h:51
int_fast32_t tt_utoff
Definition pgtz.h:28

References fb(), i, pg_tz::state, ttinfo::tt_utoff, and state::ttis.

Referenced by DecodeTimeOnly(), and TimestampTimestampTzRequiresRewrite().

◆ pg_gmtime()

struct pg_tm * pg_gmtime ( const pg_time_t timep)
extern

Definition at line 1392 of file localtime.c.

1393{
1394 return gmtsub(timep, 0, &tm);
1395}
static struct pg_tm * gmtsub(pg_time_t const *timep, int_fast32_t offset, struct pg_tm *tmp)
Definition localtime.c:1360
static struct pg_tm tm
Definition localtime.c:104

References fb(), gmtsub(), and tm.

Referenced by AddFileToBackupManifest(), and GetEpochTime().

◆ pg_interpret_timezone_abbrev()

bool pg_interpret_timezone_abbrev ( const char abbrev,
const pg_time_t timep,
long int gmtoff,
int isdst,
const pg_tz tz 
)
extern

Definition at line 1746 of file localtime.c.

1751{
1752 const struct state *sp;
1753 const char *abbrs;
1754 const struct ttinfo *ttisp;
1755 int abbrind;
1756 int cutoff;
1757 int i;
1758 const pg_time_t t = *timep;
1759
1760 sp = &tz->state;
1761
1762 /*
1763 * Locate the abbreviation in the zone's abbreviation list. We assume
1764 * there are not duplicates in the list.
1765 */
1766 abbrs = sp->chars;
1767 abbrind = 0;
1768 while (abbrind < sp->charcnt)
1769 {
1770 if (strcmp(abbrev, abbrs + abbrind) == 0)
1771 break;
1772 while (abbrs[abbrind] != '\0')
1773 abbrind++;
1774 abbrind++;
1775 }
1776 if (abbrind >= sp->charcnt)
1777 return false; /* not there! */
1778
1779 /*
1780 * Unlike pg_next_dst_boundary, we needn't sweat about extrapolation
1781 * (goback/goahead zones). Finding the newest or oldest meaning of the
1782 * abbreviation should get us what we want, since extrapolation would just
1783 * be repeating the newest or oldest meanings.
1784 *
1785 * Use binary search to locate the first transition > cutoff time. (Note
1786 * that sp->timecnt could be zero, in which case this loop does nothing
1787 * and only the defaulttype entry will be checked.)
1788 */
1789 {
1790 int lo = 0;
1791 int hi = sp->timecnt;
1792
1793 while (lo < hi)
1794 {
1795 int mid = (lo + hi) >> 1;
1796
1797 if (t < sp->ats[mid])
1798 hi = mid;
1799 else
1800 lo = mid + 1;
1801 }
1802 cutoff = lo;
1803 }
1804
1805 /*
1806 * Scan backwards to find the latest interval using the given abbrev
1807 * before the cutoff time.
1808 */
1809 for (i = cutoff - 1; i >= 0; i--)
1810 {
1811 ttisp = &sp->ttis[sp->types[i]];
1812 if (ttisp->tt_desigidx == abbrind)
1813 {
1814 *gmtoff = ttisp->tt_utoff;
1815 *isdst = ttisp->tt_isdst;
1816 return true;
1817 }
1818 }
1819
1820 /*
1821 * Not found yet; check the defaulttype, which is notionally the era
1822 * before any of the entries in sp->types[].
1823 */
1824 ttisp = &sp->ttis[sp->defaulttype];
1825 if (ttisp->tt_desigidx == abbrind)
1826 {
1827 *gmtoff = ttisp->tt_utoff;
1828 *isdst = ttisp->tt_isdst;
1829 return true;
1830 }
1831
1832 /*
1833 * Not there, so scan forwards to find the first one after the cutoff.
1834 */
1835 for (i = cutoff; i < sp->timecnt; i++)
1836 {
1837 ttisp = &sp->ttis[sp->types[i]];
1838 if (ttisp->tt_desigidx == abbrind)
1839 {
1840 *gmtoff = ttisp->tt_utoff;
1841 *isdst = ttisp->tt_isdst;
1842 return true;
1843 }
1844 }
1845
1846 return false; /* hm, not actually used in any interval? */
1847}
int64 pg_time_t
Definition pgtime.h:23
Definition pgtz.h:27
static int charcnt
Definition zic.c:182

References charcnt, state::chars, fb(), i, and pg_tz::state.

Referenced by DetermineTimeZoneAbbrevOffsetInternal(), and pg_timezone_abbrevs_zone().

◆ pg_localtime()

struct pg_tm * pg_localtime ( const pg_time_t timep,
const pg_tz tz 
)
extern

Definition at line 1347 of file localtime.c.

1348{
1349 return localsub(&tz->state, timep, &tm);
1350}
static struct pg_tm * localsub(struct state const *sp, pg_time_t const *timep, struct pg_tm *const tmp)
Definition localtime.c:1262

References fb(), localsub(), pg_tz::state, and tm.

Referenced by build_backup_content(), get_formatted_log_time(), get_formatted_start_time(), log_status_format(), logfile_getname(), pg_tz_acceptable(), score_timezone(), set_next_rotation_time(), str_time(), timeofday(), and timestamp2tm().

◆ pg_next_dst_boundary()

int pg_next_dst_boundary ( const pg_time_t timep,
long int before_gmtoff,
int before_isdst,
pg_time_t boundary,
long int after_gmtoff,
int after_isdst,
const pg_tz tz 
)
extern

Definition at line 1613 of file localtime.c.

1620{
1621 const struct state *sp;
1622 const struct ttinfo *ttisp;
1623 int i;
1624 int j;
1625 const pg_time_t t = *timep;
1626
1627 sp = &tz->state;
1628 if (sp->timecnt == 0)
1629 {
1630 /* non-DST zone, use the defaulttype */
1631 ttisp = &sp->ttis[sp->defaulttype];
1633 *before_isdst = ttisp->tt_isdst;
1634 return 0;
1635 }
1636 if ((sp->goback && t < sp->ats[0]) ||
1637 (sp->goahead && t > sp->ats[sp->timecnt - 1]))
1638 {
1639 /* For values outside the transition table, extrapolate */
1640 pg_time_t newt = t;
1643 int64 icycles;
1644 int result;
1645
1646 if (t < sp->ats[0])
1647 seconds = sp->ats[0] - t;
1648 else
1649 seconds = t - sp->ats[sp->timecnt - 1];
1650 --seconds;
1652 ++tcycles;
1653 icycles = tcycles;
1654 if (tcycles - icycles >= 1 || icycles - tcycles >= 1)
1655 return -1;
1656 seconds = icycles;
1659 if (t < sp->ats[0])
1660 newt += seconds;
1661 else
1662 newt -= seconds;
1663 if (newt < sp->ats[0] ||
1664 newt > sp->ats[sp->timecnt - 1])
1665 return -1; /* "cannot happen" */
1666
1669 boundary,
1672 tz);
1673 if (t < sp->ats[0])
1674 *boundary -= seconds;
1675 else
1676 *boundary += seconds;
1677 return result;
1678 }
1679
1680 if (t >= sp->ats[sp->timecnt - 1])
1681 {
1682 /* No known transition > t, so use last known segment's type */
1683 i = sp->types[sp->timecnt - 1];
1684 ttisp = &sp->ttis[i];
1685 *before_gmtoff = ttisp->tt_utoff;
1686 *before_isdst = ttisp->tt_isdst;
1687 return 0;
1688 }
1689 if (t < sp->ats[0])
1690 {
1691 /* For "before", use the defaulttype */
1692 ttisp = &sp->ttis[sp->defaulttype];
1693 *before_gmtoff = ttisp->tt_utoff;
1694 *before_isdst = ttisp->tt_isdst;
1695 *boundary = sp->ats[0];
1696 /* And for "after", use the first segment's type */
1697 i = sp->types[0];
1698 ttisp = &sp->ttis[i];
1699 *after_gmtoff = ttisp->tt_utoff;
1700 *after_isdst = ttisp->tt_isdst;
1701 return 1;
1702 }
1703 /* Else search to find the boundary following t */
1704 {
1705 int lo = 1;
1706 int hi = sp->timecnt - 1;
1707
1708 while (lo < hi)
1709 {
1710 int mid = (lo + hi) >> 1;
1711
1712 if (t < sp->ats[mid])
1713 hi = mid;
1714 else
1715 lo = mid + 1;
1716 }
1717 i = lo;
1718 }
1719 j = sp->types[i - 1];
1720 ttisp = &sp->ttis[j];
1721 *before_gmtoff = ttisp->tt_utoff;
1722 *before_isdst = ttisp->tt_isdst;
1723 *boundary = sp->ats[i];
1724 j = sp->types[i];
1725 ttisp = &sp->ttis[j];
1726 *after_gmtoff = ttisp->tt_utoff;
1727 *after_isdst = ttisp->tt_isdst;
1728 return 1;
1729}
int64_t int64
Definition c.h:621
int j
Definition isn.c:78
int pg_next_dst_boundary(const pg_time_t *timep, long int *before_gmtoff, int *before_isdst, pg_time_t *boundary, long int *after_gmtoff, int *after_isdst, const pg_tz *tz)
Definition localtime.c:1613
#define AVGSECSPERYEAR
Definition private.h:150
#define YEARSPERREPEAT
Definition private.h:91

References AVGSECSPERYEAR, fb(), i, j, pg_next_dst_boundary(), result, pg_tz::state, ttinfo::tt_utoff, state::ttis, and YEARSPERREPEAT.

Referenced by DetermineTimeZoneOffsetInternal(), and pg_next_dst_boundary().

◆ pg_strftime()

size_t pg_strftime ( char s,
size_t  maxsize,
const char format,
const struct pg_tm t 
)
extern

Definition at line 135 of file strftime.c.

136{
137 char *p;
138 int saved_errno = errno;
139 enum warn warn = IN_NONE;
140
141 p = _fmt(format, t, s, s + maxsize, &warn);
142 if (!p)
143 {
145 if (maxsize > 0)
146 *s = '\0';
147 return 0;
148 }
149 if (p == s + maxsize)
150 {
151 errno = ERANGE;
152 if (maxsize > 0)
153 *s = '\0';
154 return 0;
155 }
156 *p = '\0';
157 errno = saved_errno;
158 return p - s;
159}
static char format
#define EOVERFLOW
Definition private.h:41
warn
Definition strftime.c:110
@ IN_NONE
Definition strftime.c:111
static char * _fmt(const char *format, const struct pg_tm *t, char *pt, const char *ptlim, enum warn *warnp)
Definition strftime.c:162

References _fmt(), EOVERFLOW, fb(), format, and IN_NONE.

Referenced by AddFileToBackupManifest(), build_backup_content(), get_formatted_log_time(), get_formatted_start_time(), log_status_format(), logfile_getname(), str_time(), and timeofday().

◆ pg_timezone_abbrev_is_known()

bool pg_timezone_abbrev_is_known ( const char abbrev,
bool isfixed,
long int gmtoff,
int isdst,
const pg_tz tz 
)
extern

Definition at line 1864 of file localtime.c.

1869{
1870 bool result = false;
1871 const struct state *sp = &tz->state;
1872 const char *abbrs;
1873 int abbrind;
1874
1875 /*
1876 * Locate the abbreviation in the zone's abbreviation list. We assume
1877 * there are not duplicates in the list.
1878 */
1879 abbrs = sp->chars;
1880 abbrind = 0;
1881 while (abbrind < sp->charcnt)
1882 {
1883 if (strcmp(abbrev, abbrs + abbrind) == 0)
1884 break;
1885 while (abbrs[abbrind] != '\0')
1886 abbrind++;
1887 abbrind++;
1888 }
1889 if (abbrind >= sp->charcnt)
1890 return false; /* definitely not there */
1891
1892 /*
1893 * Scan the ttinfo array to find uses of the abbreviation.
1894 */
1895 for (int i = 0; i < sp->typecnt; i++)
1896 {
1897 const struct ttinfo *ttisp = &sp->ttis[i];
1898
1899 if (ttisp->tt_desigidx == abbrind)
1900 {
1901 if (!result)
1902 {
1903 /* First usage */
1904 *isfixed = true; /* for the moment */
1905 *gmtoff = ttisp->tt_utoff;
1906 *isdst = ttisp->tt_isdst;
1907 result = true;
1908 }
1909 else
1910 {
1911 /* Second or later usage, does it match? */
1912 if (*gmtoff != ttisp->tt_utoff ||
1913 *isdst != ttisp->tt_isdst)
1914 {
1915 *isfixed = false;
1916 break; /* no point in looking further */
1917 }
1918 }
1919 }
1920 }
1921
1922 return result;
1923}

References charcnt, state::chars, fb(), i, result, pg_tz::state, and ttinfo::tt_utoff.

Referenced by TimeZoneAbbrevIsKnown().

◆ pg_timezone_initialize()

void pg_timezone_initialize ( void  )
extern

Definition at line 361 of file pgtz.c.

362{
363 /*
364 * We may not yet know where PGSHAREDIR is (in particular this is true in
365 * an EXEC_BACKEND subprocess). So use "GMT", which pg_tzset forces to be
366 * interpreted without reference to the filesystem. This corresponds to
367 * the bootstrap default for these variables in guc_parameters.dat,
368 * although in principle it could be different.
369 */
370 session_timezone = pg_tzset("GMT");
372}
pg_tz * log_timezone
Definition pgtz.c:31
pg_tz * pg_tzset(const char *tzname)
Definition pgtz.c:234
pg_tz * session_timezone
Definition pgtz.c:28

References log_timezone, pg_tzset(), and session_timezone.

Referenced by InitializeGUCOptions().

◆ pg_tz_acceptable()

bool pg_tz_acceptable ( pg_tz tz)
extern

Definition at line 2007 of file localtime.c.

2008{
2009 struct pg_tm *tt;
2011
2012 /*
2013 * To detect leap-second timekeeping, run pg_localtime for what should be
2014 * GMT midnight, 2000-01-01. Insist that the tm_sec value be zero; any
2015 * other result has to be due to leap seconds.
2016 */
2018 tt = pg_localtime(&time2000, tz);
2019 if (!tt || tt->tm_sec != 0)
2020 return false;
2021
2022 return true;
2023}
#define UNIX_EPOCH_JDATE
Definition timestamp.h:234
#define SECS_PER_DAY
Definition timestamp.h:126
#define POSTGRES_EPOCH_JDATE
Definition timestamp.h:235
struct pg_tm * pg_localtime(const pg_time_t *timep, const pg_tz *tz)
Definition localtime.c:1347
Definition pgtime.h:35

References fb(), pg_localtime(), POSTGRES_EPOCH_JDATE, SECS_PER_DAY, and UNIX_EPOCH_JDATE.

Referenced by check_log_timezone(), check_timezone(), pg_tzenumerate_next(), score_timezone(), and validate_zone().

◆ pg_tzenumerate_end()

void pg_tzenumerate_end ( pg_tzenum dir)
extern

Definition at line 414 of file pgtz.c.

415{
416 while (dir->depth >= 0)
417 {
418 FreeDir(dir->dirdesc[dir->depth]);
419 pfree(dir->dirname[dir->depth]);
420 dir->depth--;
421 }
422 pfree(dir);
423}
int FreeDir(DIR *dir)
Definition fd.c:3009
void pfree(void *pointer)
Definition mcxt.c:1619
char * dirname[MAX_TZDIR_DEPTH]
Definition pgtz.c:390
int depth
Definition pgtz.c:388
DIR * dirdesc[MAX_TZDIR_DEPTH]
Definition pgtz.c:389

References pg_tzenum::depth, pg_tzenum::dirdesc, pg_tzenum::dirname, FreeDir(), and pfree().

Referenced by pg_timezone_names().

◆ pg_tzenumerate_next()

pg_tz * pg_tzenumerate_next ( pg_tzenum dir)
extern

Definition at line 426 of file pgtz.c.

427{
428 while (dir->depth >= 0)
429 {
430 struct dirent *direntry;
431 char fullname[MAXPGPATH * 2];
432
433 direntry = ReadDir(dir->dirdesc[dir->depth], dir->dirname[dir->depth]);
434
435 if (!direntry)
436 {
437 /* End of this directory */
438 FreeDir(dir->dirdesc[dir->depth]);
439 pfree(dir->dirname[dir->depth]);
440 dir->depth--;
441 continue;
442 }
443
444 if (direntry->d_name[0] == '.')
445 continue;
446
447 snprintf(fullname, sizeof(fullname), "%s/%s",
448 dir->dirname[dir->depth], direntry->d_name);
449
451 {
452 /* Step into the subdirectory */
453 if (dir->depth >= MAX_TZDIR_DEPTH - 1)
455 (errmsg_internal("timezone directory stack overflow")));
456 dir->depth++;
457 dir->dirname[dir->depth] = pstrdup(fullname);
458 dir->dirdesc[dir->depth] = AllocateDir(fullname);
459 if (!dir->dirdesc[dir->depth])
462 errmsg("could not open directory \"%s\": %m",
463 fullname)));
464
465 /* Start over reading in the new directory */
466 continue;
467 }
468
469 /*
470 * Load this timezone using tzload() not pg_tzset(), so we don't fill
471 * the cache. Also, don't ask for the canonical spelling: we already
472 * know it, and pg_open_tzfile's way of finding it out is pretty
473 * inefficient.
474 */
475 if (tzload(fullname + dir->baselen, NULL, &dir->tz.state, true) != 0)
476 {
477 /* Zone could not be loaded, ignore it */
478 continue;
479 }
480
481 if (!pg_tz_acceptable(&dir->tz))
482 {
483 /* Ignore leap-second zones */
484 continue;
485 }
486
487 /* OK, return the canonical zone name spelling. */
488 strlcpy(dir->tz.TZname, fullname + dir->baselen,
489 sizeof(dir->tz.TZname));
490
491 /* Timezone loaded OK. */
492 return &dir->tz;
493 }
494
495 /* Nothing more found */
496 return NULL;
497}
int errcode_for_file_access(void)
Definition elog.c:898
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
#define ERROR
Definition elog.h:40
#define ereport(elevel,...)
Definition elog.h:152
DIR * AllocateDir(const char *dirname)
Definition fd.c:2891
struct dirent * ReadDir(DIR *dir, const char *dirname)
Definition fd.c:2957
PGFileType get_dirent_type(const char *path, const struct dirent *de, bool look_through_symlinks, int elevel)
Definition file_utils.c:547
@ PGFILETYPE_DIR
Definition file_utils.h:23
int tzload(char const *name, char *canonname, struct state *sp, bool doextend)
Definition localtime.c:589
char * pstrdup(const char *in)
Definition mcxt.c:1910
static char * errmsg
#define MAXPGPATH
bool pg_tz_acceptable(pg_tz *tz)
Definition localtime.c:2007
#define MAX_TZDIR_DEPTH
Definition pgtz.c:383
#define snprintf
Definition port.h:261
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition strlcpy.c:45
int baselen
Definition pgtz.c:387
struct pg_tz tz
Definition pgtz.c:391

References AllocateDir(), pg_tzenum::baselen, pg_tzenum::depth, pg_tzenum::dirdesc, pg_tzenum::dirname, ereport, errcode_for_file_access(), errmsg, errmsg_internal(), ERROR, fb(), FreeDir(), get_dirent_type(), MAX_TZDIR_DEPTH, MAXPGPATH, pfree(), pg_tz_acceptable(), PGFILETYPE_DIR, pstrdup(), ReadDir(), snprintf, pg_tz::state, strlcpy(), pg_tzenum::tz, tzload(), and pg_tz::TZname.

Referenced by pg_timezone_names().

◆ pg_tzenumerate_start()

pg_tzenum * pg_tzenumerate_start ( void  )
extern

Definition at line 397 of file pgtz.c.

398{
400 char *startdir = pstrdup(pg_TZDIR());
401
402 ret->baselen = strlen(startdir) + 1;
403 ret->depth = 0;
404 ret->dirname[0] = startdir;
405 ret->dirdesc[0] = AllocateDir(startdir);
406 if (!ret->dirdesc[0])
409 errmsg("could not open directory \"%s\": %m", startdir)));
410 return ret;
411}
#define palloc0_object(type)
Definition fe_memutils.h:90
static const char * pg_TZDIR(void)
Definition pgtz.c:43

References AllocateDir(), pg_tzenum::baselen, pg_tzenum::depth, pg_tzenum::dirdesc, pg_tzenum::dirname, ereport, errcode_for_file_access(), errmsg, ERROR, fb(), palloc0_object, pg_TZDIR(), and pstrdup().

Referenced by pg_timezone_names().

◆ pg_tzset()

pg_tz * pg_tzset ( const char tzname)
extern

Definition at line 234 of file pgtz.c.

235{
236 pg_tz_cache *tzp;
237 struct state tzstate;
238 char uppername[TZ_STRLEN_MAX + 1];
239 char canonname[TZ_STRLEN_MAX + 1];
240 char *p;
241
243 return NULL; /* not going to fit */
244
245 if (!timezone_cache)
247 return NULL;
248
249 /*
250 * Upcase the given name to perform a case-insensitive hashtable search.
251 * (We could alternatively downcase it, but we prefer upcase so that we
252 * can get consistently upcased results from tzparse() in case the name is
253 * a POSIX-style timezone spec.)
254 */
255 p = uppername;
256 while (*tzname)
257 *p++ = pg_toupper((unsigned char) *tzname++);
258 *p = '\0';
259
261 uppername,
262 HASH_FIND,
263 NULL);
264 if (tzp)
265 {
266 /* Timezone found in cache, nothing more to do */
267 return &tzp->tz;
268 }
269
270 /*
271 * "GMT" is always sent to tzparse(), as per discussion above.
272 */
273 if (strcmp(uppername, "GMT") == 0)
274 {
275 if (!tzparse(uppername, &tzstate, true))
276 {
277 /* This really, really should not happen ... */
278 elog(ERROR, "could not initialize GMT time zone");
279 }
280 /* Use uppercase name as canonical */
282 }
283 else if (tzload(uppername, canonname, &tzstate, true) != 0)
284 {
285 if (uppername[0] == ':' || !tzparse(uppername, &tzstate, false))
286 {
287 /* Unknown timezone. Fail our call instead of loading GMT! */
288 return NULL;
289 }
290 /* For POSIX timezone specs, use uppercase name as canonical */
292 }
293
294 /* Save timezone in the cache */
296 uppername,
298 NULL);
299
300 /* hash_search already copied uppername into the hash key */
301 strcpy(tzp->tz.TZname, canonname);
302 memcpy(&tzp->tz.state, &tzstate, sizeof(tzstate));
303
304 return &tzp->tz;
305}
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition dynahash.c:889
#define elog(elevel,...)
Definition elog.h:228
@ HASH_FIND
Definition hsearch.h:108
@ HASH_ENTER
Definition hsearch.h:109
bool tzparse(const char *name, struct state *sp, bool lastditch)
Definition localtime.c:939
#define TZ_STRLEN_MAX
Definition pgtime.h:54
static HTAB * timezone_cache
Definition pgtz.c:198
static bool init_timezone_hashtable(void)
Definition pgtz.c:202
unsigned char pg_toupper(unsigned char ch)
pg_tz tz
Definition pgtz.c:195

References elog, ERROR, fb(), HASH_ENTER, HASH_FIND, hash_search(), init_timezone_hashtable(), memcpy(), pg_toupper(), pg_tz::state, timezone_cache, pg_tz_cache::tz, TZ_STRLEN_MAX, tzload(), pg_tz::TZname, and tzparse().

Referenced by check_log_timezone(), check_timezone(), DecodeDateTime(), DecodeTimeOnly(), DecodeTimezoneName(), FetchDynamicTimeZone(), pg_timezone_initialize(), and pg_tzset_offset().

◆ pg_tzset_offset()

pg_tz * pg_tzset_offset ( long  gmtoffset)
extern

Definition at line 320 of file pgtz.c.

321{
322 long absoffset = (gmtoffset < 0) ? -gmtoffset : gmtoffset;
323 char offsetstr[64];
324 char tzname[128];
325
327 "%02ld", absoffset / SECS_PER_HOUR);
329 if (absoffset != 0)
330 {
332 sizeof(offsetstr) - strlen(offsetstr),
333 ":%02ld", absoffset / SECS_PER_MINUTE);
335 if (absoffset != 0)
337 sizeof(offsetstr) - strlen(offsetstr),
338 ":%02ld", absoffset);
339 }
340 if (gmtoffset > 0)
341 snprintf(tzname, sizeof(tzname), "<-%s>+%s",
343 else
344 snprintf(tzname, sizeof(tzname), "<+%s>-%s",
346
347 return pg_tzset(tzname);
348}
#define SECS_PER_HOUR
Definition timestamp.h:127
#define SECS_PER_MINUTE
Definition timestamp.h:128

References fb(), pg_tzset(), SECS_PER_HOUR, SECS_PER_MINUTE, and snprintf.

Referenced by check_timezone(), and DecodeTimezoneNameToTz().

Variable Documentation

◆ log_timezone

◆ session_timezone