Пример #1
0
int curl_parse_http_time(const char *t, usec_t *ret) {
        const char *e;
        locale_t loc;
        struct tm tm;
        time_t v;

        assert(t);
        assert(ret);

        loc = newlocale(LC_TIME_MASK, "C", (locale_t) 0);
        if (loc == (locale_t) 0)
                return -errno;

        /* RFC822 */
        e = strptime_l(t, "%a, %d %b %Y %H:%M:%S %Z", &tm, loc);
        if (!e || *e != 0)
                /* RFC 850 */
                e = strptime_l(t, "%A, %d-%b-%y %H:%M:%S %Z", &tm, loc);
        if (!e || *e != 0)
                /* ANSI C */
                e = strptime_l(t, "%a %b %d %H:%M:%S %Y", &tm, loc);
        freelocale(loc);
        if (!e || *e != 0)
                return -EINVAL;

        v = timegm(&tm);
        if (v == (time_t) -1)
                return -EINVAL;

        *ret = (usec_t) v * USEC_PER_SEC;
        return 0;
}
Пример #2
0
time_t c_parse_unix_time(char *fmt, char *src) {
    struct tm dst;
    init_locale();
    memset(&dst, 0, sizeof(struct tm));
#if THREAD_SAFE
    strptime_l(src, fmt, &dst, c_locale);
#else
    strptime(src, fmt, &dst);
#endif
    return mktime(&dst);
}
Пример #3
0
time_t c_parse_unix_time_gmt(char *fmt, char *src) {
    struct tm dst;
    char *local_tz;
    init_locale();
    memset(&dst, 0, sizeof(struct tm));
    local_tz = set_tz_utc();
#if THREAD_SAFE
    strptime_l(src, fmt, &dst, c_locale);
#else
    strptime(src, fmt, &dst);
#endif
    set_tz(local_tz);
    return timegm(&dst);
}