Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Typedefs | Functions

tzparser.h File Reference

#include "utils/datetime.h"
Include dependency graph for tzparser.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  tzEntry

Typedefs

typedef struct tzEntry tzEntry

Functions

TimeZoneAbbrevTableload_tzoffsets (const char *filename)

Typedef Documentation

typedef struct tzEntry tzEntry

Function Documentation

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;
}