コード例 #1
0
ファイル: dnssectool.c プロジェクト: rodrigc/bz-vimage
isc_stdtime_t
strtotime(const char *str, isc_int64_t now, isc_int64_t base) {
	isc_int64_t val, offset;
	isc_result_t result;
	char *endp;

	if (str[0] == '+') {
		offset = strtol(str + 1, &endp, 0);
		if (*endp != '\0')
			fatal("time value %s is invalid", str);
		val = base + offset;
	} else if (strncmp(str, "now+", 4) == 0) {
		offset = strtol(str + 4, &endp, 0);
		if (*endp != '\0')
			fatal("time value %s is invalid", str);
		val = now + 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", str);
	} else {
		result = dns_time64_fromtext(str, &val);
		if (result != ISC_R_SUCCESS)
			fatal("time value %s is invalid", str);
	}

	return ((isc_stdtime_t) val);
}
コード例 #2
0
ファイル: dnssectool.c プロジェクト: 274914765/C
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);
}
コード例 #3
0
isc_result_t
dns_time32_fromtext(const char *source, isc_uint32_t *target) {
	isc_int64_t value64;
	isc_result_t result;
	result = dns_time64_fromtext(source, &value64);
	if (result != ISC_R_SUCCESS)
		return (result);
	*target = (isc_uint32_t)value64;

	return (ISC_R_SUCCESS);
}