From 48e3b833c6bb930a29a8aaf194cdef8b9ed5d1b4 Mon Sep 17 00:00:00 2001 From: Nabeel Sowan Date: Wed, 1 Jul 2009 11:03:25 +0200 Subject: [PATCH] Add sanity checks to output plugins / Add config option FLOG_CONFIG_MSG_ID_STRINGS_EXTENDED --- config.h | 6 ++++++ flog_msg_id.h | 9 +++++++-- flog_output_file.h | 11 +++++++++++ flog_output_stdio.h | 11 +++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/config.h b/config.h index abca6bc..fdaac87 100644 --- a/config.h +++ b/config.h @@ -70,6 +70,12 @@ #define FLOG_CONFIG_MSG_ID_STRINGS +//! @def FLOG_CONFIG_MSG_ID_STRINGS_EXTENDED +//! If defined, a couple of useful message strings will be included in flog. +//! Undefine this to save a little bit of memory. +#define FLOG_CONFIG_MSG_ID_STRINGS_EXTENDED + + //! @def FLOG_CONFIG_ERRNO_STRINGS //! If defined, then setting msg_id to a valid libc errno will fetch the //! correct string from libc when outputing a string. diff --git a/flog_msg_id.h b/flog_msg_id.h index 6649dde..f38e1ca 100644 --- a/flog_msg_id.h +++ b/flog_msg_id.h @@ -16,6 +16,7 @@ #include "config.h" //! Amount of msg_id entries reserved for passing errno values +//! @todo make configurable, move out #define FLOG_MSG_ID_AMOUNT_RESERVED_FOR_ERRNO 8000 @@ -28,14 +29,18 @@ X(FLOG_MSG_FUNCTION_END, "Function end" ) //! Extended message ids, useful but not entirely necessary +#ifdef FLOG_CONFIG_MSG_ID_STRINGS_EXTENDED #define FLOG_MSG_IDS_EXTENDED \ X(FLOG_MSG_CANNOT_READ_FROM_STDIN, "Cannot read from stdin") \ X(FLOG_MSG_CANNOT_READ_FILE, "Cannot read from file" ) \ X(FLOG_MSG_CANNOT_OPEN_SOCKET, "Cannot open socket" ) +#else +#define FLOG_MSG_IDS_EXTENDED +#endif //! Message ids for stdio output module -#ifdef FLOG_CONFIG_OUTPUT_STDIO +#if defined(FLOG_CONFIG_OUTPUT_STDIO) || defined(FLOG_CONFIG_MSG_ID_STRINGS_EXTENDED) #define FLOG_MSG_IDS_OUTPUT_STDIO \ X(FLOG_MSG_CANNOT_WRITE_TO_STDOUT, "Cannot write to stdout") \ X(FLOG_MSG_CANNOT_WRITE_TO_STDERR, "Cannot write to stderr") @@ -45,7 +50,7 @@ X(FLOG_MSG_CANNOT_WRITE_TO_STDERR, "Cannot write to stderr") //! Message ids for file output module -#ifdef FLOG_CONFIG_OUTPUT_FILE +#if defined(FLOG_CONFIG_OUTPUT_FILE) || defined(FLOG_CONFIG_MSG_ID_STRINGS_EXTENDED) #define FLOG_MSG_IDS_OUTPUT_FILE \ X(FLOG_MSG_CANNOT_OPEN_FILE, "Cannot open file" ) \ X(FLOG_MSG_CANNOT_WRITE_FILE, "Cannot write to file" ) \ diff --git a/flog_output_file.h b/flog_output_file.h index 2f4da4b..d462ee0 100644 --- a/flog_output_file.h +++ b/flog_output_file.h @@ -14,6 +14,17 @@ #ifdef FLOG_CONFIG_OUTPUT_FILE +// Sanity checks +#ifndef FLOG_CONFIG_STRING_OUTPUT +#error FLOG_CONFIG_OUTPUT_FILE requires FLOG_CONFIG_STRING_OUTPUT +#endif +#ifndef FLOG_CONFIG_MSG_ID_STRINGS +#error FLOG_CONFIG_OUTPUT_FILE requires FLOG_CONFIG_MSG_ID_STRINGS +#endif +#ifndef FLOG_CONFIG_ERRNO_STRINGS +#error FLOG_CONFIG_OUTPUT_FILE requires FLOG_CONFIG_ERRNO_STRINGS +#endif + int flog_output_file(FLOG_T *log,const FLOG_MSG_T *msg); FLOG_T * create_flog_output_file(const char *name, FLOG_MSG_TYPE_T accepted_msg_type, const char *filename); void destroy_flog_output_file(FLOG_T *p); diff --git a/flog_output_stdio.h b/flog_output_stdio.h index 1a30a31..7f5efb1 100644 --- a/flog_output_stdio.h +++ b/flog_output_stdio.h @@ -13,6 +13,17 @@ #ifdef FLOG_CONFIG_OUTPUT_STDIO +// Sanity checks +#ifndef FLOG_CONFIG_STRING_OUTPUT +#error FLOG_CONFIG_OUTPUT_STDIO requires FLOG_CONFIG_STRING_OUTPUT +#endif +#ifndef FLOG_CONFIG_MSG_ID_STRINGS +#error FLOG_CONFIG_OUTPUT_STDIO requires FLOG_CONFIG_MSG_ID_STRINGS +#endif +#ifndef FLOG_CONFIG_ERRNO_STRINGS +#error FLOG_CONFIG_OUTPUT_STDIO requires FLOG_CONFIG_ERRNO_STRINGS +#endif + int flog_output_stdout(FLOG_T *log,const FLOG_MSG_T *msg); int flog_output_stderr(FLOG_T *log,const FLOG_MSG_T *msg); -- 2.11.4.GIT