syslog: put variable initialization in the front
@@ -83,12 +83,11 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap)
struct lib_syslogstream_s stream;
int ret = 0;
#if CONFIG_TASK_NAME_SIZE > 0 && defined(CONFIG_SYSLOG_PROCESS_NAME)
- struct tcb_s *tcb;
+ FAR struct tcb_s *tcb = nxsched_get_tcb(gettid());
#endif
#ifdef CONFIG_SYSLOG_TIMESTAMP
struct timespec ts;
# if defined(CONFIG_SYSLOG_TIMESTAMP_FORMATTED)
- int d_ret;
struct tm tm;
char date_buf[CONFIG_SYSLOG_TIMESTAMP_BUFFER];
# endif
@@ -139,25 +138,27 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap)
# endif
}
+# if defined(CONFIG_SYSLOG_TIMESTAMP_FORMATTED)
+ date_buf[0] = '\0';
+ strftime(date_buf, CONFIG_SYSLOG_TIMESTAMP_BUFFER,
+ CONFIG_SYSLOG_TIMESTAMP_FORMAT, &tm);
+# endif
+#endif
+
#if defined(CONFIG_SYSLOG_COLOR_OUTPUT)
/* Reset the terminal style. */
ret = lib_sprintf(&stream.public, "\e[0m");
#endif
+#ifdef CONFIG_SYSLOG_TIMESTAMP
# if defined(CONFIG_SYSLOG_TIMESTAMP_FORMATTED)
- d_ret = strftime(date_buf, CONFIG_SYSLOG_TIMESTAMP_BUFFER,
- CONFIG_SYSLOG_TIMESTAMP_FORMAT, &tm);
-
- if (d_ret > 0)
- {
# if defined(CONFIG_SYSLOG_TIMESTAMP_FORMAT_MICROSECOND)
ret += lib_sprintf(&stream.public, "[%s.%06ld] ",
date_buf, ts.tv_nsec / NSEC_PER_USEC);
# else
ret += lib_sprintf(&stream.public, "[%s] ", date_buf);
# endif
- }
# else
ret += lib_sprintf(&stream.public, "[%5jd.%06ld] ",
(uintmax_t)ts.tv_sec, ts.tv_nsec / NSEC_PER_USEC);
@@ -195,7 +196,6 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap)
#if CONFIG_TASK_NAME_SIZE > 0 && defined(CONFIG_SYSLOG_PROCESS_NAME)
/* Prepend the thread name */
- tcb = nxsched_get_tcb(gettid());
ret += lib_sprintf(&stream.public, "%s: ",
tcb != NULL ? tcb->name : "(null)");
#endif
