diff options
| author | 2025-06-09 11:41:26 +0200 | |
|---|---|---|
| committer | 2025-06-09 11:41:26 +0200 | |
| commit | 796d09d32de51e933bb300d9847c46e3a96eb9ac (patch) | |
| tree | 102c999a1c250de2cfdf43aeb1f689dc4773d729 | |
| parent | b9ff67fbd70074964e09c043206e19d2f5af4f41 (diff) | |
| download | libimobiledevice-796d09d32de51e933bb300d9847c46e3a96eb9ac.tar.gz libimobiledevice-796d09d32de51e933bb300d9847c46e3a96eb9ac.tar.bz2 | |
Add milliseconds to debug messages and remove unnecessary allocations
| -rw-r--r-- | common/debug.c | 42 | ||||
| -rw-r--r-- | configure.ac | 2 |
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) | |||
| 51 | #ifndef STRIP_DEBUG_CODE | 51 | #ifndef STRIP_DEBUG_CODE |
| 52 | static void debug_print_line(const char *func, const char *file, int line, const char *buffer) | 52 | static void debug_print_line(const char *func, const char *file, int line, const char *buffer) |
| 53 | { | 53 | { |
| 54 | char *str_time = NULL; | 54 | char str_time[16]; |
| 55 | char *header = NULL; | 55 | #ifdef _WIN32 |
| 56 | SYSTEMTIME lt; | ||
| 57 | GetLocalTime(<); | ||
| 58 | snprintf(str_time, 13, "%02d:%02d:%02d.%03d", lt.wHour, lt.wMinute, lt.wSecond, lt.wMilliseconds); | ||
| 59 | #else | ||
| 60 | #ifdef HAVE_GETTIMEOFDAY | ||
| 61 | struct timeval tv; | ||
| 62 | struct tm tp_; | ||
| 63 | struct tm *tp; | ||
| 64 | gettimeofday(&tv, NULL); | ||
| 65 | #ifdef HAVE_LOCALTIME_R | ||
| 66 | tp = localtime_r(&tv.tv_sec, &tp_); | ||
| 67 | #else | ||
| 68 | tp = localtime(&tv.tv_sec); | ||
| 69 | #endif | ||
| 70 | strftime(str_time, 9, "%H:%M:%S", tp); | ||
| 71 | snprintf(str_time+8, 5, ".%03d", (int)tv.tv_usec/1000); | ||
| 72 | #else | ||
| 56 | time_t the_time; | 73 | time_t the_time; |
| 57 | |||
| 58 | time(&the_time); | 74 | time(&the_time); |
| 59 | str_time = (char*)malloc(255); | 75 | strftime(str_time, 15, "%H:%M:%S", localtime (&the_time)); |
| 60 | strftime(str_time, 254, "%H:%M:%S", localtime (&the_time)); | 76 | #endif |
| 61 | 77 | #endif | |
| 62 | /* generate header text */ | 78 | fprintf(stderr, "%s %s:%d %s(): %s\n", str_time, file, line, func, buffer); |
| 63 | if(asprintf(&header, "%s %s:%d %s()", str_time, file, line, func)<0){} | ||
| 64 | free (str_time); | ||
| 65 | |||
| 66 | /* trim ending newlines */ | ||
| 67 | |||
| 68 | /* print header */ | ||
| 69 | fprintf(stderr, "%s: ", header); | ||
| 70 | |||
| 71 | /* print actual debug content */ | ||
| 72 | fprintf(stderr, "%s\n", buffer); | ||
| 73 | |||
| 74 | free (header); | ||
| 75 | } | 79 | } |
| 76 | #endif | 80 | #endif |
| 77 | 81 | ||
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 | |||
| 70 | AC_TYPE_UINT8_T | 70 | AC_TYPE_UINT8_T |
| 71 | 71 | ||
| 72 | # Checks for library functions. | 72 | # Checks for library functions. |
| 73 | AC_CHECK_FUNCS([asprintf strcasecmp strdup strerror strndup stpcpy vasprintf getifaddrs]) | 73 | AC_CHECK_FUNCS([asprintf strcasecmp strdup strerror strndup stpcpy vasprintf getifaddrs gettimeofday localtime_r]) |
| 74 | 74 | ||
| 75 | AC_CHECK_HEADER(endian.h, [ac_cv_have_endian_h="yes"], [ac_cv_have_endian_h="no"]) | 75 | AC_CHECK_HEADER(endian.h, [ac_cv_have_endian_h="yes"], [ac_cv_have_endian_h="no"]) |
| 76 | if test "x$ac_cv_have_endian_h" = "xno"; then | 76 | if test "x$ac_cv_have_endian_h" = "xno"; then |
