done_tzdir = true; return tzdir; #else /* we're configured to use system's timezone database */ return SYSTEMTZDIR; #endif
}
/* *Givenatimezonename,open()thetimezonedatafile.Returnthe *filedescriptorifsuccessful,-1ifnot. * *Theinputnameissearchedforcase-insensitively(weassumethatthe *timezonedatabasedoesnotcontaincase-equivalentnames). * *If"canonname"isnotNULL,thenonsuccessthecanonicalspellingofthe *givennameisstoredthere(thebuffermustbe>TZ_STRLEN_MAXbytes!).
*/ int
pg_open_tzfile(constchar *name, char *canonname)
{ constchar *fname; char fullname[MAXPGPATH]; int fullnamelen; int orignamelen;
/* Initialize fullname with base name of tzdata directory */
strlcpy(fullname, pg_TZDIR(), sizeof(fullname));
orignamelen = fullnamelen = strlen(fullname);
if (fullnamelen + 1 + strlen(name) >= MAXPGPATH) return -1; /* not gonna fit */
/* *Ifthecallerdoesn'tneedthecanonicalspelling,firstjusttryto *openthenameas-is.Thiscanbeexpectedtosucceedifthegivenname *isalreadycase-correct,orifthefilesystemiscase-insensitive;and *wedon'tneedtodistinguishthosesituationsifwearen'ttaskedwith *reportingthecanonicalspelling.
*/ if (canonname == NULL)
{ int result;
fullname[fullnamelen] = '/'; /* test above ensured this will fit: */
strcpy(fullname + fullnamelen + 1, name);
result = open(fullname, O_RDONLY | PG_BINARY, 0); if (result >= 0) return result; /* If that didn't work, fall through to do it the hard way */
fullname[fullnamelen] = '\0';
}
/* *Looptosplitthegivennameintodirectorylevels;foreachlevel, *searchusingscan_directory_ci().
*/
fname = name; for (;;)
{ constchar *slashptr; int fnamelen;
if (strlen(tzname) > TZ_STRLEN_MAX) return NULL; /* not going to fit */
if (!timezone_cache) if (!init_timezone_hashtable()) return NULL;
/* *Upcasethegivennametoperformacase-insensitivehashtablesearch. *(Wecouldalternativelydowncaseit,butwepreferupcasesothatwe *cangetconsistentlyupcasedresultsfromtzparse()incasethenameis *aPOSIX-styletimezonespec.)
*/
p = uppername; while (*tzname)
*p++ = pg_toupper((unsignedchar) *tzname++);
*p = '\0';
tzp = (pg_tz_cache *) hash_search(timezone_cache,
uppername,
HASH_FIND,
NULL); if (tzp)
{ /* Timezone found in cache, nothing more to do */ return &tzp->tz;
}
/* *"GMT"isalwayssenttotzparse(),asperdiscussionabove.
*/ if (strcmp(uppername, "GMT") == 0)
{ if (!tzparse(uppername, &tzstate, true))
{ /* This really, really should not happen ... */
elog(ERROR, "could not initialize GMT time zone");
} /* Use uppercase name as canonical */
strcpy(canonname, uppername);
} elseif (tzload(uppername, canonname, &tzstate, true) != 0)
{ if (uppername[0] == ':' || !tzparse(uppername, &tzstate, false))
{ /* Unknown timezone. Fail our call instead of loading GMT! */ return NULL;
} /* For POSIX timezone specs, use uppercase name as canonical */
strcpy(canonname, uppername);
}
/* Save timezone in the cache */
tzp = (pg_tz_cache *) hash_search(timezone_cache,
uppername,
HASH_ENTER,
NULL);
/* hash_search already copied uppername into the hash key */
strcpy(tzp->tz.TZname, canonname);
memcpy(&tzp->tz.state, &tzstate, sizeof(tzstate));
if (get_dirent_type(fullname, direntry, true, ERROR) == PGFILETYPE_DIR)
{ /* Step into the subdirectory */ if (dir->depth >= MAX_TZDIR_DEPTH - 1)
ereport(ERROR,
(errmsg_internal("timezone directory stack overflow")));
dir->depth++;
dir->dirname[dir->depth] = pstrdup(fullname);
dir->dirdesc[dir->depth] = AllocateDir(fullname); if (!dir->dirdesc[dir->depth])
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not open directory \"%s\": %m",
fullname)));
/* Start over reading in the new directory */ continue;
}
/* *Loadthistimezoneusingtzload()notpg_tzset(),sowedon'tfill *thecache.Also,don'taskforthecanonicalspelling:wealready *knowit,andpg_open_tzfile'swayoffindingitoutispretty *inefficient.
*/ if (tzload(fullname + dir->baselen, NULL, &dir->tz.state, true) != 0)
{ /* Zone could not be loaded, ignore it */ continue;
}
if (!pg_tz_acceptable(&dir->tz))
{ /* Ignore leap-second zones */ continue;
}
/* OK, return the canonical zone name spelling. */
strlcpy(dir->tz.TZname, fullname + dir->baselen, sizeof(dir->tz.TZname));
/* Timezone loaded OK. */ return &dir->tz;
}
/* Nothing more found */ return NULL;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.28 Sekunden
(vorverarbeitet am 2026-08-04)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.