diff options
Diffstat (limited to 'bjnp-debug.c')
-rw-r--r-- | bjnp-debug.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/bjnp-debug.c b/bjnp-debug.c index b48dcdf..533542a 100644 --- a/bjnp-debug.c +++ b/bjnp-debug.c @@ -2,7 +2,7 @@ * debug support code * Part of: * bjnp backend for the Common UNIX Printing System (CUPS). - * Copyright 2008-2014 by Louis Lagendijk + * Copyright 2008-2020 by Louis Lagendijk * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,7 +20,7 @@ #include <stdio.h> #include <stdarg.h> -#include <sys/timeb.h> +#include <sys/time.h> #include <errno.h> #include "bjnp.h" @@ -139,7 +139,7 @@ bjnp_hexdump(bjnp_loglevel_t level, char *header, const void *d_, } - bjnp_debug(level, "%s\n", header); + bjnp_debug(level, "%s (%d bytes)\n", header, len); ofs = 0; while (ofs < len) { @@ -192,7 +192,7 @@ bjnp_debug(bjnp_loglevel_t level, const char *fmt, ...) { va_list ap; char printbuf[1024]; - struct timeb timebuf; + struct timeval timebuf; int sec; int msec; @@ -211,14 +211,16 @@ bjnp_debug(bjnp_loglevel_t level, const char *fmt, ...) /* all log messages may go to the own logfile */ if (debug_file != NULL) { - ftime(&timebuf); + gettimeofday(&timebuf, NULL); - if ((msec = timebuf.millitm - start_msec) < 0) { + msec = timebuf.tv_usec / 1000; + + if ((msec - start_msec) < 0) { msec += 1000; - timebuf.time -= 1; + timebuf.tv_sec -= 1; } - sec = timebuf.time - start_sec; + sec = timebuf.tv_sec - start_sec; fprintf(debug_file, "%8s: %03d.%03d %s", level2str(level), sec, msec, printbuf); @@ -234,12 +236,12 @@ bjnp_set_debug_level(const char *level, const char *filename) * set debug level to level (string) */ - struct timeb timebuf; + struct timeval timebuf; char loglevel[16]; - ftime(&timebuf); - start_sec = timebuf.time; - start_msec = timebuf.millitm; + gettimeofday(&timebuf, NULL); + start_sec = timebuf.tv_sec; + start_msec = timebuf.tv_usec / 1000; /* * Set log level |