void sysinfo(void)
{
    FILE *f = con_term;
    int fg = 0;
    const char *env = NULL;

    head();

#if defined(HAVE_LOCALTIME) && defined(HAVE_GMTIME)
    {
        char s[40];
        time_t t;

        t = time(NULL);
        tm2str(s, sizeof(s), localtime(&t));
        con_fprintf(f,"Local time is:  %s\n",s);
        tm2str(s, sizeof(s), gmtime(&t));
        con_fprintf(f,"GMT time is:    %s\n\n",s);
    }
#endif

#if defined(OPTIONS_VAR)
    env = getenv(OPTIONS_VAR);
    if (env && env[0])
        con_fprintf(f,"Contents of environment variable %s: '%s'\n\n",
                    OPTIONS_VAR, env);
    else
        con_fprintf(f,"Environment variable '%s' is not set.\n\n",
                    OPTIONS_VAR);
#endif

#if defined(USE_FOPEN)
    con_fprintf(f,"This version uses stdio for opening files.\n\n");
#endif

#if defined(__DJGPP__)
    sysinfo_djgpp();
#endif

    UNUSED(env);
    UNUSED(fg);
}
Beispiel #2
0
void time2str(char *s, size_t size, const time_t *t)
{
    assert(size >= 18);
#if (HAVE_LOCALTIME)
    tm2str(s, size, localtime(t));
#elif (HAVE_CTIME)
    const char *p = ctime(t);
    memset(s, ' ', 16);
    memcpy(s + 2, p + 4, 6);
    memcpy(s + 11, p + 11, 5);
    s[16] = 0;
#else
    s[0] = 0;
#endif
}
Beispiel #3
0
int main()
{
	char timestamp[32];
	time_t ltime;
	struct tm *tm1, tm2;
	DATETIME dt;

	/* get linux datetime */
	time(&ltime);
	tm1 = localtime(&ltime);

	printf("Struct tm format:\n");
	printf("yr=%d\n", tm1->tm_year);
	printf("mon=%d\n", tm1->tm_mon);
	printf("mday=%d\n", tm1->tm_mday);
	printf("hr=%d\n", tm1->tm_hour);
	printf("min=%d\n", tm1->tm_min);
	printf("sec=%d\n", tm1->tm_sec);

	tm2dt(tm1, &dt);
	printf("DATEIME format:\n");
	printf("yr=%x\n", dt.yr);
	printf("mon=%x\n", dt.mon);
	printf("mday=%x\n", dt.mday);
	printf("hr=%x\n", dt.hr);
	printf("min=%x\n", dt.min);
	printf("sec=%x\n", dt.sec);

	dt2tm(&dt, &tm2);
	printf("Struct tm format:\n");
	printf("yr=%d\n", tm2.tm_year);
	printf("mon=%d\n", tm2.tm_mon);
	printf("mday=%d\n", tm2.tm_mday);
	printf("hr=%d\n", tm2.tm_hour);
	printf("min=%d\n", tm2.tm_min);
	printf("sec=%d\n", tm2.tm_sec);

	/* convert datetime value to string */
	memset(timestamp, '\0', sizeof(timestamp));
	tm2str(tm1, timestamp);
	printf("%s\n", timestamp);
	
	memset(timestamp, '\0', sizeof(timestamp));
	dt2str(&dt, timestamp);
	printf("%s\n", timestamp);
	
	return 0;
}