#include #include #include "common/file_utils.h" #include "datatype/timestamp.h" #include "miscadmin.h" #include "pgtz.h" #include "storage/fd.h" #include "utils/hsearch.h"">

PostgreSQL Source Code: src/timezone/pgtz.c File Reference (original) (raw)

#include "[postgres.h](postgres%5F8h%5Fsource.html)"
#include <ctype.h>
#include <fcntl.h>
#include <[time.h](time%5F8h%5Fsource.html)>
#include "[common/file_utils.h](file%5F%5Futils%5F8h%5Fsource.html)"
#include "[datatype/timestamp.h](datatype%5F2timestamp%5F8h%5Fsource.html)"
#include "[miscadmin.h](miscadmin%5F8h%5Fsource.html)"
#include "[pgtz.h](pgtz%5F8h%5Fsource.html)"
#include "[storage/fd.h](fd%5F8h%5Fsource.html)"
#include "[utils/hsearch.h](hsearch%5F8h%5Fsource.html)"

Go to the source code of this file.

Functions
static bool scan_directory_ci (const char *dirname, const char *fname, int fnamelen, char *canonname, int canonnamelen)
static const char * pg_TZDIR (void)
int pg_open_tzfile (const char *name, char *canonname)
static bool init_timezone_hashtable (void)
pg_tz * pg_tzset (const char *tzname)
pg_tz * pg_tzset_offset (long gmtoffset)
void pg_timezone_initialize (void)
pg_tzenum * pg_tzenumerate_start (void)
void pg_tzenumerate_end (pg_tzenum *dir)
pg_tz * pg_tzenumerate_next (pg_tzenum *dir)
Variables
pg_tz * session_timezone = NULL
pg_tz * log_timezone = NULL
static HTAB * timezone_cache = NULL

MAX_TZDIR_DEPTH

#define MAX_TZDIR_DEPTH 10

Definition at line 383 of file pgtz.c.

init_timezone_hashtable()

static bool init_timezone_hashtable ( void ) static

Definition at line 202 of file pgtz.c.

203{

205

208

210 4,

211 &hash_ctl,

214 return false;

215

216 return true;

217}

HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)

static HTAB * timezone_cache

References HASHCTL::entrysize, hash_create(), HASH_ELEM, HASH_STRINGS, HASHCTL::keysize, timezone_cache, and TZ_STRLEN_MAX.

Referenced by pg_tzset().

pg_open_tzfile()

int pg_open_tzfile ( const char * name,
char * canonname
)

Definition at line 76 of file pgtz.c.

77{

78 const char *fname;

80 int fullnamelen;

81 int orignamelen;

82

83

85 orignamelen = fullnamelen = strlen(fullname);

86

88 return -1;

89

90

91

92

93

94

95

96

97 if (canonname == NULL)

98 {

99 int result;

100

101 fullname[fullnamelen] = '/';

102

103 strcpy(fullname + fullnamelen + 1, name);

104 result = open(fullname, O_RDONLY | PG_BINARY, 0);

105 if (result >= 0)

106 return result;

107

108 fullname[fullnamelen] = '\0';

109 }

110

111

112

113

114

115 fname = name;

116 for (;;)

117 {

118 const char *slashptr;

119 int fnamelen;

120

121 slashptr = strchr(fname, '/');

122 if (slashptr)

123 fnamelen = slashptr - fname;

124 else

125 fnamelen = strlen(fname);

127 fullname + fullnamelen + 1,

129 return -1;

130 fullname[fullnamelen++] = '/';

131 fullnamelen += strlen(fullname + fullnamelen);

132 if (slashptr)

133 fname = slashptr + 1;

134 else

135 break;

136 }

137

138 if (canonname)

140

141 return open(fullname, O_RDONLY | PG_BINARY, 0);

142}

static const char * pg_TZDIR(void)

static bool scan_directory_ci(const char *dirname, const char *fname, int fnamelen, char *canonname, int canonnamelen)

size_t strlcpy(char *dst, const char *src, size_t siz)

References MAXPGPATH, name, PG_BINARY, pg_TZDIR(), scan_directory_ci(), strlcpy(), and TZ_STRLEN_MAX.

pg_timezone_initialize()

void pg_timezone_initialize ( void )

pg_TZDIR()

static const char * pg_TZDIR ( void ) static

pg_tzenumerate_end()

pg_tzenumerate_next()

Definition at line 426 of file pgtz.c.

427{

428 while (dir->depth >= 0)

429 {

430 struct dirent *direntry;

432

434

435 if (!direntry)

436 {

437

441 continue;

442 }

443

444 if (direntry->d_name[0] == '.')

445 continue;

446

447 snprintf(fullname, sizeof(fullname), "%s/%s",

449

451 {

452

462 errmsg("could not open directory \"%s\": %m",

463 fullname)));

464

465

466 continue;

467 }

468

469

470

471

472

473

474

476 {

477

478 continue;

479 }

480

482 {

483

484 continue;

485 }

486

487

490

491

492 return &dir->tz;

493 }

494

495

496 return NULL;

497}

int errmsg_internal(const char *fmt,...)

int errcode_for_file_access(void)

int errmsg(const char *fmt,...)

#define ereport(elevel,...)

DIR * AllocateDir(const char *dirname)

