From: Julian Seward Date: Tue, 19 Jul 2005 12:17:05 +0000 (+0000) Subject: Move the code for generating a human-readable time string into its own X-Git-Tag: svn/VALGRIND_3_0_0~137 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dbca335ced2c1869e47ccd6ae9018bb74189ce0c;p=thirdparty%2Fvalgrind.git Move the code for generating a human-readable time string into its own function. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4181 --- diff --git a/coregrind/m_libcprint.c b/coregrind/m_libcprint.c index e5f32d9012..9adb6618e1 100644 --- a/coregrind/m_libcprint.c +++ b/coregrind/m_libcprint.c @@ -41,6 +41,7 @@ #include #include + /* --------------------------------------------------------------------- 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)) diff --git a/coregrind/pub_core_libcprint.h b/coregrind/pub_core_libcprint.h index 303a4305c3..15f99f8c77 100644 --- a/coregrind/pub_core_libcprint.h +++ b/coregrind/pub_core_libcprint.h @@ -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 /*--------------------------------------------------------------------*/