Commit 4ec4a90c authored by Karl Heyes's avatar Karl Heyes

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
parent cf3e3c80
......@@ -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;
......
......@@ -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__ */
......@@ -27,7 +27,7 @@
#include <sys/select.h>
#endif
#ifdef __MINGW32__
#ifdef HAVE_SYS_TIMEB_H
#include <sys/timeb.h>
#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
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment