]> mj.ucw.cz Git - libucw.git/commitdiff
Logging: Use LOG_STREAM_DEFAULT to refer to the default stream.
authorMartin Mares <mj@ucw.cz>
Fri, 13 Feb 2009 23:08:17 +0000 (00:08 +0100)
committerMartin Mares <mj@ucw.cz>
Fri, 13 Feb 2009 23:08:17 +0000 (00:08 +0100)
This keeps the casts removing constness hidden.

ucw/log-file.c
ucw/log.c
ucw/log.h

index 6a060baa446686dd05af76646b218aa46c60231c..c74db01bea74535a0dbf8b8202701e19903c98f1 100644 (file)
@@ -110,7 +110,7 @@ log_file(const char *name)
     {
       struct log_stream *old = s->p;
       log_rm_substream(def, old);
-      if (old != (struct log_stream *) &log_stream_default)
+      if (old != LOG_STREAM_DEFAULT)
        log_close_stream(old);
     }
   dup2(ls->idata, 2);                  // Let fd2 be an alias for the log file
index f3c6aa146f5cc61a29cfdb403226669af356ad77..1f7eea9deb59ed416bb37c675af41b934be593ba 100644 (file)
--- a/ucw/log.c
+++ b/ucw/log.c
@@ -64,7 +64,7 @@ log_stream_by_flags(uns flags)
 {
   int n = LS_GET_STRNUM(flags);
   if (n < 0 || n >= log_streams_after || log_streams.ptr[n]->regnum == -1)
-    return (n ? NULL : (struct log_stream *) &log_stream_default);
+    return (n ? NULL : LOG_STREAM_DEFAULT);
   return log_streams.ptr[n];
 }
 
@@ -88,7 +88,7 @@ vmsg(uns cat, const char *fmt, va_list args)
   if (!ls)
     {
       msg((LS_INTERNAL_MASK&cat)|L_WARN, "No log_stream with number %d! Logging to the default log.", LS_GET_STRNUM(cat));
-      ls = (struct log_stream *) &log_stream_default;
+      ls = LOG_STREAM_DEFAULT;
     }
 
   /* Get the current time */
@@ -139,7 +139,7 @@ vmsg(uns cat, const char *fmt, va_list args)
   if (log_pass_msg(0, ls, &m))
     {
       /* Error (such as infinite loop) occurred */
-      log_pass_msg(0, (struct log_stream *) &log_stream_default, &m);
+      log_pass_msg(0, LOG_STREAM_DEFAULT, &m);
     }
 
   if (m.raw_msg != msgbuf)
@@ -160,7 +160,7 @@ log_pass_msg(int depth, struct log_stream *ls, struct log_msg *m)
       struct log_msg errm = *m;
       errm.flags = L_ERROR | (m->flags & LS_INTERNAL_MASK);
       errm.raw_msg = "Loop in the log_stream system detected.";
-      log_pass_msg(0, (struct log_stream *) &log_stream_default, &errm);
+      log_pass_msg(0, LOG_STREAM_DEFAULT, &errm);
     }
 
   /* Filter by level and hook function */
index 306c5c94984460170e5a60bd08c09bd8ba9b70e1..dcef4ae9a467cccc6e5b29c16ef3e5db08d98a37 100644 (file)
--- a/ucw/log.h
+++ b/ucw/log.h
@@ -53,6 +53,7 @@ struct log_stream
 
 /* the default logger */
 extern const struct log_stream log_stream_default;
+#define LOG_STREAM_DEFAULT ((struct log_stream *) &log_stream_default)
 
 /* A message is processed as follows:
  *  1. Discard if message level not in levels