示例#1
0
static int
nevra_init(_NevraObject *self, PyObject *args, PyObject *kwds)
{
    char *name, *version = NULL, *release = NULL, *arch = NULL;
    PyObject *epoch_o = NULL;
    HyNevra cnevra = NULL;

    char *kwlist[] = {"name", "epoch", "version", "release", "arch",
        "nevra", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zOzzzO&", kwlist,
	&name, &epoch_o, &version, &release, &arch, nevra_converter, &cnevra))
	return -1;
    if (name == NULL && cnevra == NULL) {
	PyErr_SetString(PyExc_ValueError,
	    "Name is required parameter.");
	return -1;
    }
    if (cnevra != NULL) {
	self->nevra = hy_nevra_clone(cnevra);
	return 0;
    }
    if (set_epoch(self, epoch_o, NULL) == -1) {
	PyErr_SetString(PyExc_TypeError,
	    "An integer value or None expected for epoch.");
	return -1;
    }
    hy_nevra_set_string(self->nevra, HY_NEVRA_NAME, name);
    hy_nevra_set_string(self->nevra, HY_NEVRA_VERSION, version);
    hy_nevra_set_string(self->nevra, HY_NEVRA_RELEASE, release);
    hy_nevra_set_string(self->nevra, HY_NEVRA_ARCH, arch);
    return 0;
}
示例#2
0
// overflows 136 years after timer epoch
u4_t timer_sec()
{
	struct timespec ts;

	if (!init) set_epoch();
	clock_gettime(CLOCK_MONOTONIC, &ts);
    return ts.tv_sec - epoch_sec;
}
示例#3
0
// overflows 1.2 hours after timer epoch
u4_t timer_us()
{
	struct timespec ts;

	if (!init) set_epoch();
	clock_gettime(CLOCK_MONOTONIC, &ts);
	int usec = ts.tv_nsec / 1000;
	assert(usec >= 0 && usec < 1000000);
    return (ts.tv_sec - epoch_sec)*1000000 + usec;	// ignore overflow
}
示例#4
0
// overflows 49.7 days after timer epoch
u4_t timer_ms()
{
	struct timespec ts;

	if (!init) set_epoch();
	clock_gettime(CLOCK_MONOTONIC, &ts);
	int msec = ts.tv_nsec/1000000;
	assert(msec >= 0 && msec < 1000);
    return (ts.tv_sec - epoch_sec)*1000 + msec;
}
示例#5
0
// never overflows (effectively)
u64_t timer_us64()
{
	struct timespec ts;
	u64_t t;

	if (!init) set_epoch();
	clock_gettime(CLOCK_MONOTONIC, &ts);
	int usec = ts.tv_nsec / 1000;
	assert(usec >= 0 && usec < 1000000);
	t = ts.tv_sec - epoch_sec;
	t *= 1000000;
	t += usec;
    return t;
}
示例#6
0
static int
nevra_init(_NevraObject *self, PyObject *args, PyObject *kwds)
{
    char *name = NULL, *version = NULL, *release = NULL, *arch = NULL;
    PyObject *epoch_o = NULL;
    Nevra * cnevra = NULL;

    const char *kwlist[] = {"name", "epoch", "version", "release", "arch",
        "nevra", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zOzzzO&", (char**) kwlist,
        &name, &epoch_o, &version, &release, &arch, nevra_converter, &cnevra))
        return -1;
    if (!name && !cnevra) {
        PyErr_SetString(PyExc_ValueError,
            "Name is required parameter.");
        return -1;
    }
    if (cnevra) {
        self->nevra = new Nevra(*cnevra);
        return 0;
    }
    if (set_epoch(self, epoch_o, NULL) == -1) {
        PyErr_SetString(PyExc_TypeError,
            "An integer value or None expected for epoch.");
        return -1;
    }
    if (name)
        self->nevra->setName(name);
    if (version)
        self->nevra->setVersion(version);
    if (release)
        self->nevra->setRelease(release);
    if (arch)
        self->nevra->setArch(arch);
    return 0;
}
示例#7
0
文件: hexdate.c 项目: doug16rogers/dr
// ---------------------------------------------------------------------------
int main(int argc, char* argv[])
{
    int i;
    struct timeval           time;
    struct HEXON_TIME_STRUCT hexon;
    struct DAYSEC_STRUCT     daysec;

    gettimeofday(&time, NULL);
    set_epoch(DEFAULT_EPOCH);
    set_format(DEFAULT_FORMAT);

    for (i = 1; i < argc; i++)
    {
        char* argument = argv[i];
        if ((strcmp(argument, "--help") == 0) || (strcmp (argument, "-h") == 0)) usage();
        else if (strequ(argument, "--epoch=" )) set_epoch(strchr(argument, '=') + 1);
        else if (strequ(argument, "--format=")) set_format(strchr(argument, '=') + 1);
        else if (strequ(argument, "--verbose")) verbose = 1;
        else if ('-' == argument[0])
        {
            fprintf(stderr, PROGRAM_NAME ": *** error: unknown option \"%s\".\n\n", argument);
            usage();
        }
        else
        {
            if (time_count >= MAX_TIMES)
            {
                fprintf(stderr, PROGRAM_NAME ": limited to %d explicit times on command line; continuing.\n", MAX_TIMES);
                break;
            }

            time_list[time_count++] = argument;
        }
    }

    /*
     * If no time is specified, use now.
     */
    if (0 == time_count)
    {
        time_list[time_count++] = "now";
    }

    /*
     * Go through the list of times to check.
     */
    for (i = 0; i < time_count; i++)
    {
        if (!daysec_from_text(&daysec, time_list[i]))
        {
            fprintf(stderr, PROGRAM_NAME ": *** error: invalid time \"%s\".\n", null_check(time_list[i]));
            usage();
        }

        if (verbose)
        {
            printf("Unix time    (seconds.microseconds): %llu.%06lu (hex 0x%llx/0x%05lx.\n",
                   (long long) time.tv_sec, (long) time.tv_usec, (long long) time.tv_sec, (long) time.tv_usec);
            printf("Unix daysec  (days.seconds): %lu.%05lu (hex 0x%lx/0x%05lx.\n",
                   daysec.day, (long) daysec.sec, daysec.day, (long) daysec.sec);
            printf("Epoch daysec (days.seconds): %lu.%05lu (hex 0x%lx/0x%05lx.\n",
                   epoch.day, (long) epoch.sec, epoch.day, (long) epoch.sec);
        }

        daysec_sub(&daysec, &daysec, &epoch);

        if (verbose)
        {
            printf("Daysec since epoch  (days.seconds): %lu.%05lu (hex 0x%lx/0x%05lx.\n",
                   daysec.day, (long) daysec.sec, daysec.day, (long) daysec.sec);
        }

        Hexon_Set_Day_Second(&hexon, daysec.day, daysec.sec);

        if (verbose)
        {
            printf("Decimal hexon = %20.6f.\n", hexon.hexon);
        }

        if (!Hexon_Print(stdout, output_format, &hexon))
        {
            fprintf(stderr, PROGRAM_NAME ": *** error: could not print using format \"%s\".\n", null_check(output_format));
            return 1;
        }
    }   /* For each time to check */

    return 0;
}   // main
示例#8
0
u4_t timer_server_start_unix_time()
{
	if (!init) set_epoch();
	return server_start_unix_time;
}
示例#9
0
u4_t timer_epoch_sec()
{
	if (!init) set_epoch();
	return epoch_sec;
}