summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2025-06-09 11:41:26 +0200
committerGravatar Nikias Bassen2025-06-09 11:41:26 +0200
commit796d09d32de51e933bb300d9847c46e3a96eb9ac (patch)
tree102c999a1c250de2cfdf43aeb1f689dc4773d729
parentb9ff67fbd70074964e09c043206e19d2f5af4f41 (diff)
downloadlibimobiledevice-796d09d32de51e933bb300d9847c46e3a96eb9ac.tar.gz
libimobiledevice-796d09d32de51e933bb300d9847c46e3a96eb9ac.tar.bz2
Add milliseconds to debug messages and remove unnecessary allocations
-rw-r--r--common/debug.c42
-rw-r--r--configure.ac2
2 files changed, 24 insertions, 20 deletions
diff --git a/common/debug.c b/common/debug.c
index cf1bc2f..11aab00 100644
--- a/common/debug.c
+++ b/common/debug.c
@@ -51,27 +51,31 @@ void internal_set_debug_level(int level)
#ifndef STRIP_DEBUG_CODE
static void debug_print_line(const char *func, const char *file, int line, const char *buffer)
{
- char *str_time = NULL;
- char *header = NULL;
+ char str_time[16];
+#ifdef _WIN32
+ SYSTEMTIME lt;
+ GetLocalTime(&lt);
+ snprintf(str_time, 13, "%02d:%02d:%02d.%03d", lt.wHour, lt.wMinute, lt.wSecond, lt.wMilliseconds);
+#else
+#ifdef HAVE_GETTIMEOFDAY
+ struct timeval tv;
+ struct tm tp_;
+ struct tm *tp;
+ gettimeofday(&tv, NULL);
+#ifdef HAVE_LOCALTIME_R
+ tp = localtime_r(&tv.tv_sec, &tp_);
+#else
+ tp = localtime(&tv.tv_sec);
+#endif
+ strftime(str_time, 9, "%H:%M:%S", tp);
+ snprintf(str_time+8, 5, ".%03d", (int)tv.tv_usec/1000);
+#else
time_t the_time;
-
time(&the_time);
- str_time = (char*)malloc(255);
- strftime(str_time, 254, "%H:%M:%S", localtime (&the_time));
-
- /* generate header text */
- if(asprintf(&header, "%s %s:%d %s()", str_time, file, line, func)<0){}
- free (str_time);
-
- /* trim ending newlines */
-
- /* print header */
- fprintf(stderr, "%s: ", header);
-
- /* print actual debug content */
- fprintf(stderr, "%s\n", buffer);
-
- free (header);
+ strftime(str_time, 15, "%H:%M:%S", localtime (&the_time));
+#endif
+#endif
+ fprintf(stderr, "%s %s:%d %s(): %s\n", str_time, file, line, func, buffer);
}
#endif
diff --git a/configure.ac b/configure.ac
index 5a976c9..f2acd88 100644
--- a/configure.ac
+++ b/configure.ac
@@ -70,7 +70,7 @@ AC_TYPE_UINT32_T
AC_TYPE_UINT8_T
# Checks for library functions.
-AC_CHECK_FUNCS([asprintf strcasecmp strdup strerror strndup stpcpy vasprintf getifaddrs])
+AC_CHECK_FUNCS([asprintf strcasecmp strdup strerror strndup stpcpy vasprintf getifaddrs gettimeofday localtime_r])
AC_CHECK_HEADER(endian.h, [ac_cv_have_endian_h="yes"], [ac_cv_have_endian_h="no"])
if test "x$ac_cv_have_endian_h" = "xno"; then