+/*
+ * printf with a date and time stamp so that we can correlate printf's
+ * with the log files of a system in case of test failure.
+ *
+ * NB: MY_PRINTF_DATE_FMT chosen to look like syslog to aid "grep".
+ */
+#define MY_PRINTF_DATE_FMT "%b %e %T"
+#undef printf /* was my_printf */
+int
+my_printf(const char * __restrict fmt, ...)
+{
+ char *bufp;
+ char datebuf[256];
+ struct tm *timeptr;
+ time_t result;
+ int rv;
+ va_list ap;
+
+ /* Get the timestamp for this printf */
+ result = time(NULL);
+ timeptr = localtime(&result);
+ strftime(datebuf, sizeof(datebuf), MY_PRINTF_DATE_FMT, timeptr);
+
+ /* do the printf of the requested data to a local buffer */
+ va_start(ap, fmt);
+ rv = vasprintf(&bufp, fmt, ap);
+ va_end(ap);
+
+ /*
+ * if we successfully got a local buffer, then we want to
+ * print a timestamp plus what we would have printed before,
+ * then free the allocated memory.
+ */
+ if (rv != -1) {
+ rv = printf("%s %s", datebuf, bufp);
+ free(bufp);
+ }
+
+ return(rv);
+}