Move the code for generating a human-readable time string into its own

function.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4181
This commit is contained in:
Julian Seward 2005-07-19 12:17:05 +00:00
parent 89b76a72f4
commit dbca335ced
2 changed files with 31 additions and 11 deletions

View File

@ -41,6 +41,7 @@
#include <time.h>
#include <sys/time.h>
/* ---------------------------------------------------------------------
Writing to file or a socket
------------------------------------------------------------------ */
@ -197,6 +198,29 @@ void VG_(percentify)(UInt n, UInt m, UInt d, Int n_buf, char buf[])
for (i = 0; i < space; i++) buf[i] = ' ';
}
/* ---------------------------------------------------------------------
ctime()
------------------------------------------------------------------ */
/* BUF must be at least 25 characters long. This is unchecked. */
void VG_(ctime) ( /*OUT*/HChar* buf )
{
struct timeval tv;
struct tm tm;
buf[0] = 0;
if ( gettimeofday( &tv, NULL ) == 0
&& localtime_r( &tv.tv_sec, &tm ) == &tm )
{
VG_(sprintf)( buf,
"%04d-%02d-%02d %02d:%02d:%02d.%03d",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tv.tv_usec / 1000 );
}
}
/* ---------------------------------------------------------------------
message()
------------------------------------------------------------------ */
@ -228,17 +252,9 @@ UInt VG_(vmessage) ( VgMsgKind kind, const HChar* format, va_list vargs )
count += VG_(printf) ("%s%c%c", pfx_s, c,c);
if (VG_(clo_time_stamp)) {
struct timeval tv;
struct tm tm;
if ( gettimeofday( &tv, NULL ) == 0 &&
localtime_r( &tv.tv_sec, &tm ) == &tm )
{
count +=
VG_(printf)( "%04d-%02d-%02d %02d:%02d:%02d.%03d ",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tv.tv_usec / 1000 );
}
HChar buf[50];
VG_(ctime)(buf);
count += VG_(printf)( "%s ", buf);
}
if (!VG_(clo_xml))

View File

@ -42,6 +42,10 @@
descriptor or a socket descriptor. */
extern Bool VG_(logging_to_socket);
/* Get a human-readable representation of the local time into BUF,
which must be at least 25 characters long. This is unchecked. */
extern void VG_(ctime) ( /*OUT*/HChar* buf );
#endif // __PUB_CORE_LIBCPRINT_H
/*--------------------------------------------------------------------*/