From 8acf94cdb5dce41d58db4a50901f410ea8bb73f5 Mon Sep 17 00:00:00 2001 From: Karl Heyes Date: Thu, 8 Jan 2009 02:18:11 +0000 Subject: [PATCH] log: When keeping around log lines, only allocate what we actually use. Allow compiler printf arg checking. timing: win32 fix, don't use timeGetTime, fixes access log timestamp svn path=/icecast/trunk/log/; revision=15610 --- log/log.c | 13 ++++++------- log/log.h | 2 +- timing/timing.c | 20 +++++++++----------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/log/log.c b/log/log.c index 9a728f1..33dfbaa 100644 --- a/log/log.c +++ b/log/log.c @@ -360,17 +360,16 @@ void log_shutdown(void) static int create_log_entry (int log_id, const char *pre, const char *line) { - int len; log_entry_t *entry; if (loglist[log_id].keep_entries == 0) return fprintf (loglist[log_id].logfile, "%s%s\n", pre, line); entry = calloc (1, sizeof (log_entry_t)); - entry->line = malloc (LOG_MAXLINELEN); - len = snprintf (entry->line, LOG_MAXLINELEN, "%s%s\n", pre, line); - entry->len = len; - loglist [log_id].total += len; + entry->len = strlen (pre) + strlen (line) + 2; + entry->line = malloc (entry->len); + snprintf (entry->line, entry->len, "%s%s\n", pre, line); + loglist [log_id].total += entry->len; fprintf (loglist[log_id].logfile, "%s", entry->line); *loglist [log_id].log_tail = entry; @@ -386,7 +385,7 @@ static int create_log_entry (int log_id, const char *pre, const char *line) } else loglist [log_id].entries++; - return len; + return entry->len; } @@ -458,9 +457,9 @@ void log_write(int log_id, unsigned priority, const char *cat, const char *func, void log_write_direct(int log_id, const char *fmt, ...) { - char line[LOG_MAXLINELEN]; va_list ap; time_t now; + char line[LOG_MAXLINELEN]; if (log_id < 0 || log_id >= LOG_MAXLOGS) return; diff --git a/log/log.h b/log/log.h index a7718f0..3733efa 100644 --- a/log/log.h +++ b/log/log.h @@ -39,6 +39,6 @@ void log_shutdown(void); void log_write(int log_id, unsigned priority, const char *cat, const char *func, const char *fmt, ...); -void log_write_direct(int log_id, const char *fmt, ...); +void log_write_direct(int log_id, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); #endif /* __LOG_H__ */ diff --git a/timing/timing.c b/timing/timing.c index c4f1b46..4aeaa25 100644 --- a/timing/timing.c +++ b/timing/timing.c @@ -27,7 +27,7 @@ #include #endif -#ifdef __MINGW32__ +#ifdef HAVE_SYS_TIMEB_H #include #endif @@ -40,21 +40,19 @@ */ uint64_t timing_get_time(void) { -#ifdef _WIN32 -#ifdef __MINGW32__ - struct timeb t; - - ftime(&t); - return t.time * 1000 + t.millitm; -#else - return timeGetTime(); -#endif -#else +#ifdef HAVE_GETTIMEOFDAY struct timeval mtv; gettimeofday(&mtv, NULL); return (uint64_t)(mtv.tv_sec) * 1000 + (uint64_t)(mtv.tv_usec) / 1000; +#elif HAVE_FTIME + struct timeb t; + + ftime(&t); + return t.time * 1000 + t.millitm; +#else +#error need time query handler #endif }