Пример #1
0
isc_stdtime_t strtotime (const char *str, isc_int64_t now, isc_int64_t base)
{
    isc_int64_t val, offset;

    isc_result_t result;

    const char *orig = str;

    char *endp;

    if ((str[0] == '0' || str[0] == '-') && str[1] == '\0')
        return ((isc_stdtime_t) 0);

    if (strncmp (str, "now", 3) == 0)
    {
        base = now;
        str += 3;
    }

    if (str[0] == '\0')
        return ((isc_stdtime_t) base);
    else if (str[0] == '+')
    {
        offset = strtol (str + 1, &endp, 0);
        offset = time_units ((isc_stdtime_t) offset, endp, orig);
        val = base + offset;
    }
    else if (str[0] == '-')
    {
        offset = strtol (str + 1, &endp, 0);
        offset = time_units ((isc_stdtime_t) offset, endp, orig);
        val = base - offset;
    }
    else if (strlen (str) == 8U)
    {
        char timestr[15];

        sprintf (timestr, "%s000000", str);
        result = dns_time64_fromtext (timestr, &val);
        if (result != ISC_R_SUCCESS)
            fatal ("time value %s is invalid: %s", orig, isc_result_totext (result));
    }
    else if (strlen (str) > 14U)
    {
        fatal ("time value %s is invalid", orig);
    }
    else
    {
        result = dns_time64_fromtext (str, &val);
        if (result != ISC_R_SUCCESS)
            fatal ("time value %s is invalid: %s", orig, isc_result_totext (result));
    }

    return ((isc_stdtime_t) val);
}
Пример #2
0
dns_ttl_t
strtottl(const char *str) {
	const char *orig = str;
	dns_ttl_t ttl;
	char *endp;

	ttl = strtol(str, &endp, 0);
	if (ttl == 0 && endp == str)
		fatal("TTL must be numeric");
	ttl = time_units(ttl, endp, orig);
	return (ttl);
}