From: Martin Mares Date: Thu, 12 Feb 2009 23:07:30 +0000 (+0100) Subject: Logging: Coding style cleanups. X-Git-Tag: holmes-import~105 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=fd2af7c42ca0574eb3dffd5c2dbae35432da12bc;p=libucw.git Logging: Coding style cleanups. Also removed a couple of unused variables. --- diff --git a/ucw/logstream.c b/ucw/logstream.c index d12688c0..97ef9d39 100644 --- a/ucw/logstream.c +++ b/ucw/logstream.c @@ -1,6 +1,17 @@ +/* + * UCW Library -- Logging + * + * (c) 2008 Tomas Gavenciak + * (c) 2009 Martin Mares + * + * This software may be freely distributed and used according to the terms + * of the GNU Lesser General Public License. + */ + #include "ucw/lib.h" #include "ucw/clists.h" #include "ucw/simple-lists.h" +#include "ucw/logstream.h" #include #include @@ -13,7 +24,6 @@ #include #include #include -#include "ucw/logstream.h" /* forward declaration */ static int ls_fdfile_handler(struct log_stream* ls, const char *m, u32 cat); @@ -56,16 +66,13 @@ int ls_streams_after = 0; * the first ls_new() (for backward compatibility and ease of use). */ static void ls_init_module(void) { - unsigned int i; if (ls_initialized) return; /* create the grow array */ - ls_streams.ptr = NULL; - ls_streams.len = 0; + lsbuf_init(&ls_streams); lsbuf_set_size(&ls_streams, LS_INIT_STREAMS); - /* bzero */ - memset(ls_streams.ptr, 0, sizeof(struct log_stream*) * (ls_streams.len)); + bzero(ls_streams.ptr, sizeof(struct log_stream*) * (ls_streams.len)); ls_streams_free = -1; ls_initialized = 1; @@ -201,7 +208,8 @@ struct log_stream *ls_bynum(int num) { if (n==0) return (struct log_stream *)&ls_default_log; - else return NULL; + else + return NULL; } return ls_streams.ptr[n]; } @@ -217,7 +225,6 @@ void ls_vmsg(unsigned int cat, const char *fmt, va_list args) char sutime[12]; char *buf,*p; int len; - int level=LS_GET_LEVEL(cat); struct log_stream *ls=ls_bynum(cat); /* Check the stream existence */ @@ -419,7 +426,7 @@ static void ls_fdfile_close(struct log_stream *ls) } /* handler for standard files */ -static int ls_fdfile_handler(struct log_stream* ls, const char *m, u32 cat) +static int ls_fdfile_handler(struct log_stream* ls, const char *m, u32 cat UNUSED) { int len = strlen(m); int r = write(ls->idata, m, len); diff --git a/ucw/logstream.h b/ucw/logstream.h index 9948a8e1..67ac4d27 100644 --- a/ucw/logstream.h +++ b/ucw/logstream.h @@ -1,3 +1,13 @@ +/* + * UCW Library -- Logging + * + * (c) 2008 Tomas Gavenciak + * (c) 2009 Martin Mares + * + * This software may be freely distributed and used according to the terms + * of the GNU Lesser General Public License. + */ + #ifndef _UCW_LOGSTREAM_H_ #define _UCW_LOGSTREAM_H_ @@ -30,7 +40,7 @@ struct log_stream void (*close)(struct log_stream* ls); }; -/* the deafult logger */ +/* the default logger */ extern const struct log_stream ls_default_log; /* A message is processed as follows: @@ -42,7 +52,7 @@ extern const struct log_stream ls_default_log; */ /* log header verbosity specifying message passed to handler */ -enum LS_FMT +enum ls_fmt { LSFMT_LEVEL=1, /* log severity level (one letter) */ LSFMT_TIME=2, /* log time (date-seconds) */ @@ -55,7 +65,7 @@ enum LS_FMT LSFMT_DEFAULT=LSFMT_LEVEL+LSFMT_TIME }; -enum LS_LEVELS +enum ls_levels { L_DEBUG=0, /* 'D' - Debugging messages */ L_INFO, /* 'I' - Informational */ @@ -80,7 +90,7 @@ enum LS_LEVELS // <8 bits: severity level> LSB // Bits per section -enum LS_FLAGBITS { +enum ls_flagbits { LS_LEVEL_BITS = 8, LS_STRNUM_BITS = 16, LS_FLAGS_BITS = 5, @@ -88,7 +98,7 @@ enum LS_FLAGBITS { }; // Section shifts -enum LS_FLAGPOS { +enum ls_flagpos { LS_LEVEL_POS = 0, LS_STRNUM_POS = LS_LEVEL_POS + LS_LEVEL_BITS, LS_FLAGS_POS = LS_STRNUM_POS + LS_STRNUM_BITS, @@ -96,7 +106,7 @@ enum LS_FLAGPOS { }; // Bitmasks -enum LS_FLAGMASKS { +enum ls_flagmasks { LS_LEVEL_MASK = (( 1 << LS_LEVEL_BITS ) - 1 ) << LS_LEVEL_POS, LS_STRNUM_MASK = (( 1 << LS_STRNUM_BITS ) - 1 ) << LS_STRNUM_POS, LS_FLAGS_MASK = (( 1 << LS_FLAGS_BITS ) - 1 ) << LS_FLAGS_POS, @@ -120,7 +130,7 @@ enum LS_FLAGMASKS { #define LSFLAG_SIGHANDLER LS_SET_INTERNAL(0x001) // The module is initialized when a first stream is created. -// Before that only the default log exists. +// Before that only the default stream exists. // Initial number of streams to allocate (must be >=2) #define LS_INIT_STREAMS 8 @@ -136,7 +146,7 @@ void ls_close(struct log_stream *ls); * use only ls_default_log */ void ls_close_all(void); -/* add a new substream, malloc()-ate a new simp_node */ +/* add a new substream, xmalloc()-ate a new simp_node */ void ls_add_substream(struct log_stream *where, struct log_stream *what); /* remove all occurences of a substream, free() the simp_node */