// // File: // // simple library to create timestamps for log files // // Written by: David M. Stanhope // #include #include "timestamp.h" char * time_string_time_t(time_t t) { static char buf[4][64]; static int idx = 0; char *s = ctime(&t); strcpy(buf[idx], s); s = buf[idx++]; if(idx > 3) idx = 0; s[24] = '\0'; // drop '\n' return s; } char * time_string_str(char *ts) { time_t t = atol (ts); return time_string_time_t(t); } char * timestamp(void) { time_t t = RIGHT_NOW; return time_string_time_t(t); } // Date: Wed, 03 Oct 2001 21:55:56 GMT // Last-Modified: Mon, 01 Oct 2001 03:11:41 GMT static char *day_name[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; static char *mon_name[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; char * web_timestamp(void) { static char buf[64]; time_t t = RIGHT_NOW; struct tm *ts = gmtime(&t); sprintf(buf, "%s, %02d %s %d %02d:%02d:%02d GMT", day_name[ts->tm_wday], ts->tm_mday , mon_name[ts->tm_mon ], ts->tm_year + 1900, ts->tm_hour, ts->tm_min, ts->tm_sec); return buf; } // // The End! //