dt_status_t dt_timezone_lookup()

in src/unix/dt_unix.c [140:174]


dt_status_t dt_timezone_lookup(const char *timezone_name, dt_timezone_t *timezone)
{
    dt_status_t status = DT_UNKNOWN_ERROR;
    tz_aliases_t *aliases = NULL;
    tz_alias_iterator_t *it = TZMAP_BEGIN;
    tz_alias_t *alias = NULL;
    char path[PATH_MAX] = {0,};

    const struct state *s = NULL;

    if (timezone == NULL || timezone_name == NULL) {
        return DT_INVALID_ARGUMENT;
    }

    if ((status = tzmap_map(timezone_name, &aliases)) != DT_OK) {
        return status;
    }

    while ((status = tzmap_iterate(aliases, &it, &alias)) == DT_OK) {
        if (alias->kind == DT_PREFFERED_TZMAP_TYPE) {
            strcat(path, TZDIR);
            strcat(path, "/");
            strcat(path, alias->name);
            s = tz_alloc(path);
            if (s == NULL) {
                return DT_TIMEZONE_NOT_FOUND;
            }
            timezone->state = s;
            tzmap_free(aliases);
            return DT_OK;
        }
    }

    return status;
}