The predefined logging handlers add various dependencies on the standard
library.  Compiling them out removes these dependencies, making it
easier to use libntfs-3g with a cut-down standard library.  Callers can
still supply a custom logging handler using whatever facilities they
have available.
---
 configure.ac         |   11 +++++++++++
 libntfs-3g/logging.c |   25 ++++++++++++++++---------
 2 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/configure.ac b/configure.ac
index f0d4b6b..33ea365 100644
--- a/configure.ac
+++ b/configure.ac
@@ -47,6 +47,17 @@ AC_ARG_WITH(fuse,
 )
 AM_CONDITIONAL(FUSE, test x$with_fuse = xyes)
 
+AC_ARG_ENABLE(standard-logging,
+       AS_HELP_STRING(--disable-standard-logging, disable predefined logging 
functions), ,
+       enable_standard_logging=yes)
+AC_MSG_CHECKING(whether to enable standard logging)
+if test x$enable_standard_logging = xyes ; then
+       AC_MSG_RESULT(yes)
+       AC_DEFINE(ENABLE_STANDARD_LOGGING, 1, enable predefined logging 
functions)
+else
+       AC_MSG_RESULT(no)
+fi
+
 AC_ARG_ENABLE(debug,
        AS_HELP_STRING(--enable-debug,enable additional debugging code and
                       output), ,
diff --git a/libntfs-3g/logging.c b/libntfs-3g/logging.c
index 647fe3d..5552405 100644
--- a/libntfs-3g/logging.c
+++ b/libntfs-3g/logging.c
@@ -24,9 +24,6 @@
 #include "config.h"
 #endif
 
-#ifdef HAVE_STDIO_H
-#include <stdio.h>
-#endif
 #ifdef HAVE_ERRNO_H
 #include <errno.h>
 #endif
@@ -36,12 +33,18 @@
 #ifdef HAVE_STRING_H
 #include <string.h>
 #endif
+
+#ifdef ENABLE_STANDARD_LOGGING
+#ifdef HAVE_STDIO_H
+#include <stdio.h>
+#endif
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
 #endif
 #ifdef HAVE_SYSLOG_H
 #include <syslog.h>
 #endif
+#endif
 
 #include "logging.h"
 #include "misc.h"
@@ -50,6 +53,7 @@
 #define PATH_SEP '/'
 #endif
 
+#ifdef ENABLE_STANDARD_LOGGING
 /* Colour prefixes and a suffix */
 static const char *col_green  = "\e[32m";
 static const char *col_cyan   = "\e[36m";
@@ -57,6 +61,7 @@ static const char *col_yellow = "\e[01;33m";
 static const char *col_red    = "\e[01;31m";
 static const char *col_redinv = "\e[01;07;31m";
 static const char *col_end    = "\e[0m";
+#endif /* ENABLE_STANDARD_LOGGING */
 
 /**
  * struct ntfs_logging - Control info for the logging system
@@ -82,7 +87,7 @@ static struct ntfs_logging ntfs_log = {
        NTFS_LOG_LEVEL_ERROR | NTFS_LOG_LEVEL_PERROR | NTFS_LOG_LEVEL_CRITICAL |
        NTFS_LOG_LEVEL_PROGRESS,
        NTFS_LOG_FLAG_ONLYNAME,
-#ifdef DEBUG
+#if defined(DEBUG) && defined(ENABLE_STANDARD_LOGGING)
        ntfs_log_handler_outerr
 #else
        ntfs_log_handler_null
@@ -183,7 +188,7 @@ u32 ntfs_log_clear_flags(u32 flags)
        return old;
 }
 
-
+#ifdef ENABLE_STANDARD_LOGGING
 /**
  * ntfs_log_get_stream - Default output streams for logging levels
  * @level:     Log level
@@ -269,7 +274,7 @@ static const char * ntfs_log_get_prefix(u32 level)
 
        return prefix;
 }
-
+#endif /* ENABLE_STANDARD_LOGGING */
 
 /**
  * ntfs_log_set_handler - Provide an alternate logging handler
@@ -282,7 +287,7 @@ void ntfs_log_set_handler(ntfs_log_handler *handler)
 {
        if (handler) {
                ntfs_log.handler = handler;
-#ifdef HAVE_SYSLOG_H
+#if defined(ENABLE_STANDARD_LOGGING) && defined(HAVE_SYSLOG_H)
                if (handler == ntfs_log_handler_syslog)
                        openlog("libntfs", LOG_PID, LOG_USER);
 #endif
@@ -326,7 +331,7 @@ int ntfs_log_redirect(const char *function, const char 
*file,
        return ret;
 }
 
-
+#ifdef ENABLE_STANDARD_LOGGING
 /**
  * ntfs_log_handler_syslog - syslog logging handler
  * @function:  Function in which the log line occurred
@@ -480,6 +485,7 @@ int ntfs_log_handler_fprintf(const char *function, const 
char *file,
        errno = olderr;
        return ret;
 }
+#endif /* ENABLE_STANDARD_LOGGING */
 
 /**
  * ntfs_log_handler_null - Null logging handler (no output)
@@ -503,6 +509,7 @@ int ntfs_log_handler_null(const char *function 
__attribute__((unused)), const ch
        return 0;
 }
 
+#ifdef ENABLE_STANDARD_LOGGING
 /**
  * ntfs_log_handler_stdout - All logs go to stdout
  * @function:  Function in which the log line occurred
@@ -593,7 +600,7 @@ int ntfs_log_handler_stderr(const char *function, const 
char *file,
 
        return ntfs_log_handler_fprintf(function, file, line, level, data, 
format, args);
 }
-
+#endif /* ENABLE_STANDARD_LOGGING */
 
 /**
  * ntfs_log_parse_option - Act upon command line options
-- 
1.4.4.2

Attachment: signature.asc
Description: Digital signature

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
ntfs-3g-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ntfs-3g-devel

Reply via email to