[Firebug-cvs] fireboard/beta/tools/src/xlisten/timestamp timestamp.c,NONE,1.1 timestamp.h,NONE,1.1
Brought to you by:
doolin
From: David M. D. <do...@us...> - 2005-05-19 19:58:29
|
Update of /cvsroot/firebug/fireboard/beta/tools/src/xlisten/timestamp In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3755/timestamp Added Files: timestamp.c timestamp.h Log Message: Starting code for xlisten modifications. --- NEW FILE: timestamp.h --- /** * Standard TinyOS license here. */ /** * Parts of this code were developed as part of * the NSF-ITR FireBug project. * * @author David M. Doolin * * @url http://firebug.sourceforge.net * */ /** * $Id: timestamp.h,v 1.1 2005/05/19 19:58:18 doolin Exp $ */ #ifndef FB_TIMESTAMP_H #define FB_TIMESTAMP_H #ifdef __cplusplus extern "C" { #endif #define TIMESTRING_SIZE 128 /** Incomplete type, easier to extend later. */ typedef struct _timestamp Timestamp; Timestamp * timestamp_new (void); void timestamp_delete (Timestamp * ts); /** A handy format matching a mysql's time stamping syntax. * The date written as text can be imported directly into * a mysql table. */ void timestamp_get_ymdhms (Timestamp * ts, char * timestring); void timestamp_get_string (Timestamp * ts, char * timestring); #ifdef __cplusplus } #endif #endif /* FB_TIMESTAMP_H */ --- NEW FILE: timestamp.c --- /** * Standard TinyOS license here. */ /** * Parts of this code were developed as part of * the NSF-ITR FireBug project. * * @author David M. Doolin * * @url http://firebug.sourceforge.net * */ /** * $Id: timestamp.c,v 1.1 2005/05/19 19:58:18 doolin Exp $ */ #include <time.h> #include <stdlib.h> #include <memory.h> #include <locale.h> #include "timestamp.h" #ifdef __cplusplus extern "C" { #endif struct _timestamp { struct tm * time; }; Timestamp * timestamp_new (void) { Timestamp * ts = (Timestamp*)malloc(sizeof(Timestamp)); // Shred memory to indicate initialization status. memset((void*)ts,0xda,sizeof(Timestamp)); return ts; } void timestamp_delete (Timestamp * ts) { // Shred memory going out to indicate invalid access. memset((void*)ts,0xdd,sizeof(Timestamp)); free(ts); } /** @brief Get a timestamp in MySQL compatible format. * The innards could probably be slightly * improved. See header file to check/adjust * TIMESTRING_SIZE * * @author David M. Doolin */ void timestamp_get_ymdhms (Timestamp * ts, char timestring[TIMESTRING_SIZE]) { struct tm * l_time = ts->time; time_t timetype; timetype = time(NULL); l_time = localtime(&timetype); strftime(timestring, TIMESTRING_SIZE, "%Y%m%d%H%M%S", l_time); } /** * Return string of timestamp in YYYY/MM/DD hh:mm:ss format. * * @version 2004/9/27 mturon Initial revision */ void timestamp_get_string (Timestamp * ts, char timestring[TIMESTRING_SIZE]) { struct tm * l_time = ts->time; time_t timetype; timetype = time(NULL); l_time = localtime(&timetype); strftime(timestring, TIMESTRING_SIZE, "%Y/%m/%d %H:%M:%S", l_time); } #ifdef __cplusplus } #endif |