]> mj.ucw.cz Git - libucw.git/blobdiff - lib/log.c
Merge with git+ssh://git.ucw.cz/projects/sherlock/GIT/sherlock.git
[libucw.git] / lib / log.c
index e513cbe6d4719c448423a1de13768f0efe1406a8..0063f3ea7eed13d2239f28f85cda35d8a475d927 100644 (file)
--- a/lib/log.c
+++ b/lib/log.c
@@ -26,7 +26,7 @@ void (*log_die_hook)(void);
 void (*log_switch_hook)(struct tm *tm);
 
 void
 void (*log_switch_hook)(struct tm *tm);
 
 void
-vlog_msg(unsigned int cat, const char *msg, va_list args)
+vmsg(unsigned int cat, const char *fmt, va_list args)
 {
   struct timeval tv;
   struct tm tm;
 {
   struct timeval tv;
   struct tm tm;
@@ -45,7 +45,9 @@ vlog_msg(unsigned int cat, const char *msg, va_list args)
     {
       p = buf = alloca(buflen);
       *p++ = cat;
     {
       p = buf = alloca(buflen);
       *p++ = cat;
-      p += strftime(p, buflen, " %Y-%m-%d %H:%M:%S", &tm);
+      /* We cannot use strftime() here, because it's not re-entrant */
+      p += sprintf(p, " %4d-%02d-%02d %02d:%02d:%02d", tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
+                  tm.tm_hour, tm.tm_min, tm.tm_sec);
       if (log_precise_timings)
         p += sprintf(p, ".%06d", (int)tv.tv_usec);
       *p++ = ' ';
       if (log_precise_timings)
         p += sprintf(p, ".%06d", (int)tv.tv_usec);
       *p++ = ' ';
@@ -64,7 +66,7 @@ vlog_msg(unsigned int cat, const char *msg, va_list args)
       l0 = p - buf + 1;
       r = buflen - l0;
       va_copy(args2, args);
       l0 = p - buf + 1;
       r = buflen - l0;
       va_copy(args2, args);
-      l = vsnprintf(p, r, msg, args2);
+      l = vsnprintf(p, r, fmt, args2);
       va_end(args2);
       if (l < 0)
        l = r;
       va_end(args2);
       if (l < 0)
        l = r;
@@ -85,22 +87,22 @@ vlog_msg(unsigned int cat, const char *msg, va_list args)
 }
 
 void
 }
 
 void
-log_msg(unsigned int cat, const char *msg, ...)
+msg(unsigned int cat, const char *fmt, ...)
 {
   va_list args;
 
 {
   va_list args;
 
-  va_start(args, msg);
-  vlog_msg(cat, msg, args);
+  va_start(args, fmt);
+  vmsg(cat, fmt, args);
   va_end(args);
 }
 
 void
   va_end(args);
 }
 
 void
-die(const char *msg, ...)
+die(const char *fmt, ...)
 {
   va_list args;
 
 {
   va_list args;
 
-  va_start(args, msg);
-  vlog_msg(L_FATAL, msg, args);
+  va_start(args, fmt);
+  vmsg(L_FATAL, fmt, args);
   va_end(args);
   if (log_die_hook)
     log_die_hook();
   va_end(args);
   if (log_die_hook)
     log_die_hook();
@@ -112,9 +114,9 @@ die(const char *msg, ...)
 }
 
 void
 }
 
 void
-assert_failed(char *assertion, char *file, int line)
+assert_failed(const char *assertion, const char *file, int line)
 {
 {
-  log(L_FATAL, "Assertion `%s' failed at %s:%d", assertion, file, line);
+  msg(L_FATAL, "Assertion `%s' failed at %s:%d", assertion, file, line);
   abort();
 }
 
   abort();
 }
 
@@ -124,10 +126,10 @@ assert_failed_noinfo(void)
   die("Internal error: Assertion failed.");
 }
 
   die("Internal error: Assertion failed.");
 }
 
-static byte *
-log_basename(byte *n)
+static const char *
+log_basename(const char *n)
 {
 {
-  byte *p = n;
+  const char *p = n;
 
   while (*n)
     if (*n++ == '/')
 
   while (*n)
     if (*n++ == '/')
@@ -136,7 +138,7 @@ log_basename(byte *n)
 }
 
 void
 }
 
 void
-log_init(byte *argv0)
+log_init(const char *argv0)
 {
   if (argv0)
     {
 {
   if (argv0)
     {