struct dirent * ReadDir(DIR *dir, const char *dirname)

PGFileType get_dirent_type(const char *path, const struct dirent *de, bool look_through_symlinks, int elevel)

int tzload(const char *name, char *canonname, struct state *sp, bool doextend)

char * pstrdup(const char *in)

bool pg_tz_acceptable(pg_tz *tz)

char TZname[TZ_STRLEN_MAX+1]

References AllocateDir(), pg_tzenum::baselen, dirent::d_name, pg_tzenum::depth, pg_tzenum::dirdesc, pg_tzenum::dirname, ereport, errcode_for_file_access(), errmsg(), errmsg_internal(), ERROR, 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.

pg_tzenumerate_start()

Definition at line 397 of file pgtz.c.

398{

401

402 ret->baselen = strlen(startdir) + 1;

404 ret->dirname[0] = startdir;

409 errmsg("could not open directory \"%s\": %m", startdir)));

410 return ret;

411}

void * palloc0(Size size)

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

pg_tzset()

pg_tz * pg_tzset ( const char * tzname )

Definition at line 234 of file pgtz.c.

235{

237 struct state tzstate;

240 char *p;

241

243 return NULL;

244

247 return NULL;

248

249

250

251

252

253

254

255 p = uppername;

256 while (*tzname)

257 *p++ = pg_toupper((unsigned char) *tzname++);

258 *p = '\0';

259

261 uppername,

263 NULL);

264 if (tzp)

265 {

266

267 return &tzp->tz;

268 }

269

270

271

272

273 if (strcmp(uppername, "GMT") == 0)

274 {

275 if (tzparse(uppername, &tzstate, true))

276 {

277

278 elog(ERROR, "could not initialize GMT time zone");

279 }

280

281 strcpy(canonname, uppername);

282 }

283 else if (tzload(uppername, canonname, &tzstate, true) != 0)

284 {

285 if (uppername[0] == ':' || tzparse(uppername, &tzstate, false))

286 {

287

288 return NULL;

289 }

290

291 strcpy(canonname, uppername);

292 }

293

294

296 uppername,

298 NULL);

299

300

301 strcpy(tzp->tz.TZname, canonname);

302 memcpy(&tzp->tz.state, &tzstate, sizeof(tzstate));

303

304 return &tzp->tz;

305}

void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)

bool tzparse(const char *name, struct state *sp, bool lastditch)

static bool init_timezone_hashtable(void)

unsigned char pg_toupper(unsigned char ch)

References elog, ERROR, HASH_ENTER, HASH_FIND, hash_search(), init_timezone_hashtable(), 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 )

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

326 snprintf(offsetstr, sizeof(offsetstr),

329 if (absoffset != 0)

330 {

331 snprintf(offsetstr + strlen(offsetstr),

332 sizeof(offsetstr) - strlen(offsetstr),

335 if (absoffset != 0)

336 snprintf(offsetstr + strlen(offsetstr),

337 sizeof(offsetstr) - strlen(offsetstr),

338 ":%02ld", absoffset);

339 }

340 if (gmtoffset > 0)

341 snprintf(tzname, sizeof(tzname), "<-%s>+%s",

342 offsetstr, offsetstr);

343 else

344 snprintf(tzname, sizeof(tzname), "<+%s>-%s",

345 offsetstr, offsetstr);

346

348}

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

Referenced by check_timezone(), and DecodeTimezoneNameToTz().

scan_directory_ci()

static bool scan_directory_ci ( const char * dirname, const char * fname, int fnamelen, char * canonname, int canonnamelen ) static

Definition at line 151 of file pgtz.c.

153{

154 bool found = false;

155 DIR *dirdesc;

156 struct dirent *direntry;

157

159

161 {

162

163

164

165

166 if (direntry->d_name[0] == '.')

167 continue;

168

169 if (strlen(direntry->d_name) == fnamelen &&

171 {

172

173 strlcpy(canonname, direntry->d_name, canonnamelen);

174 found = true;

175 break;

176 }

177 }

178

180

181 return found;

182}

struct dirent * ReadDirExtended(DIR *dir, const char *dirname, int elevel)

int pg_strncasecmp(const char *s1, const char *s2, size_t n)

References AllocateDir(), dirent::d_name, FreeDir(), LOG, pg_strncasecmp(), ReadDirExtended(), and strlcpy().

Referenced by pg_open_tzfile().

log_timezone

pg_tz* log_timezone = NULL

session_timezone

pg_tz* session_timezone = NULL

Definition at line 28 of file pgtz.c.

Referenced by assign_timezone(), date2timestamptz_opt_overflow(), DecodeDateTime(), DecodeTimeOnly(), DecodeTimezoneAbbrev(), DecodeTimezoneAbbrevPrefix(), executeDateTimeMethod(), generate_series_timestamptz_internal(), GetCurrentTimeUsec(), pg_timezone_abbrevs_zone(), pg_timezone_initialize(), show_timezone(), time_timetz(), timeofday(), timestamp2timestamptz_opt_overflow(), timestamp2tm(), TimestampTimestampTzRequiresRewrite(), timestamptz_pl_interval_internal(), timestamptz_trunc(), timetz_at_local(), and to_timestamp().

timezone_cache

HTAB* timezone_cache = NULL static