summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/wolf/log.h18
-rw-r--r--include/wolf/port/sys.h18
-rw-r--r--makefiles/nmake/clean.mk1
-rw-r--r--makefiles/nmake/compiler.mk3
-rw-r--r--src/Makefile.W3218
-rw-r--r--src/log.c16
-rw-r--r--src/port/stdio.h8
7 files changed, 75 insertions, 7 deletions
diff --git a/include/wolf/log.h b/include/wolf/log.h
index 76dd5ac..97db35b 100644
--- a/include/wolf/log.h
+++ b/include/wolf/log.h
@@ -55,6 +55,7 @@ typedef enum {
WOLF_LOG_DEBUG5 = 12 /**< debug-level messages */
} wolf_log_level_t;
+#if defined HAVE_SYSLOG_H
/**
* @brief Possible syslog facilities. Not the same on all Unix systems.
*/
@@ -84,7 +85,9 @@ typedef enum {
WOLF_LOG_LOCAL6 = 22, /**< local facility 6 */
WOLF_LOG_LOCAL7 = 23 /**< local facility 7 */
} wolf_log_syslog_facility_t;
+#endif /* defined HAVE_SYSLOG_H */
+#if defined HAVE_SYSLOG_H
/**
* @brief Options for opening the system logger, as defined by the Open Group.
*
@@ -95,12 +98,16 @@ typedef enum {
WOLF_LOG_SYSLOG_PID = 1, /**< log the process ID with each message */
WOLF_LOG_SYSLOG_CONS = 2 /**< log to the system console on error */
} wolf_log_syslog_option_t;
+#endif /* defined HAVE_SYSLOG_H */
/**
* @brief The default options to pass to the system logger.
*/
+#if defined HAVE_SYSLOG_H
#define WOLF_LOG_SYSLOG_DEFAULT_OPTIONS WOLF_LOG_SYSLOG_PID | WOLF_LOG_SYSLOG_CONS
+#endif /* defined HAVE_SYSLOG_H */
+#if defined HAVE_SYSLOG_H
/**
* Convert a wolf_log_syslog_facility_t to its string representation.
*
@@ -108,7 +115,9 @@ typedef enum {
* @return a string constant like "DAEMON"
*/
const char *wolf_log_syslog_facility_to_str( wolf_log_syslog_facility_t facility );
+#endif /* defined HAVE_SYSLOG_H */
+#if defined HAVE_SYSLOG_H
/**
* Convert a name of a syslog facility like "DAEMON" to the corresponding
* wolf_log_syslog_facility_t
@@ -118,7 +127,9 @@ const char *wolf_log_syslog_facility_to_str( wolf_log_syslog_facility_t facility
* passed facility is not known
*/
wolf_log_syslog_facility_t wolf_log_str_to_syslog_facility( const char *facility );
+#endif /* defined HAVE_SYSLOG_H */
+#if defined HAVE_SYSLOG_H
/**
* Returns if the current platform knows about the given syslog facility.
*
@@ -126,6 +137,7 @@ wolf_log_syslog_facility_t wolf_log_str_to_syslog_facility( const char *facility
* @return true if the facility exists, false if not
*/
bool wolf_log_platform_has_syslog_facility( wolf_log_syslog_facility_t facility );
+#endif /* defined HAVE_SYSLOG_H */
/**
* Convert a wolf_log_level_t to its string representation.
@@ -154,6 +166,7 @@ wolf_log_level_t wolf_log_str_to_level( const char *level );
*/
void wolf_log_openlogtofile( const char *filename, wolf_log_level_t level );
+#if defined HAVE_SYSLOG_H
/**
* Open a channel to the Unix system logger.
*
@@ -169,6 +182,7 @@ void wolf_log_openlogtosyslog( const char *ident,
wolf_log_syslog_facility_t facility,
wolf_log_level_t level,
int options );
+#endif /* defined HAVE_SYSLOG_H */
/**
* Open a channel for logging to stderr.
@@ -183,10 +197,12 @@ void wolf_log_openlogtostderr( wolf_log_level_t level );
*/
void wolf_log_closelogtofile( void );
+#if defined HAVE_SYSLOG_H
/**
* Close logging to the Unix system logger.
*/
void wolf_log_closelogtosyslog( void );
+#endif /* defined HAVE_SYSLOG_H */
/**
* Close logging to stderr.
@@ -198,10 +214,12 @@ void wolf_log_closelogtostderr( void );
*/
void wolf_log_reopenlogtofile( void );
+#if defined HAVE_SYSLOG_H
/**
* Reopen logging to the Unix system logger.
*/
void wolf_log_reopenlogtosyslog( void );
+#endif /* defined HAVE_SYSLOG_H */
/**
* Write a formatted log message to the logger.
diff --git a/include/wolf/port/sys.h b/include/wolf/port/sys.h
index 3cd4e9e..28415cd 100644
--- a/include/wolf/port/sys.h
+++ b/include/wolf/port/sys.h
@@ -45,6 +45,7 @@
#define HAVE_STRCASECMP
#define HAVE_STRNCASECMP
#define HAVE_STRINGS_H
+#define HAVE_SYSLOG_H
#else
#error unknown platform
#endif /* defined OS_MINOR_VERSION == 6 */
@@ -66,6 +67,7 @@
#define HAVE_STRDUP
#define HAVE_STRERROR_R
#define HAVE_LOCKF
+#define HAVE_SYSLOG_H
#else
#error unknown platform
#endif /* defined OS_MINOR_VERSION == 0 */
@@ -82,6 +84,7 @@
#define HAVE_STRDUP
#define HAVE_STRERROR_R
#define HAVE_LOCKF
+#define HAVE_SYSLOG_H
#else
#error unknown platform
#endif /* defined OS_MINOR_VERSION == 2 */
@@ -104,6 +107,7 @@
#define HAVE_STRDUP
#define HAVE_STRERROR_R
#define HAVE_LOCKF
+#define HAVE_SYSLOG_H
#else
#error unknown platform
#endif /* defined OS_MINOR_VERSION >= 2 && OS_MINOR_VERSION <= 3 */
@@ -128,6 +132,7 @@
#define HAVE_STRCASECMP
#define HAVE_STRNCASECMP
#define HAVE_STRINGS_H
+#define HAVE_SYSLOG_H
#else
#error unknown platform
#endif /* defined OS_MINOR_VERSION == 2 */
@@ -153,6 +158,7 @@
#define HAVE_STRCASECMP
#define HAVE_STRNCASECMP
#define HAVE_STRINGS_H
+#define HAVE_SYSLOG_H
#else
#if OS_MINOR_VERSION == 10
#if !defined __cplusplus
@@ -169,6 +175,7 @@
#define HAVE_STRCASECMP
#define HAVE_STRNCASECMP
#define HAVE_STRINGS_H
+#define HAVE_SYSLOG_H
#else
#error unknown platform
#endif /* OS_MINOR_VERSION == 10 */
@@ -204,6 +211,7 @@
#define HAVE_PTRDIFF_T 1
#define HAVE_VA_COPY 0
#define HAVE___VA_COPY 0
+#define HAVE_SYSLOG_H
#else
#error unknown platform
#endif /* OS_MINOR_VERSION >= 0 && OS_MINOR_VERSON <= 1 */
@@ -212,7 +220,13 @@
#endif /* OS_MAJOR_VERSION == 5 */
#endif /* defined CYGWIN */
-/** @} */ /* @addtogroup wolf_port */
+#if defined _WIN32
+/* TODO */
+#endif /* defined _WIN32 */
+
+/* Microsoft Windows compiler */
+#if defined _MSC_VER
+#endif /* defined _MSC_VER */
#if defined __INTEL_COMPILER
@@ -227,4 +241,6 @@
#endif /* defined __INTEL_COMPILER */
+/** @} */ /* @addtogroup wolf_port */
+
#endif /* ifndef WOLF_SYS_H */
diff --git a/makefiles/nmake/clean.mk b/makefiles/nmake/clean.mk
index 4c25f90..19cc006 100644
--- a/makefiles/nmake/clean.mk
+++ b/makefiles/nmake/clean.mk
@@ -32,6 +32,7 @@ clean:
-@erase *.exe
-@erase *.exe.manifest
-@erase *.obj
+ -@erase $(OBJS)
-@erase *.pdb
#.PHONY: distclean_recursive distclean local_distclean
diff --git a/makefiles/nmake/compiler.mk b/makefiles/nmake/compiler.mk
index a351041..22e30a5 100644
--- a/makefiles/nmake/compiler.mk
+++ b/makefiles/nmake/compiler.mk
@@ -7,6 +7,7 @@
# - BIN_OBJS: the object files we need for the binaries (containing the main)
#
+# TODO: which flags to enable?
# /EHsc: enable C++ exception handling
# compilation flags and compilers
@@ -29,7 +30,7 @@ CCPP_LINK = link.exe
.SUFFIXES: .c .cpp .obj .exe
.c.obj:
- $(CC) $(CFLAGS) $<
+ $(CC) $(CFLAGS) /Fo$@ $<
.cpp.obj:
$(CCPP) $(CCPPFLAGS) $<
diff --git a/src/Makefile.W32 b/src/Makefile.W32
index ed789b0..a3b4242 100644
--- a/src/Makefile.W32
+++ b/src/Makefile.W32
@@ -1,14 +1,22 @@
-TOPDIR = .
+TOPDIR = ..
SUBDIRS =
-INCLUDE_DIRS = /I$(TOPDIR)
+INCLUDE_DIRS = /I$(TOPDIR)\include\wolf /I.
-EXE=.exe
+BINS =
-CPP_BINS = test1$(EXE) test2$(EXE) test3$(EXE) typeof1$(EXE) test4$(EXE)
+LIBS = libwolf.a
-OBJS = vector.obj
+PORT_OBJS = \
+ port\string.obj
+
+COMMON_OBJS = \
+ log.obj
+
+OBJS = \
+ $(PORT_OBJS) \
+ $(COMMON_OBJS)
# compiler.mk
LINK = link.exe
diff --git a/src/log.c b/src/log.c
index 9039f04..5528ba1 100644
--- a/src/log.c
+++ b/src/log.c
@@ -6,8 +6,11 @@
#include <stdarg.h> /* for variable arguments */
#include <errno.h> /* for errno */
+#if defined HAVE_SYSLOG_H
#include <syslog.h> /* for syslog, closelog and levels */
+#endif
+#if defined HAVE_SYSLOG_H
const char *wolf_log_syslog_facility_to_str( wolf_log_syslog_facility_t facility ) {
switch( facility ) {
/* Linux, FreeBSD, OpenBSD, NetBSD */
@@ -68,7 +71,9 @@ const char *wolf_log_syslog_facility_to_str( wolf_log_syslog_facility_t facility
default: return "<unknown>";
}
}
+#endif /* defined HAVE_SYSLOG_H */
+#if defined HAVE_SYSLOG_H
wolf_log_syslog_facility_t wolf_log_str_to_syslog_facility( const char *facility ) {
if( strcmp( facility, "KERN" ) == 0 ) return WOLF_LOG_KERN;
if( strcmp( facility, "USER" ) == 0 ) return WOLF_LOG_USER;
@@ -98,7 +103,9 @@ wolf_log_syslog_facility_t wolf_log_str_to_syslog_facility( const char *facility
/* this is a seasonable default if nothing else exists */
return WOLF_LOG_DAEMON;
}
+#endif /* defined HAVE_SYSLOG_H */
+#if defined HAVE_SYSLOG_H
bool wolf_log_platform_has_syslog_facility( wolf_log_syslog_facility_t facility ) {
switch( facility ) {
/* Linux, FreeBSD, OpenBSD, NetBSD */
@@ -161,6 +168,7 @@ bool wolf_log_platform_has_syslog_facility( wolf_log_syslog_facility_t facility
return false;
}
+#endif /* defined HAVE_SYSLOG_H */
wolf_log_level_t wolf_log_str_to_level( const char *level ) {
if( strcmp( level, "EMERG" ) == 0 ) return WOLF_LOG_EMERG;
@@ -180,6 +188,7 @@ wolf_log_level_t wolf_log_str_to_level( const char *level ) {
return WOLF_LOG_EMERG;
}
+#if defined HAVE_SYSLOG_H
static int map_log_to_syslog_level( int level ) {
switch( level ) {
case WOLF_LOG_EMERG: return LOG_EMERG;
@@ -198,7 +207,9 @@ static int map_log_to_syslog_level( int level ) {
default: return LOG_EMERG;
}
}
+#endif /* defined HAVE_SYSLOG_H */
+#if defined HAVE_SYSLOG_H
static int map_log_facility_to_syslog_facility( int facility ) {
switch( facility ) {
case WOLF_LOG_KERN: return LOG_KERN;
@@ -252,6 +263,7 @@ static int map_log_facility_to_syslog_facility( int facility ) {
default: return LOG_DAEMON;
}
}
+#endif /* defined HAVE_SYSLOG_H */
const char *wolf_log_level_to_str( wolf_log_level_t level ) {
switch( level ) {
@@ -287,6 +299,7 @@ void wolf_log_openlogtofile( const char *filename, wolf_log_level_t level ) {
wolf_log_reopenlogtofile( );
}
+#if defined HAVE_SYSLOG_H
static int map_log_options_to_syslog_options( int opts ) {
int syslog_opts = LOG_NDELAY;
@@ -299,7 +312,9 @@ static int map_log_options_to_syslog_options( int opts ) {
return syslog_opts;
}
+#endif /* defined HAVE_SYSLOG_H */
+#if defined HAVE_SYSLOG_H
void wolf_log_openlogtosyslog( const char *ident,
wolf_log_syslog_facility_t facility,
wolf_log_level_t level,
@@ -312,6 +327,7 @@ void wolf_log_openlogtosyslog( const char *ident,
openlog( ident, LOG_CONS | LOG_NDELAY, facility );
setlogmask( LOG_UPTO( level ) );
}
+#endif /* defined HAVE_SYSLOG_H */
void wolf_log_openlogtostderr( wolf_log_level_t level ) {
log_stderr_level = level;
diff --git a/src/port/stdio.h b/src/port/stdio.h
index 360abaf..8f09201 100644
--- a/src/port/stdio.h
+++ b/src/port/stdio.h
@@ -5,6 +5,14 @@
#include <stdio.h>
+/* TODO: check which features we need in snprintf, make sure the platform one supports it,
+ * otherwise we take the stub */
+/* TODO: also clean up mess here with autoconf relicts! */
+#if defined _WIN32
+/* secure snprintf on Wndows is called differently */
+#define snprintf sprintf_s
+#else
#include "port/snprintf.h"
+#endif
#endif /* ifndef __STDIO_H */