#include "utils/datetime.h"
Go to the source code of this file.
Data Structures | |
struct | tzEntry |
Typedefs | |
typedef struct tzEntry | tzEntry |
Functions | |
TimeZoneAbbrevTable * | load_tzoffsets (const char *filename) |
TimeZoneAbbrevTable* load_tzoffsets | ( | const char * | filename | ) |
Definition at line 422 of file tzparser.c.
References ALLOCSET_SMALL_INITSIZE, ALLOCSET_SMALL_MAXSIZE, ALLOCSET_SMALL_MINSIZE, AllocSetContextCreate(), ConvertTimeZoneAbbrevs(), CurrentMemoryContext, GUC_check_errmsg, malloc, MemoryContextDelete(), MemoryContextSwitchTo(), offsetof, palloc(), and ParseTzFile().
Referenced by check_timezone_abbreviations().
{ TimeZoneAbbrevTable *result = NULL; MemoryContext tmpContext; MemoryContext oldContext; tzEntry *array; int arraysize; int n; /* * Create a temp memory context to work in. This makes it easy to clean * up afterwards. */ tmpContext = AllocSetContextCreate(CurrentMemoryContext, "TZParserMemory", ALLOCSET_SMALL_MINSIZE, ALLOCSET_SMALL_INITSIZE, ALLOCSET_SMALL_MAXSIZE); oldContext = MemoryContextSwitchTo(tmpContext); /* Initialize array at a reasonable size */ arraysize = 128; array = (tzEntry *) palloc(arraysize * sizeof(tzEntry)); /* Parse the file(s) */ n = ParseTzFile(filename, 0, &array, &arraysize, 0); /* If no errors so far, allocate result and let datetime.c convert data */ if (n >= 0) { result = malloc(offsetof(TimeZoneAbbrevTable, abbrevs) + n * sizeof(datetkn)); if (!result) GUC_check_errmsg("out of memory"); else ConvertTimeZoneAbbrevs(result, array, n); } /* Clean up */ MemoryContextSwitchTo(oldContext); MemoryContextDelete(tmpContext); return result; }