summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Huston <shuston@riverace.com>2010-12-04 16:25:22 +0000
committerSteve Huston <shuston@riverace.com>2010-12-04 16:25:22 +0000
commit4250ae4c1ca8adb62a25cdf87734c4cb2258970c (patch)
treeae520666f5ae6a2953ea61c5deacaa318f8fdb94
parentfbb46a2183a1f1d8aea05b76c4a04dae60ed5a9c (diff)
downloadATCD-4250ae4c1ca8adb62a25cdf87734c4cb2258970c.tar.gz
ChangeLogTag:Sat Dec 4 14:25:26 UTC 2010 Steve Huston <shuston@riverace.com>
-rw-r--r--ACE/ChangeLog10
-rw-r--r--ACE/ace/ACE.cpp25
-rw-r--r--ACE/ace/Log_Msg.cpp59
-rw-r--r--ACE/ace/Log_Msg_UNIX_Syslog.cpp2
-rw-r--r--ACE/ace/Log_Record.cpp11
-rw-r--r--ACE/examples/Misc/test_timestamp.cpp2
6 files changed, 67 insertions, 42 deletions
diff --git a/ACE/ChangeLog b/ACE/ChangeLog
index 1694b348e15..630e49784c3 100644
--- a/ACE/ChangeLog
+++ b/ACE/ChangeLog
@@ -1,3 +1,13 @@
+Sat Dec 4 14:25:26 UTC 2010 Steve Huston <shuston@riverace.com>
+
+ * ace/ACE.cpp (timestamp):
+ * ace/Log_Msg.cpp (log):
+ * ace/Log_Msg_UNIX_Syslog.cpp (log):
+ * ace/Log_Record.cpp (format_msg):
+ * examples/Misc/test_timestamp.cpp: Cleanups, correcting buffer sizes
+ from old 35-char length to 27 based on new timestamp format. Thanks
+ to Thomas Lockhart for these.
+
Thu Dec 2 18:29:36 UTC 2010 Steve Huston <shuston@riverace.com>
* ace/ACE.{h cpp} (timestamp): Changed the format produced from
diff --git a/ACE/ace/ACE.cpp b/ACE/ace/ACE.cpp
index d3238d10123..952e83b9bed 100644
--- a/ACE/ace/ACE.cpp
+++ b/ACE/ace/ACE.cpp
@@ -2389,6 +2389,8 @@ ACE::timestamp (ACE_TCHAR date_and_time[],
// "hour:minute:second:microsecond." The month, day, and year are
// also stored in the beginning of the date_and_time array
// using ISO-8601 format.
+// 012345678901234567890123456
+// 2010-12-02 12:56:00.123456<nul>
ACE_TCHAR *
ACE::timestamp (const ACE_Time_Value& time_value,
@@ -2398,6 +2400,8 @@ ACE::timestamp (const ACE_Time_Value& time_value,
{
//ACE_TRACE ("ACE::timestamp");
+ // This magic number is from the formatting statement
+ // farther down this routine.
if (date_and_timelen < 27)
{
errno = EINVAL;
@@ -2410,16 +2414,17 @@ ACE::timestamp (const ACE_Time_Value& time_value,
time_t secs = cur_time.sec ();
struct tm tms;
ACE_OS::localtime_r (&secs, &tms);
- ACE_OS::sprintf (date_and_time,
- ACE_TEXT ("%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d.%06ld"),
- tms.tm_year + 1900,
- tms.tm_mon + 1,
- tms.tm_mday,
- tms.tm_hour,
- tms.tm_min,
- tms.tm_sec,
- cur_time.usec());
- date_and_time[26] = '\0';
+ ACE_OS::snprintf (date_and_time,
+ date_and_timelen,
+ ACE_TEXT ("%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d.%06ld"),
+ tms.tm_year + 1900,
+ tms.tm_mon + 1,
+ tms.tm_mday,
+ tms.tm_hour,
+ tms.tm_min,
+ tms.tm_sec,
+ cur_time.usec());
+ date_and_time[date_and_timelen - 1] = '\0';
return &date_and_time[11 + (return_pointer_to_first_digit != 0)];
}
diff --git a/ACE/ace/Log_Msg.cpp b/ACE/ace/Log_Msg.cpp
index 6e4844fd9ee..e14bdbe13c5 100644
--- a/ACE/ace/Log_Msg.cpp
+++ b/ACE/ace/Log_Msg.cpp
@@ -1051,27 +1051,30 @@ ACE_Log_Msg::log (const ACE_TCHAR *format_str,
}
if (timestamp_ > 0)
- {
- ACE_TCHAR day_and_time[35];
- const ACE_TCHAR *s = 0;
- if (timestamp_ == 1)
- {
- // Print just the time
- s = ACE::timestamp (day_and_time, sizeof day_and_time / sizeof (ACE_TCHAR), 1);
- }
- else
- {
- // Print time and date
- ACE::timestamp (day_and_time, sizeof day_and_time / sizeof (ACE_TCHAR));
- s = day_and_time;
- }
-
- for (; bspace > 1 && (*bp = *s) != '\0'; ++s, --bspace)
- ++bp;
-
- *bp++ = '|';
- --bspace;
- }
+ {
+ ACE_TCHAR day_and_time[27];
+ const ACE_TCHAR *s = 0;
+ if (timestamp_ == 1)
+ {
+ // Print just the time
+ s = ACE::timestamp (day_and_time,
+ sizeof (day_and_time) / sizeof (ACE_TCHAR),
+ true);
+ }
+ else
+ {
+ // Print time and date
+ ACE::timestamp (day_and_time,
+ sizeof (day_and_time) / sizeof (ACE_TCHAR));
+ s = day_and_time;
+ }
+
+ for (; bspace > 1 && (*bp = *s) != '\0'; ++s, --bspace)
+ ++bp;
+
+ *bp++ = '|';
+ --bspace;
+ }
while (*format_str != '\0' && bspace > 0)
{
@@ -1648,21 +1651,23 @@ ACE_Log_Msg::log (const ACE_TCHAR *format_str,
}
case 'D': // Format the timestamp in format:
- // Weekday Month day year hour:minute:sec.usec
+ // yyyy-mm-dd hour:minute:sec.usec
+ // This is a maximum of 27 characters
+ // including terminator.
{
- ACE_TCHAR day_and_time[35];
+ ACE_TCHAR day_and_time[27];
// Did we find the flag indicating a time value argument
if (format[1] == ACE_TEXT('#'))
{
ACE_Time_Value* time_value = va_arg (argp, ACE_Time_Value*);
ACE::timestamp (*time_value,
day_and_time,
- sizeof day_and_time / sizeof (ACE_TCHAR));
+ sizeof (day_and_time) / sizeof (ACE_TCHAR));
}
else
{
ACE::timestamp (day_and_time,
- sizeof day_and_time / sizeof (ACE_TCHAR));
+ sizeof (day_and_time) / sizeof (ACE_TCHAR));
}
#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
ACE_OS::strcpy (fp, ACE_TEXT ("ls"));
@@ -1679,9 +1684,9 @@ ACE_Log_Msg::log (const ACE_TCHAR *format_str,
}
case 'T': // Format the timestamp in
- // hour:minute:sec:usec format.
+ // hour:minute:sec.usec format.
{
- ACE_TCHAR day_and_time[35];
+ ACE_TCHAR day_and_time[27];
#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
ACE_OS::strcpy (fp, ACE_TEXT ("ls"));
#else
diff --git a/ACE/ace/Log_Msg_UNIX_Syslog.cpp b/ACE/ace/Log_Msg_UNIX_Syslog.cpp
index dba78bcd571..8fe420bc030 100644
--- a/ACE/ace/Log_Msg_UNIX_Syslog.cpp
+++ b/ACE/ace/Log_Msg_UNIX_Syslog.cpp
@@ -110,7 +110,7 @@ ACE_Log_Msg_UNIX_Syslog::log (ACE_Log_Record &log_record)
if (ACE_BIT_ENABLED (flags, ACE_Log_Msg::VERBOSE)
|| ACE_BIT_ENABLED (flags, ACE_Log_Msg::VERBOSE_LITE))
{
- ACE_TCHAR date_and_time[35];
+ ACE_TCHAR date_and_time[27];
if (0 == ACE::timestamp (date_and_time, sizeof (date_and_time), 1))
ACE_OS::strcpy (date_and_time, ACE_TEXT ("<time error>"));
const ACE_TCHAR *prio_name =
diff --git a/ACE/ace/Log_Record.cpp b/ACE/ace/Log_Record.cpp
index fb7ae019708..299b66bb480 100644
--- a/ACE/ace/Log_Record.cpp
+++ b/ACE/ace/Log_Record.cpp
@@ -5,7 +5,6 @@
#include "ace/Log_Msg.h"
#include "ace/ACE.h"
#include "ace/OS_NS_stdio.h"
-#include "ace/OS_NS_time.h"
#include "ace/CDR_Stream.h"
#include "ace/Auto_Ptr.h"
#include "ace/Truncate.h"
@@ -233,9 +232,15 @@ ACE_Log_Record::format_msg (const ACE_TCHAR host_name[],
|| ACE_BIT_ENABLED (verbose_flag,
ACE_Log_Msg::VERBOSE_LITE))
{
- ACE_Time_Value now (this->secs_, this->usecs_);
- ACE::timestamp (now, timestamp, 27);
+ ACE_Time_Value reftime (this->secs_, this->usecs_);
+ if (0 == ACE::timestamp (reftime,
+ timestamp,
+ sizeof (timestamp) / sizeof (ACE_TCHAR)))
+ return -1;
+
// Historical timestamp in VERBOSE[_LITE] used 3 places for partial sec.
+ // 012345678901234567890123456
+ // 1989-10-18 14:25:36.123<nul>
timestamp[23] = '\0';
}
diff --git a/ACE/examples/Misc/test_timestamp.cpp b/ACE/examples/Misc/test_timestamp.cpp
index 8670021d758..cf9c73f7fbc 100644
--- a/ACE/examples/Misc/test_timestamp.cpp
+++ b/ACE/examples/Misc/test_timestamp.cpp
@@ -11,7 +11,7 @@
int
ACE_TMAIN (int, ACE_TCHAR *[])
{
- ACE_TCHAR day_and_time[35];
+ ACE_TCHAR day_and_time[27];
ACE::timestamp (day_and_time,
sizeof day_and_time);